Skip to content

Set minimal workflow token permissions #2773

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

Merged
merged 4 commits into from
Dec 12, 2023
Merged

Conversation

pnacht
Copy link
Contributor

@pnacht pnacht commented Dec 8, 2023

Fixes #2772.

This PR sets top-level read-only permissions on all CI/CD workflows. Jobs that require additional permissions (stale.yml and pr-comment.yml) are given them at the job-level.

I made more significant changes in pr-comment.yml. It is vulnerable to code injection, since it runs files controlled by the PR author (requirements.txt and scripts/list_missing_entries.py, taken from the PR). I have therefore modified the workflow to checkout those files from the base branch instead, ensuring we're running trusted versions of those files.

And in order to minimize the code that has access to the issues/pull-requests: write permissions, I have separated the workflow into two sequential jobs:

  1. define-comment, which is unprivileged and does almost everything
  2. write-comment, which has those additional permissions and uses them to perform the very last step of actually writing the comment on the PR.

Signed-off-by: Pedro Kaj Kjellerup Nacht <pnacht@google.com>
Signed-off-by: Pedro Kaj Kjellerup Nacht <pnacht@google.com>
Signed-off-by: Pedro Kaj Kjellerup Nacht <pnacht@google.com>
Copy link
Collaborator

@mmmarcos mmmarcos left a comment

Choose a reason for hiding this comment

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

LGTM. Thanks for this PR!

@mmmarcos mmmarcos requested review from cmaureir and rtobar December 9, 2023 15:12
Copy link
Collaborator

@rtobar rtobar left a comment

Choose a reason for hiding this comment

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

Thanks for the changes @pnacht, they seem very useful and I'll probably apply this to other projects I maintain.

I left a very small question, but otherwise LGTM. I'd also like to chase that pipeline failure before merging -- it seems unrelated, but since your changes touch exactly this infrastructure I'd like to get all tests passing correctly and make surr nothing really breaks.

@pnacht
Copy link
Contributor Author

pnacht commented Dec 11, 2023

I'd also like to chase that pipeline failure before merging -- it seems unrelated, but since your changes touch exactly this infrastructure I'd like to get all tests passing correctly and make surr nothing really breaks.

Yeah, I'm pretty sure this is unrelated, but I've just pushed a commit that undoes the change to main.yml. Feel free to approve the workflow to test this again. If it still fails, I'll re-apply the read-only token permissions).


EDIT: Nevermind, I've unpushed that commit. Instead, please see this PR on my fork. The test is failing even though the workflow workflow is unchanged on my main branch (3.12).

@rtobar
Copy link
Collaborator

rtobar commented Dec 11, 2023

@pnacht the issue with the CI failure is totally on our end, you just happened to be the first one to get hit by it. Hopefully we'll get #2776 merged soon to get it fixed.

@rtobar rtobar merged commit d88bff3 into python:3.12 Dec 12, 2023
@rtobar
Copy link
Collaborator

rtobar commented Dec 12, 2023

Thanks again @pnacht for the changes!

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.

Set minimal workflow permissions
3 participants