Restrict GITHUB_TOKEN permissions in workflows - #703
Merged
Conversation
CodeQL (actions/missing-workflow-permissions) flags workflows without an explicit permissions block: they fall back to the repository/organization default, which for repos created before February 2023 is read-write. Add 'permissions: contents: read' at the top of each workflow that only needs to read the repository, and make the PyPI deploy job's existing job-level block explicit about contents: read alongside id-token: write.
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.
Workflows without an explicit
permissionsblock use the repository or organization default token permissions. For repositories created before February 2023 that default is read-write, so every job runs with a token that can push to the repo even though all it does is check out and run tests.CodeQL flags this as
actions/missing-workflow-permissions(7 open alerts). Setting the permissions explicitly documents what each workflow actually needs and keeps it restricted if the default changes or the workflow is copied elsewhere.contents: readat the workflow root is enough for all of them; the PyPI deploy job keepsid-token: writefor trusted publishing and now statescontents: readtoo, since a job-level block replaces rather than extends the root one.See Assigning permissions to jobs.