Skip to content

ci: add minimum GitHub token permissions for workflows #13645

New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Closed
wants to merge 1 commit into from

Conversation

ashishkurmi
Copy link

Description

This PR adds minimum token permissions for the GITHUB_TOKEN in GitHub Actions workflows using https://github.com/step-security/secure-workflows.

The GitHub Actions workflow has a GITHUB_TOKEN with write access to multiple scopes.
Here is an example of the permissions in one of the workflow runs:
https://github.com/python/mypy/runs/8253080028?check_suite_focus=true#step:1:19

After this change, the scopes will be reduced to the minimum needed for the following workflows:

  • build_wheels.yml
  • docs.yml
  • mypy_primer.yml
  • test.yml
  • test_stubgenc.yml

The following workflow already has the least privileged token permission set:

  • mypy_primer_comment.yml

Motivation and Context

Signed-off-by: Ashish Kurmi [email protected]

Copy link
Member

@sobolevn sobolevn left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I like the idea. Stronger security is always a good thing.

@@ -15,6 +15,9 @@ on:
- 'mypy/test/**'
- 'test-data/**'

permissions:
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Copy link
Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Hello @sobolevn, I analyzed all of the workflows included in the project and found that they only need contents:read to function hence I added it on all workflow files.

Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Maybe there are other places where we already have permissions: set?

Copy link
Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

@sobolevn yes, mypy_primer_comment.yml already has token permission set hence I did not include it in the PR. This change will increase the security of other workflow files.

@github-actions
Copy link
Contributor

According to mypy_primer, this change has no effect on the checked open source code. 🤖🎉

@ashishkurmi
Copy link
Author

Thanks for reviewing the PR @sobolevn ! I just addressed your comment, please take a look when you get a chance.

@hauntsaninja
Copy link
Collaborator

Thanks, I think fixed in #15965

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

Successfully merging this pull request may close these issues.

3 participants