ci: add explicit GITHUB_TOKEN permission scopes to workflows - #1364
Open
Makeph wants to merge 1 commit into
Open
ci: add explicit GITHUB_TOKEN permission scopes to workflows#1364Makeph wants to merge 1 commit into
Makeph wants to merge 1 commit into
Conversation
No workflow declared a `permissions:` block, so every job ran with the repository's default GITHUB_TOKEN scopes. Depending on repository and organisation settings those defaults can include write access to contents, packages and pull requests, which is far more than any of these jobs need. Each workflow now denies everything at the top level and grants the minimum back per job: - contents: read wherever a job checks out the repository - packages: write only for the jobs publishing to GHCR - contents/id-token/attestations: write kept as-is for the release job Jobs that never touch GITHUB_TOKEN keep the empty default: the artifact smoke tests only consume artifacts from their own run, the changelog check works anonymously on public repositories, and update-downstream authenticates with PAT_GITHUB throughout. Closes GitGuardian#1350
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.
Closes #1350.
No workflow declared a
permissions:block, so every job ran with the repository's defaultGITHUB_TOKENscopes. Depending on repository and organisation settings, those defaults can include write access to contents, packages and pull requests — considerably more than any of these jobs needs.I went through every workflow under
.github/workflows/, not just the two named in the issue. Each one now denies everything at the top level (permissions: {}) and grants the minimum back per job.What each job got, and why
build_release_assets.ymlbuild_wheel_sdist,build_os_packagescontents: readlinux_package_smoke_testschangelog-check.ymlcheck-changelogci.ymllint,build,functest_api,test_github_secret_scan_actioncontents: readbuild_os_packagescontents: readpush_docker_images-unstablecontents: read,packages: writeinstall-scripts.ymlbatscontents: readperfbench.ymlbenchmarkcontents: readtag.ymlreleasecontents: write,id-token: write,attestations: writepush_to_pypi,push_to_cloudsmith,push_to_chocolateycontents: readpush_docker_imagescontents: read,packages: writeupdate-downstream.ymlupdate-ggshield-versionPAT_GITHUBTwo things worth flagging
tag.ymlreferences./.github/workflows/update_vscode_extension.yml, but that file isn't present in the repository. I left that job's permissions untouched (it inherits the empty default) since I can't see what it needs — happy to adjust if you can tell me.pull_requestruns use the base branch's workflow files), so this can't be validated by the checks on this PR. I verified statically that all seven files parse and that the resulting permission tree is what's described above. You may want to confirm on a branch in the main repo before merging.If you'd rather have a single workflow-level
contents: readinstead ofpermissions: {}plus per-job grants, say the word and I'll rework it.Prepared with AI assistance; I reviewed every line and verified the YAML parses and resolves to the permission tree documented above.