ci: scope GITHUB_TOKEN to least privilege in release workflow#757
Merged
Conversation
Agent-Logs-Url: https://github.com/FlutterGen/flutter_gen/sessions/154a81b1-1dd2-483d-98a6-bd296cbbc022 Co-authored-by: AlexV525 <15884415+AlexV525@users.noreply.github.com>
Copilot
AI
changed the title
[WIP] Update GitHub Actions workflow for least-privilege permissions
ci: scope GITHUB_TOKEN to least privilege in release workflow
May 14, 2026
Codecov Report✅ All modified and coverable lines are covered by tests. Additional details and impacted files@@ Coverage Diff @@
## main #757 +/- ##
=======================================
Coverage 97.37% 97.37%
=======================================
Files 24 24
Lines 989 989
=======================================
Hits 963 963
Misses 26 26 ☔ View full report in Codecov by Sentry. 🚀 New features to boost your workflow:
|
There was a problem hiding this comment.
Pull request overview
This PR tightens the GitHub Actions release workflow’s GITHUB_TOKEN permissions to a least-privilege model while keeping the release/build and Homebrew tap dispatch behavior intact, and updates workflow outputs to the non-deprecated mechanism.
Changes:
- Removed workflow-wide
pull-requests: writeandcontents: write, replacing withpermissions: {}at the workflow level. - Scoped
contents: writeonly to thebuildjob (the only job that publishes release assets viasoftprops/action-gh-release@v2). - Replaced deprecated
::set-outputwith$GITHUB_OUTPUTin theupdatejob.
💡 Add Copilot custom instructions for smarter, more guided reviews. Learn how to get started.
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.
The release workflow granted
pull-requests: writeandcontents: writeglobally — unnecessarily widening theGITHUB_TOKENblast radius for every job, including ones that never touch releases or PRs.Changes
pull-requests: write— nothing in the workflow interacts with PRspermissions: {}) and grantcontents: writeonly to thebuildjob, which is the sole caller ofsoftprops/action-gh-release@v2; theupdatejob now carries zeroGITHUB_TOKENwrite access::set-outputwith$GITHUB_OUTPUTin theupdatejob'sversionandchecksumstepsOriginal prompt
Update the GitHub Actions workflow at
.github/workflows/release.ymlin repositoryFlutterGen/flutter_gento follow a least-privilege permissions model and tighten related workflow hygiene.Context:
pull-requests: writecontents: writepull-requests: writedoes not appear to be required.contents: writeis required for the release asset publishing step usingsoftprops/action-gh-release@v2, but it should be scoped as narrowly as possible to reduce supply-chain risk.::set-outputsyntax in theupdatejob.Requested changes:
.github/workflows/release.ymlto use least privilege.contents: writeonly to the specific job(s) that need it.pull-requests: writeunless it is demonstrably required by the workflow.::set-outputusage with the modern$GITHUB_OUTPUTmechanism.main).Please create a pull request with these changes and include a concise explanation in the PR description of:
contents: writeremains where it does,pull-requests: writewas removed because it was not used by the workflow as written.The following is the prior conversation context from the user's chat exploration (may be truncated):
User: Does the new release making and artifacts upload require
contents&pull-requesetswrite permission here? Do they required for this workflow?Assistant: Short answer:
contents: writeis required for the release upload step;pull-requests: writedoes not appear to be required by this workflow as shown.Why:
In
.github/workflows/release.yml, the workflow sets:pull-requests: writecontents: writeThe step that actually creates/updates the GitHub Release and uploads assets is:
That action writes release objects/assets in the repository, which falls under repository contents/releases access, so
contents: writeis the relevant permission.What I do not see in this workflow:
So based on the file you provided,
pull-requests: writeis unnecessary.Also note:
actions/upload-artifact@v4uploads artifacts to the workflow run artifact store. That does not needpull-requests: write.actions/download-artifact@v4.1.8also does not needpull-requests: write.peter-evans/repository-dispatch@v3sends a dispatch event to another repository using the app token fromactions/create-github-app-token@v1; that permission is governed by the GitHub App token’s permissions, not by this workflow’spull-requests: writeonGITHUB_TOKEN.So the minimal top-level permissions here likely are:
If you want, I can also point out a couple of other things in this workflow that look outdated or worth tightening up, like the deprecated
set-outputusage.User: You mentioned releases access, does releases has standalone permission entry? Should it be written here?
Assistant: No — there is no standalone
releases:permission key in GitHub Actions workflowpermissions. For release creation/upload, GitHub documents thatcontents: writeis the permission that allows creating a release. (docs.github.com)So in your workflow, this is the right form:
Not this:
Because
releasesis not one of the workflowGITHUB_TOKENpermission entries documented by GitHub; release management is covered by repository contents write access. GitHub’s REST docs for releases also say creating a release requires Contents repository permission (write) for fine-grained tokens. ([docs.github.com](https://docs.github.com/en/rest/releases/releases?utm_sour...This pull request was created from Copilot chat.