Skip to content
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

ci: add GitHub token permissions for workflows #10947

Merged
merged 1 commit into from Dec 5, 2022

Conversation

varunsh-coder
Copy link
Contributor

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

GitHub recommends defining minimum GITHUB_TOKEN permissions for securing GitHub Actions workflows

This project is part of the top 100 critical projects as per OpenSSF (https://github.com/ossf/wg-securing-critical-projects), so fixing the token permissions to improve security.

Before the change:
GITHUB_TOKEN has write permissions for multiple scopes, e.g.
https://github.com/rubocop/rubocop/runs/7939389109?check_suite_focus=true#step:1:19

After the change:
GITHUB_TOKEN will have minimum permissions needed for the jobs.

Signed-off-by: Varun Sharma varunsh@stepsecurity.io


Before submitting the PR make sure the following are checked:

  • The PR relates to only one subject with a clear title and description in grammatically correct, complete sentences.
  • Wrote good commit messages.
  • Commit message starts with [Fix #issue-number] (if the related issue exists).
  • Feature branch is up-to-date with master (if not - rebase it).
  • Squashed related commits together.
  • Added tests.
  • Ran bundle exec rake default. It executes all tests and runs RuboCop on its own code.
  • Added an entry (file) to the changelog folder named {change_type}_{change_description}.md if the new code introduces user-observable changes. See changelog entry format for details.

@bbatsov
Copy link
Collaborator

bbatsov commented Aug 22, 2022

@rubocop/rubocop-core Anyone familiar with these token permissions to provide a review?

@koic
Copy link
Member

koic commented Aug 23, 2022

There seem to be some similar PRs opened and I found a discussion at Node.js repository.
nodejs/node#43743

It seems that there are pros and cons, and it is difficult for me to judge whether or not to merge this. And I have no curiosity and opinion about this yet.

@varunsh-coder
Copy link
Contributor Author

Hi @koic and @bbatsov, please let me know if I can answer any questions for you.
To add more information:

  1. Not only for nodejs (as mentioned by @koic), the pull requests I created to add GITHUB token permissions for over 30 critical projects have been merged. You can see the list here: Fix token permissions for 100 critical open-source projects step-security/secure-repo#462
  2. The GITHUB token is always present in GitHub Actions workflows and has write permissions by default. Here is an example for this repo's workflow: https://github.com/rubocop/rubocop/runs/7939389109?check_suite_focus=true#step:1:19. If one of the Actions has a vulnerability or gets compromised, this token can be used to overwrite code or releases.
  3. Here is an example, where security researcher exploited this for VS Code : https://www.bleepingcomputer.com/news/security/heres-how-a-researcher-broke-into-microsoft-vs-codes-github/

This change reduces the token permissions, so even if compromised, it cannot be used to cause damage. GitHub itself recommends adding minimum token permissions.

Please let me know if you have any questions about this. I am also curious what is the con that you see with this change?Thanks!

@bbatsov
Copy link
Collaborator

bbatsov commented Nov 4, 2022

Please let me know if you have any questions about this. I am also curious what is the con that you see with this change?Thanks!

I don't see any cons, I'm just wary of breaking something by doing changes we don't fully understand. Anyways, I've reviewed your suggestion and the links you've provided and everything looks good to me. Can you rebase on top of master to address the merge conflict?

@bbatsov
Copy link
Collaborator

bbatsov commented Dec 5, 2022

@varunsh-coder ping :-)

@varunsh-coder
Copy link
Contributor Author

@varunsh-coder ping :-)

Sorry for the delay. I will do this today.

Signed-off-by: Varun Sharma <varunsh@stepsecurity.io>
@varunsh-coder
Copy link
Contributor Author

@varunsh-coder ping :-)

Sorry for the delay. I will do this today.

Done.

@bbatsov bbatsov merged commit 353eac8 into rubocop:master Dec 5, 2022
@bbatsov
Copy link
Collaborator

bbatsov commented Dec 5, 2022

Thanks!

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.

None yet

3 participants