X Tutup
Skip to content

feat: gate deployments from non-collaborators behind approval#5255

Draft
Flo4604 wants to merge 11 commits intofeat/github-deployment-statusfrom
feat/external-contributor-protection
Draft

feat: gate deployments from non-collaborators behind approval#5255
Flo4604 wants to merge 11 commits intofeat/github-deployment-statusfrom
feat/external-contributor-protection

Conversation

@Flo4604
Copy link
Member

@Flo4604 Flo4604 commented Mar 9, 2026

What does this PR do?

Implements deployment protection for external contributors by adding authorization controls for GitHub webhook-triggered deployments. When deployment protection is enabled on a project, pushes from non-collaborators will require manual approval before deployment workflows are triggered.

Key Changes:

  • Deployment Authorization API: Added AuthorizeDeployment RPC endpoint that fetches the current HEAD commit from GitHub and creates deployment records for approved external contributions
  • GitHub Collaborator Checking: Enhanced GitHub client with collaborator status verification and caching to determine if users need approval
  • Webhook Protection Logic: Modified push handler to check deployment protection settings and block non-collaborator deployments with GitHub status updates
  • Database Schema Updates: Added deployment_protection field to projects table and github_deployment_id field to deployments table
  • GitHub Status Integration: Added workflow for updating GitHub Deployment statuses from the worker service
  • Environment Configuration: Added FORCE_DEPLOYMENT_APPROVAL flag for testing authorization flows

The system creates GitHub Deployment checks with failure status for blocked deployments, providing clear feedback to contributors with links to the authorization page.

Type of change

  • New feature (non-breaking change which adds functionality)
  • Enhancement (small improvements)

How should this be tested?

  • Enable deployment protection on a project in the database
  • Create a GitHub webhook push from a non-collaborator account
  • Verify the deployment is blocked and GitHub shows failure status
  • Test the authorization endpoint to approve blocked deployments
  • Verify collaborators can deploy without approval
  • Test FORCE_DEPLOYMENT_APPROVAL=true environment variable

Checklist

Required

  • Filled out the "How to test" section in this PR
  • Read Contributing Guide
  • Self-reviewed my own code
  • Commented on my code in hard-to-understand areas
  • Ran pnpm build
  • Ran pnpm fmt
  • Ran make fmt on /go directory
  • Checked for warnings, there are none
  • Removed all console.logs
  • Merged the latest changes from main onto my branch with git pull origin main
  • My changes don't cause any responsiveness issues

Appreciated

  • Updated the Unkey Docs if changes were necessary

@vercel
Copy link

vercel bot commented Mar 9, 2026

The latest updates on your projects. Learn more about Vercel for GitHub.

Project Deployment Actions Updated (UTC)
dashboard Ready Ready Preview, Comment Mar 9, 2026 1:44pm

Request Review

Copy link
Member Author

Flo4604 commented Mar 9, 2026

Warning

This pull request is not mergeable via GitHub because a downstack PR is open. Once all requirements are satisfied, merge this PR as a stack on Graphite.
Learn more

This stack of pull requests is managed by Graphite. Learn more about stacking.

@coderabbitai
Copy link
Contributor

coderabbitai bot commented Mar 9, 2026

Important

Review skipped

Draft detected.

Please check the settings in the CodeRabbit UI or the .coderabbit.yaml file in this repository. To trigger a single review, invoke the @coderabbitai review command.

⚙️ Run configuration

Configuration used: Repository UI

Review profile: CHILL

Plan: Pro

Run ID: a886fedc-28eb-407d-a296-b53e69c63df5

You can disable this status message by setting the reviews.review_status to false in the CodeRabbit configuration file.

Use the checkbox below for a quick retry:

  • 🔍 Trigger review
✨ Finishing Touches
🧪 Generate unit tests (beta)
  • Create PR with unit tests
  • Post copyable unit tests in a comment
  • Commit unit tests in branch feat/external-contributor-protection

