Harden GitHub Actions workflows - #269
Open
hirthbrian wants to merge 1 commit into
Open
Conversation
Limit workflow permissions and separate trusted/untrusted builds. Both workflows now set contents: read and update actions/checkout to v4 with persist-credentials:false. build.yml splits into build-main (push/trusted) and build-pr (pull_request_target/untrusted) with environment pr-build, concurrency groups, and allow-unsafe-pr-checkout for PR checkouts. build-main fetches a secret file URL and runs scripts/build.sh. Added comments explaining rationale: reduce risk from contributor-authored build scripts and protect repository secrets by scoping permissions and requiring maintainer approval for PR runs.
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.
Both workflows
permissions: contents: read. On a public repo this grants nothing an anonymous clone doesn't already have, and it removes the default write-scoped token from a job that runs contributor-authored scripts.persist-credentials: falseon checkout, so no token is left behind in.git/configfor build scripts to pick up.environment: pr-build, so a maintainer has to approve each run. Approval is tied to the head SHA, so every push to a PR is re-approved rather than approved once.concurrencygroup withcancel-in-progress: true, so pushing repeatedly to a PR queues one pending approval instead of a stack of them.allow-unsafe-pr-checkout: true— an explicit acknowledgement that this checkout is untrusted PR code underpull_request_target, rather than relying on the action's default.build.ymlspecificallybuildjob intobuild-main(push, trusted — the code is already onmain) andbuild-pr(pull_request_target, untrusted). Onlybuild-prcarries the environment gate and concurrency group; pushes tomainstill build without waiting on approval.actions/checkout@v2→@v4.ref: ${{ github.event.pull_request.head.sha || github.sha }}fallback goes away — each job now has one event and one unambiguous ref.Inline comments explaining the trusted/untrusted split are in both files, so the reasoning survives the next edit to these workflows.
Required repo setup before merging
The environment gate is inert without configuration. In Settings → Environments, create an environment named
pr-buildand add Required reviewers. Without a protection rule,environment: pr-buildresolves and the job runs immediately, so the workflows would be no worse than today but the approval step would do nothing.Notes
pull_request_target. Moving topull_requestwould drop the need for the approval gate, but PR builds would losesecrets.FILE_URLand couldn't fetch the game executable. Keepingpull_request_target+ manual approval preserves the current developer experience.doxygen.yml,frogress.yml, andprogress.ymlare untouched — none of them usepull_request_target.