Add explicit permissions to GitHub Actions workflows to fix CodeQL warnings #3648
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.
This PR addresses CodeQL warnings about missing workflow permissions by adding explicit
permissionssections to all GitHub Actions workflows in the repository.Problem
CodeQL was generating warnings for workflows that didn't have explicit permissions defined, as they were using default permissions which can be overly broad and don't follow the principle of least privilege.
Solution
Added
permissions: contents: readto all workflow files, which provides the minimal required permissions for workflows that need to checkout code and run builds/tests.Changes Made
Generated Workflows (via yml tool):
crates/tools/yml/src/:test.rs- generates test.ymlclippy.rs- generates clippy.ymlmsrv.rs- generates msrv.ymlno_default_features.rs- generates no-default-features.ymlManual Workflows:
fmt.yml,lib.yml,gen.yml,no_std.ymlslim_errors.yml,linux.yml,miri.ymldoc.yml,cross.ymlExisting workflows (
stale.yml,web.yml) already had appropriate permissions defined.Result
contents: readpermissionThe changes are minimal and surgical - adding only 3 lines per workflow file while maintaining all existing functionality.
Fixes #3647.
💡 You can make Copilot smarter by setting up custom instructions, customizing its development environment and configuring Model Context Protocol (MCP) servers. Learn more Copilot coding agent tips in the docs.