Comment @coderabbitai help to get the list of available commands and usage tips.

Flo4604 added 11 commits March 9, 2026 14:27
Add deployment protection that checks if the push sender is a repo
collaborator before triggering a deployment. Non-collaborators get their
deployment created in awaiting_approval status with a PR comment posted
linking to the approval page.

- Add awaiting_approval status to deployments enum
- Add deployment_protection boolean to projects table
- Add deployment_approvals table for audit trail
- Add sender_login to HandlePushRequest proto
- Add IsCollaborator, FindPullRequestForBranch, CreateIssueComment to
  GitHub client (with SWR cache for collaborator checks)
- Inject GitHub client into webhook service for collaborator checks
- Bot accounts ([bot] suffix) are auto-approved
- Fails open if collaborator check errors
Add Drizzle ORM schema mirroring Go schema.sql changes:
- awaiting_approval status and github_deployment_id on deployments
- deployment_protection boolean on projects
- deployment_approvals table
- Create GitHub Deployment with pending status when approval is required
- Add dashboardURL to webhook service for PR comment approve links
- Add FORCE_DEPLOYMENT_APPROVAL env var for local testing
- Set FORCE_DEPLOYMENT_APPROVAL=true in dev k8s manifest
… on rejection

- Add 'rejected' to deployments status enum in schema, models, proto, and drizzle
- Add ApproveDeployment and RejectDeployment ConnectRPC handlers
- RejectDeployment sets status to 'rejected' (not 'failed') and reports failure to GitHub
- ApproveDeployment triggers deploy workflow after status/approval update
- Add FindAppBuildSettingByAppEnv query for approve handler
- Wire Noop GitHub client into API deployment service
- Handle new statuses in exhaustive switch (get_deployment.go)
Remove GitHub client from API deployment service — the API doesn't have
GitHub App credentials. Instead, reject handler fires a Restate call to
the worker's new UpdateGitHubDeploymentStatus handler which owns the
GitHub client and performs the actual API call.
- Add UpdateIssueComment and FindBotComment to GitHub client interface
- Post/update a single PR comment (find-by-marker) showing deployment
  status table with environment, status, preview URL, and timestamp
- Update comment at each deploy phase: building, deploying, ready, failed
- Approval comment also uses find-and-update to avoid duplicates on re-push
Remove the PR comment for approval-gated deployments. The GitHub
Deployment pending status already shows in the PR sidebar — no
separate comment needed. Removes unused fmt import.
- Remove FindPullRequestForBranch, CreateIssueComment, UpdateIssueComment,
  FindBotComment from GitHub client interface and implementations
- Delete github_comment.go (PR comment reporter)
- Remove all updatePRComment calls from deploy_handler.go
- Add log_url to pending GitHub deployment status in approval flow so
  clicking the check on GitHub links to the dashboard approval page
- Fix exhaustruct lint for seed/harness test files
Show a red failed check on the PR instead of a yellow pending dot when
a deployment requires authorization. Clicking the check links to the
dashboard approval page.
Remove awaiting_approval/rejected status from deployments table and
drop deployment_approvals table. External contributor pushes no longer
create a deployment record — instead handle_push creates a GitHub
Deployment check with failure status linking to an authorize page.

Replace ApproveDeployment/RejectDeployment RPCs with a single
AuthorizeDeployment RPC that takes project_id + branch, fetches HEAD
from GitHub, re-derives deploy contexts, and creates deployments.
GitHub Deployments only appear in the PR Environments section. This adds
Check Runs via the Checks API so blocked deployments show a prominent
yellow "action_required" badge in the PR checks list. On authorization,
the check run is updated to green success.
@Flo4604 Flo4604 force-pushed the feat/external-contributor-protection branch from 36216f3 to 66dad62 Compare March 9, 2026 13:42
@Flo4604 Flo4604 force-pushed the feat/github-deployment-status branch from 162f137 to 8401e8a Compare March 9, 2026 13:42
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

1 participant

X Tutup