Skip to content

ci: add minimum GitHub token permissions for workflows - #13645

Closed
ashishkurmi wants to merge 1 commit into
python:masterfrom
ashishkurmi:master
Closed

ashishkurmi wants to merge 1 commit into
python:masterfrom
ashishkurmi:master

Conversation

@ashishkurmi

Copy link
Copy Markdown

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 akurmi@stepsecurity.io

Signed-off-by: Ashish Kurmi <akurmi@stepsecurity.io>

@sobolevn sobolevn left a comment

Copy link
Copy Markdown
Member

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.

- 'mypy/test/**'
- 'test-data/**'

permissions:

Copy link
Copy Markdown
Member

Choose a reason for hiding this comment

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

Copy link
Copy Markdown
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
Copy Markdown
Member

Choose a reason for hiding this comment

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

Copy link
Copy Markdown
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
Copy Markdown
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
Copy Markdown
Contributor

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

@ashishkurmi

Copy link
Copy Markdown
Author

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

@hauntsaninja

Copy link
Copy Markdown
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