Add least-privilege permissions to GitHub Actions workflows - #31
Merged
Merged
Conversation
Declare explicit permissions on the workflows flagged by CodeQL (actions/missing-workflow-permissions, alerts #1–#9) so GITHUB_TOKEN is no longer the default write-all. Default contents: read at workflow level; escalate only on jobs that create releases or upload CodeQL results. Co-authored-by: Julian R <julerobb1@users.noreply.github.com>
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.
Fixes CodeQL
actions/missing-workflow-permissionsalerts #1–#9. Every flagged job/workflow now has an explicitpermissions:block soGITHUB_TOKENis least-privilege instead of the default write-all.No build steps, triggers, or secrets were changed.
release.ymlwas already fixed onmain(alert #11 / Copilot Autofix)..github/workflows/dependabot.ymlis a Dependabot config, not an Actions workflow, so it was left alone.Permissions granted (and why)
Workflow-level default is
contents: readeverywhere (checkout / restore / build / test /upload-artifact, which uses the Actions runtime token rather than write onGITHUB_TOKEN). Job-level overrides replace that default only where a job needs more:ci.ymlcontents: readdotnetrestore/build/test onlycodeql-analysis.ymlcontents: read. Jobanalyze:actions: read,contents: read,security-events: writepackages: read(no private query packs)build.ymlcontents: read. Jobbuild:contents: writeactions/create-release@v1on tagsdotnet-desktop-build.ymlcontents: readdev-build.ymlcontents: readnightly-build.ymlcontents: readactions/upload-artifact@v3prod-build.ymlcontents: readrelease-drafter.ymlcontents: read. Jobupdate_release_draft:contents: write,pull-requests: readrelease-drafter/release-drafter@v5drafts a release and reads merged PR metadata. Nopull-requests: write(autolabeler is not used)release.ymlcontents: read. Jobbuild-and-release:contents: writeNotes
permissionsfully replace the workflow-level set (they do not merge), so CodeQL’sanalyzejob restatescontents: readalongside its write grant.packages: writeandid-token: writeare not granted anywhere; nothing publishes packages or uses OIDC.