ci: deploy pull request previews from a separate privileged workflow - #871
Merged
Merged
Conversation
Pull requests from forks have no access to secrets, variables or the AWS OIDC token, so the deploy job in the pull_request workflow fails. Move deployment to a workflow_run workflow that runs on main, downloads the build artifact and deploys it without running pull request code. Fork deploys use a separate preview-fork environment so that they can require reviewer approval. Co-Authored-By: Mattias Buelens <mattias.buelens@dolby.com>
Contributor
🤖 Devin AI EngineerI'll be helping with this pull request! Here's what you should know: ✅ I will automatically:
Note: I can only respond to comments from users who have write access to this repository. ⚙️ Control Options:
|
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
Add this suggestion to a batch that can be applied as a single commit.This suggestion is invalid because no changes were made to the code.Suggestions cannot be applied while the pull request is closed.Suggestions cannot be applied while viewing a subset of changes.Only one suggestion per line can be applied in a batch.Add this suggestion to a batch that can be applied as a single commit.Applying suggestions on deleted lines is not supported.You must change the existing code in this line in order to create a valid suggestion.Outdated suggestions cannot be applied.This suggestion has been applied or marked resolved.Suggestions cannot be applied from pending reviews.Suggestions cannot be applied on multi-line comments.Suggestions cannot be applied while the pull request is queued to merge.Suggestion cannot be applied right now. Please check back later.
Summary
Pull requests from forks (e.g. #870) fail in
deploy / deploy-to-cloudfront:pull_requestruns from forks get no secrets, novars, and no OIDCid-token. This splits the PR pipeline into an unprivileged part and a privileged part, following the "preventing pwn requests" pattern.pull-request.yml(pull_request, no secrets): lint + build only. The build runs the PR's code (npm ci, Docusaurus plugins), so it must stay unprivileged.docusaurus_urlis now hardcoded to the preview origin becausevarsare empty for forks.pull-request-preview.yml(runs onmain, has secrets + OIDC):workflow_runon completion of "On Pull Requests": looks up the open PR whose head is exactlyworkflow_run.head_shaviaGET /repos/{repo}/commits/{sha}/pulls(the event'spull_requestslist is empty for forks; the PR number is never read from the artifact so a fork cannot overwrite another PR's preview), downloads thedist.zipartifact from that run, and calls_deploy.yml. It never checks out or runs PR code.pull_request_targetonclosed: undeploy. Safe because it only uses event metadata, no checkout.preview-forkenvironment; same-repo PRs keep usingpreview. This letspreview-forkrequire reviewer approval without affecting internal PRs._deploy.yml: new optional inputsartifact_run_id,pr_number,pr_head_sha(defaults keepmain.ymlunchanged). PR-comment steps are gated onpr_number > 0instead ofenvironment_name == 'preview'. Top-levelconcurrencymoved to the callers aspreview-pr-<number>(inworkflow_runcontextgithub.refis alwaysmain, which would serialize and drop queued deploys across all PRs).Required setup after merge (repo settings / AWS)
preview-forkand add Required reviewers. Every deploy from a fork will wait for approval. Copy the variables that are scoped to thepreviewenvironment (e.g.AWS_REGION,AWS_ROLE,S3_BUCKET_NAME,CF_DISTRIBUTION_ID, if they are not repository-level). Organization-level variables and secrets (THEOPLAYER_BOT_APP_ID,THEOPLAYER_BOT_PRIVATE_KEY) are available to every environment and need no copy.subclaim toenvironment:preview, also allowrepo:THEOplayer/documentation:environment:preview-fork.Notes
workflow_runworkflows only trigger from the default branch, so this cannot be verified on this PR itself; the first real test is the next PR after merge (Integrate UI customization documentation into OptiView Player #870 can be re-run by pushing to it).pr-N/on the preview domain (as any PR can today); the approval step is what gates that.Link to Devin session: https://dolby.devinenterprise.com/sessions/d49785eb74de44dfbe2baeafe9b73728
Open in Devin Desktop: https://dolby.devinenterprise.com/desktop/session/d49785eb74de44dfbe2baeafe9b73728?variant=devin
Requested by: @MattiasBuelens