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

github: scope/narrow permissions, prevent template injection via GHA, enable zizmor workflow #5076

Draft
wants to merge 10 commits into
base: main
Choose a base branch
from

Conversation

thoughtpolice
Copy link
Collaborator

This adds a series of changes to the workflow files suggested by the zizmor tool, an automated security scanner for GitHub Actions Workflows. At the very end, it also adds a new workflow which will automatically run zizmor on all changes going forward.

Context: there was a recent compromise of a very popular pypi package named ultralytics that occurred due to template injection through a pushed tag. GHA has also had a long string of security vulnerabilities


Almost all of the suggested changes were low-priority, related to:

  1. Overly broad permissions (we granted read-all when we either didn't need it, or only needed it for extremely few steps), and
  2. Persisting GitHub credentials into $HOME/.git storage when running checkout — which could be exploited by steps that read and exfiltrated them.

In our case, neither of these features were necessary, so removing them is easy. However...

It also found real template injection vulnerabilities in the release.yml workflow, which in theory could be exploited by contributors who pushed tags (I am not sure if anyone except Martin is capable of pushing tags now, but it's easier to assume the answer is "yes").

I don't believe these could be exploited in a meaningful way today by any (compromised) contributor because the only thing you could exfiltrate is a narrowly scoped $GITHUB_TOKEN credential. However, I filed #2483 last year to automate the release workflow, which would necessarily expose a https://crates.io API token to the release workflow — which could have then been potentially exfiltrated via this vulnerability, resulting in absolute catastrophe.

Checklist

If applicable:

  • I have updated CHANGELOG.md
  • I have updated the documentation (README.md, docs/, demos/)
  • I have updated the config schema (cli/src/config-schema.json)
  • I have added tests to cover my changes

This stops issuing overly broad permissions to the entire workflow and instead
scopes them to the necessary steps in the job.

Found by `zizmor`.

Signed-off-by: Austin Seipp <[email protected]>
There's literally no need for permissions of any kind in this workflow, and
furthermore this disables credential persistence for Git commands.

Found by `zizmor`.

Signed-off-by: Austin Seipp <[email protected]>
The dependabot workflow already specifies the exact permissions it needs within
the workflow steps, so there's no need to enable any default permissions.

Found by `zizmor`.

Signed-off-by: Austin Seipp <[email protected]>
Found by `zizmor`.

Signed-off-by: Austin Seipp <[email protected]>
…aries workflow

Found by `zizmor`.

Signed-off-by: Austin Seipp <[email protected]>
In theory this could be exploited by a contributor who pushes a tag with a
specifically crafted name in order to exfiltrate a `GITHUB_TOKEN` that has
permissions on the jj repository. This token would be scoped narrowly ideally,
but...

Today, Martin does releases manually, so this workflow currently does not e.g.
have the ability to upload a compromised package to crates.io. However in the
future we'd like to have the release done automatically via workflow as well,
which would make this potential injection vector catastrophic if the injection
was possible in a step with a crates.io API token available.

Found by `zizmor`.

Signed-off-by: Austin Seipp <[email protected]>
This should help us catch GHA security flaws much earlier.

Signed-off-by: Austin Seipp <[email protected]>
@github-advanced-security
Copy link

This pull request sets up GitHub code scanning for this repository. Once the scans have completed and the checks have passed, the analysis results for this pull request branch will appear on this overview. Once you merge this pull request, the 'Security' tab will show more code scanning analysis results (for example, for the default branch). Depending on your configuration and choice of analysis tool, future pull requests will be annotated with code scanning analysis results. For more information about GitHub code scanning, check out the documentation.

@thoughtpolice
Copy link
Collaborator Author

I haven't tested the release workflow in my thoughtpolice/jj repository yet, so this is currently in draft until I can make sure nothing broke due to a missed permission.

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.

1 participant