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 #105003

Merged
merged 1 commit into from
Jul 4, 2022

Conversation

varunsh-coder
Copy link
Contributor

This PR adds minimum token permissions for the GITHUB_TOKEN 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.

Signed-off-by: Varun Sharma [email protected]

  • Have you followed the guidelines for contributing?
  • Have you ensured that your commits follow the commit style guide?
  • Have you checked that there aren't other open pull requests for the same formula update/change?
  • Have you built your formula locally with brew install --build-from-source <formula>, where <formula> is the name of the formula you're submitting?
  • Is your test running fine brew test <formula>, where <formula> is the name of the formula you're submitting?
  • Does your build pass brew audit --strict <formula> (after doing brew install --build-from-source <formula>)? If this is a new formula, does it pass brew audit --new <formula>?

@varunsh-coder varunsh-coder requested review from MikeMcQuaid, dawidd6 and a team as code owners July 3, 2022 14:45
@BrewTestBot BrewTestBot added automerge-skip `brew pr-automerge` will skip this pull request workflows PR modifies GitHub Actions workflow files labels Jul 3, 2022
@varunsh-coder
Copy link
Contributor Author

I could not set the right permissions for dispatch-rebottle.yml because of this line, so did not fix it:

Not sure how the GITHUB_TOKEN is being used there...

HOMEBREW_GITHUB_API_TOKEN: ${{secrets.GITHUB_TOKEN}}

@Bo98
Copy link
Member

Bo98 commented Jul 4, 2022

Not sure how the GITHUB_TOKEN is being used there...

brew audit and brew livecheck may do some checks on other Git repos (e.g. latest release check), so metadata-only permissions should be sufficient there. This isn't dispatch-rebottle specific. The same applies to dispatch-build-bottle and tests.

@SMillerDev
Copy link
Member

Do any of these actually use the GITHUB_TOKEN? AFAIK it times out too quickly.

@Bo98
Copy link
Member

Bo98 commented Jul 4, 2022

Do any of these actually use the GITHUB_TOKEN? AFAIK it times out too quickly.

Sounds like a good reason to limit the permissions of it to no-permissions rather than the default of write-all (read-all for PRs).

Though to answer your question: it is used in the scenarios I mentioned above, because it has a significantly higher rate limit than no token.

@SMillerDev
Copy link
Member

The organization default is now the same as set in this PR.

@varunsh-coder
Copy link
Contributor Author

The organization default is now the same as set in this PR.

I believe this means that if any of the workflows in the organization are using the GITHUB_TOKEN with higher than contents: read, and the permissions have not been specified explicitly in the workflow/ job, the workflow will not work as expected.

If that happens, you can add explicit workflow/ job level permissions for that workflow. You can use https://github.com/step-security/secure-workflows to add explicit permissions.

@Bo98 Bo98 merged commit d28102a into Homebrew:master Jul 4, 2022
@github-actions github-actions bot added the outdated PR was locked due to age label Aug 4, 2022
@github-actions github-actions bot locked as resolved and limited conversation to collaborators Aug 4, 2022
Sign up for free to subscribe to this conversation on GitHub. Already have an account? Sign in.
Labels
automerge-skip `brew pr-automerge` will skip this pull request outdated PR was locked due to age workflows PR modifies GitHub Actions workflow files
Projects
None yet
Development

Successfully merging this pull request may close these issues.

4 participants