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

Closed
wants to merge 3 commits into from

Conversation

varunsh-coder
Copy link

Proposed change

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 varunsh@stepsecurity.io

Type of change

  • Dependency upgrade
  • Bugfix (non-breaking change which fixes an issue)
  • New integration (thank you!)
  • New feature (which adds functionality to an existing integration)
  • Breaking change (fix/feature causing existing functionality to break)
  • Code quality improvements to existing code or addition of tests

Checklist

  • The code change is tested and works locally.
  • Local tests pass. Your PR cannot be merged unless tests pass
  • There is no commented out code in this PR.
  • I have followed the development checklist
  • The code has been formatted using Black (black --fast homeassistant tests)
  • Tests have been added to verify that the new code works.

If user exposed functionality or configuration variables are added/changed:

If the code communicates with devices, web services, or third-party tools:

  • The manifest file has all fields filled out correctly.
    Updated and included derived files by running: python3 -m script.hassfest.
  • New or updated dependencies have been added to requirements_all.txt.
    Updated by running python3 -m script.gen_requirements_all.
  • For the updated dependencies - a link to the changelog, or at minimum a diff between library versions is added to the PR description.
  • Untested files have been added to .coveragerc.

The integration reached or maintains the following Integration Quality Scale:

  • No score or internal
  • 🥈 Silver
  • 🥇 Gold
  • 🏆 Platinum

To help with the load of incoming pull requests:

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

Hi @varunsh-coder,

It seems you haven't yet signed a CLA. Please do so here.

Once you do that we will be able to review and accept this pull request.

Thanks!

Signed-off-by: Varun Sharma <varunsh@stepsecurity.io>
Comment on lines +15 to +17
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.

We should set read on repository settings instead

Copy link
Author

Choose a reason for hiding this comment

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

Hi @ludeeus, I think it would be good to set read on repo settings in addition to this change. This way, since the permissions are set explicitly in the workflow, even if one forks this repo, the workflow will still be secure in the forked repo. Please let me know your thoughts.

Copy link
Member

Choose a reason for hiding this comment

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

I think that if that is required to secure forks, GitHub has an issue that we should take up with them. Basically, you are saying that the repository settings don't work?

Copy link
Author

Choose a reason for hiding this comment

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

I think that if that is required to secure forks, GitHub has an issue that we should take up with them. Basically, you are saying that the repository settings don't work?

Setting the token permission using repository setting will work for this repository. But if the repository is forked or if someone copies the same workflow and uses it in a different repository, the repository settings will not go along. This is why it is a best practice to keep the permissions along with the workflow file.

Copy link
Member

Choose a reason for hiding this comment

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

So, you are saying the repository permissions settings are not working / causing a security issue?

Since you guys are on a mission fixing / improving security for open source project, I assume you have reported/contacted GitHub about this as well? I am interested in their response actually?

Copy link
Author

Choose a reason for hiding this comment

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

So, you are saying the repository permissions settings are not working / causing a security issue?

Since you guys are on a mission fixing / improving security for open source project, I assume you have reported/contacted GitHub about this as well? I am interested in their response actually?

Hi @frenck I have not reported/ contacted GitHub about this, since they offer multiple solutions (repo setting + workflow file setting) and developers can choose to use both of them to cover all scenarios. I did work with GitHub to set token permissions in starter workflows. For starter workflow, permissions are required to be set in the workflow file. This is the issue for it: actions/starter-workflows#1299

For your repo, if you prefer to just use repo settings for cases where only contents: read is needed, I can remove the explicit workflow level permissions. The only downside is that forks of this repo will not automatically be secure, but the maintainers of those forks can implement the fix on their own. Please let me know. Thanks!

Copy link
Author

Choose a reason for hiding this comment

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

Hi @frenck, please let me know about this. Thanks!

Comment on lines 97 to 100
permissions:
actions: read # for dawidd6/action-download-artifact to query and download artifacts
contents: read # for actions/checkout to fetch code
pull-requests: read # for dawidd6/action-download-artifact to query commit hash
Copy link
Member

Choose a reason for hiding this comment

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

These would not do anything

Copy link
Author

Choose a reason for hiding this comment

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

To clarify, do you mean these would not do anything because these are read permissions and this is a public repo, so the token will anyways have read access? I think that makes sense.

These changes are automated using https://github.com/step-security/secure-workflows, and that program just takes a workflow as input and fixes it. It does not have context on whether the workflow is in public repo or private repo. For a private repo, these permissions would need to be set explicitly. If you prefer that I remove these from the PR, I can do that. Please let me know.

Copy link
Member

Choose a reason for hiding this comment

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

These changes are automated using step-security/secure-workflows, and that program just takes a workflow as input and fixes it. It does not have context on whether the workflow is in public repo or private repo.

That is why automated tools for things like these are not really helpful and generate tons of noise.

Yes, please address the review comment.

Copy link
Author

Choose a reason for hiding this comment

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

Fixed

Comment on lines +37 to +39
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.

We should set read on repository settings instead

Comment on lines 42 to 44
permissions:
contents: read # for dorny/paths-filter to fetch a list of changed files
pull-requests: read # for dorny/paths-filter to read pull requests
Copy link
Member

Choose a reason for hiding this comment

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

These would not do anything

Copy link
Author

Choose a reason for hiding this comment

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

Fixed

Comment on lines +9 to +11
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.

We should set read on repository settings instead

Comment on lines +17 to +19
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.

We should set read on repository settings instead

Comment on lines +16 to +18
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.

We should set read on repository settings instead

Signed-off-by: Varun Sharma <varunsh@stepsecurity.io>
@github-actions
Copy link

There hasn't been any activity on this pull request recently. This pull request has been automatically marked as stale because of that and will be closed if no further activity occurs within 7 days.
Thank you for your contributions.

@github-actions github-actions bot added the stale label Oct 17, 2022
@github-actions github-actions bot closed this Oct 24, 2022
@github-actions github-actions bot locked and limited conversation to collaborators Oct 25, 2022
Sign up for free to subscribe to this conversation on GitHub. Already have an account? Sign in.
Labels
Projects
None yet
Development

Successfully merging this pull request may close these issues.

4 participants