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

Set permissions for GitHub actions #11367

Conversation

naveensrinivasan
Copy link
Contributor

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]>
@spring-projects-issues spring-projects-issues added the status: waiting-for-triage An issue we've not yet triaged label Jun 12, 2022
@rwinch rwinch requested review from sjohnr and rwinch June 14, 2022 19:45
Copy link
Member

@rwinch rwinch 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 PR @naveensrinivasan Looks good to me. @sjohnr Can you please take a second look over this and if it looks good merge?

@rwinch rwinch changed the title chore: Set permissions for GitHub actions Set permissions for GitHub actions Jun 14, 2022
@rwinch rwinch added in: build An issue in the build type: enhancement A general enhancement and removed status: waiting-for-triage An issue we've not yet triaged labels Jun 14, 2022
@rwinch rwinch added this to the 6.0.0-M6 milestone Jun 14, 2022
Copy link
Member

@sjohnr sjohnr left a comment

Choose a reason for hiding this comment

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

Thanks @naveensrinivasan! See comments below. Also, according to the scorecard reference you provided:

The highest score is awarded when the permissions definitions in each workflow's yaml file are set as read-only at the top level and the required write permissions are declared at the run-level. One point is reduced from the score if all jobs have their permissions defined but the top level permissions are not defined. This configuration is secure, but there is a chance that when a new job is added to the workflow, its job permissions could be left undefined because of human error.

If I'm understanding this correctly, we should have every workflow file in this repo contain at a minimum:

permissions:
  contents: read

Am I understanding that correctly? I see the following missing files:

  • backport-bot.yml
  • release-scheduler.yml
  • update-scheduled-release-version.yml

@marcusdacoregio marcusdacoregio modified the milestones: 6.0.0-M6, 6.0.0-M7 Jul 15, 2022
sjohnr added a commit to sjohnr/spring-security that referenced this pull request Jul 26, 2022
@sjohnr
Copy link
Member

sjohnr commented Jul 26, 2022

Thanks @naveensrinivasan, this is merged as 8f93a7f. I've also included a polish commit 3f4efed to add default permissions to each workflow.

@sjohnr sjohnr closed this Jul 26, 2022
sjohnr pushed a commit that referenced this pull request Jul 28, 2022
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]>

Closes gh-11367
sjohnr added a commit that referenced this pull request Jul 28, 2022
sjohnr pushed a commit that referenced this pull request Jul 28, 2022
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]>

Closes gh-11367
sjohnr added a commit that referenced this pull request Jul 28, 2022
@github-actions github-actions bot added the status: backported An issue that has been backported to maintenance branches label Jul 28, 2022
sjohnr pushed a commit that referenced this pull request Jul 28, 2022
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]>

Closes gh-11367
sjohnr added a commit that referenced this pull request Jul 28, 2022
@sjohnr sjohnr modified the milestones: 6.0.0-M7, 5.8.0-M2 Jul 28, 2022
@vpavic
Copy link
Contributor

vpavic commented Aug 15, 2022

FWIW, these kind of concerns are IMO better addressed at either repository or organization level under Actions settings:
image

That makes workflows easier to maintain as you only override permissions where needed.

Note that I left a similar comment in spring-projects/spring-boot#31344 (comment).

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
in: build An issue in the build status: backported An issue that has been backported to maintenance branches type: enhancement A general enhancement
Projects
None yet
Development

Successfully merging this pull request may close these issues.

6 participants