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

chore: Set permissions for GitHub actions #11226

Closed

Conversation

naveensrinivasan
Copy link

Restrict the GitHub token permissions only to the required ones; this way, even if the attackers will succeed in compromising your workflow, they won’t be able to do much.

https://docs.github.com/en/actions/using-workflows/workflow-syntax-for-github-actions#permissions

https://docs.github.com/en/actions/using-jobs/assigning-permissions-to-jobs

Keeping your GitHub Actions and workflows secure Part 1: Preventing pwn requests

Signed-off-by: naveen [email protected]

 Restrict the GitHub token permissions only to the required ones; this way, even if the attackers will succeed in compromising your workflow, they won’t be able to do much.

- Included permissions for the action. https://github.com/ossf/scorecard/blob/main/docs/checks.md#token-permissions

https://docs.github.com/en/actions/using-workflows/workflow-syntax-for-github-actions#permissions

https://docs.github.com/en/actions/using-jobs/assigning-permissions-to-jobs

[Keeping your GitHub Actions and workflows secure Part 1: Preventing pwn requests](https://securitylab.github.com/research/github-actions-preventing-pwn-requests/)

Signed-off-by: naveen <[email protected]>
@uranusjr uranusjr added the skip news Does not need a NEWS file entry (eg: trivial changes) label Jul 4, 2022
Comment on lines +7 to +8
permissions:
contents: read
Copy link
Member

Choose a reason for hiding this comment

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

Is this necessary -- this is only on pull_request, which does not get a token with write anyway?

I might have a gap in understanding here, so I'd appreciate context on why this exists.

Copy link
Author

Choose a reason for hiding this comment

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

I agree it doesn’t get write token. It is best practice to set permissions.

That was my reasoning.

Thanks

Copy link
Member

@pradyunsg pradyunsg left a comment

Choose a reason for hiding this comment

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

LGTM, but I do have one question (noted above)

@ichard26
Copy link
Member

ichard26 commented Apr 20, 2024

As far as I understand, this would be mostly redundant as by default GITHUB_TOKEN only provides read-only access to the repository thanks to current repository configuration: #12564 (comment)

I suppose we could further restrict permissions by only granting read access to specific scopes.

Copy link
Member

@ichard26 ichard26 left a comment

Choose a reason for hiding this comment

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

I'm going to add the awaiting merge label to this PR as it would improve GHA security in depth. This isn't necessary, but it's unlikely to hurt either.

I'm not against rejecting this PR though.

(To fellow maintainers, the awaiting merge label is brand new! It was created by Pradyun so I'd have a way to properly flag PRs that seem ready for merge, but don't belong in a release milestone.)

@ichard26
Copy link
Member

Ah, this branch is so old that the RTD build is failing. As long as the GHA CI passes, we can ignore that failure.

@pradyunsg
Copy link
Member

FWIW, we are protected against the kind of attack this claims to protect us from via the repo's settings.

Screenshot 2024-07-11 at 23 04 56

@pradyunsg
Copy link
Member

Deja vu: #12564 (comment)

@ichard26 ichard26 added the resolution: no action When the resolution is to not do anything label Jul 12, 2024
@ichard26
Copy link
Member

I'm going to close this PR then. Also AFAIK, we also restrict the actions this repository workflows can use so we should be okay security-wise for now.

@ichard26 ichard26 closed this Jul 12, 2024
@github-actions github-actions bot locked as resolved and limited conversation to collaborators Jul 28, 2024
Sign up for free to subscribe to this conversation on GitHub. Already have an account? Sign in.
Labels
awaiting merge resolution: no action When the resolution is to not do anything skip news Does not need a NEWS file entry (eg: trivial changes)
Projects
None yet
Development

Successfully merging this pull request may close these issues.

4 participants