Improve workflow permissions #122
Merged
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.
Summary
This PR explicitly states the permissions needed for each of the repo's workflows.
Thought process
Since our project has been created before February 2023, we have the more permissive permission
write-allset for theGITHUB_TOKENused by the workflow. Therefore, to apply the principle of least privilege, we now explicitly specify the permisisons needed for each workflow (also mentioned in the Code scan alerts).The workflows that didn't have any permissions explicitly set were
releaseandrelease-pr. Here's how the permissions for these two were determined:release- It builds, publishes to PyPi, creates a new tag and makes a new release on GitHub with the new tag. Since the workflow makes changes to the repo, it needscontents: write.release-pr- It creates a PR if there's not one already for a branch with a specific format. For that it needscontents: read(it doesn't make changes to the branch) andpull_requests: write.This addressed the following Code scan security alerts:
In addition, I've applied the same styling format for all current workflows for consistency.