Skip to content

Conversation

thoughtpolice
Copy link
Member

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

@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
Member 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.

@thoughtpolice thoughtpolice force-pushed the aseipp/push-uvkmukvyzmzp branch from 17ab108 to e6fd46f Compare December 31, 2024 01:03
@thoughtpolice thoughtpolice force-pushed the aseipp/push-uvkmukvyzmzp branch from e6fd46f to f64bfbd Compare February 11, 2025 20:44
@thoughtpolice thoughtpolice force-pushed the aseipp/push-uvkmukvyzmzp branch 3 times, most recently from 8a8930a to 46ccbb8 Compare February 11, 2025 22:54
@thoughtpolice thoughtpolice marked this pull request as ready for review February 11, 2025 22:54
@ilyagr
Copy link
Contributor

ilyagr commented Feb 12, 2025

This might be interesting to @neongreen or relevant to #5117.

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]>
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]>
Found by `zizmor`.

Signed-off-by: Austin Seipp <[email protected]>
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 issues earlier.

Signed-off-by: Austin Seipp <[email protected]>
@thoughtpolice thoughtpolice force-pushed the aseipp/push-uvkmukvyzmzp branch from 46ccbb8 to bdcba62 Compare February 12, 2025 04:20
@neongreen
Copy link
Contributor

Lgtm (assuming it works). I will rebase my docs pipeline when this is merged

Copy link
Contributor

@ilyagr ilyagr left a comment

Choose a reason for hiding this comment

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

Thanks Austin, and thanks Emily for the help with reviewing!

I don't follow all of these issues, but I trust your research, and we can revert this if it causes problems (e.g. if zizmor turns out to be hard to live with).

@thoughtpolice
Copy link
Member Author

Yeah, I think we can just get this in and fix any minor issues that come up in post. Thanks!

@thoughtpolice thoughtpolice added this pull request to the merge queue Feb 13, 2025
@github-merge-queue github-merge-queue bot removed this pull request from the merge queue due to failed status checks Feb 13, 2025
@thoughtpolice thoughtpolice added this pull request to the merge queue Feb 14, 2025
@github-merge-queue github-merge-queue bot removed this pull request from the merge queue due to failed status checks Feb 14, 2025
@thoughtpolice thoughtpolice added this pull request to the merge queue Feb 14, 2025
@github-merge-queue github-merge-queue bot removed this pull request from the merge queue due to failed status checks Feb 14, 2025
@ilyagr
Copy link
Contributor

ilyagr commented Feb 14, 2025

Getting this PR into main: https://www.youtube.com/watch?v=2Pox3loU9lQ

@thoughtpolice thoughtpolice added this pull request to the merge queue Feb 14, 2025
Merged via the queue into main with commit 514a009 Feb 14, 2025
45 checks passed
@thoughtpolice thoughtpolice deleted the aseipp/push-uvkmukvyzmzp branch February 14, 2025 09:56
martinvonz added a commit that referenced this pull request Feb 25, 2025
Similar to #5792. We haven't had any updates to the GitHub pages since
#5076, AFAICT.
github-merge-queue bot pushed a commit that referenced this pull request Feb 25, 2025
Similar to #5792. We haven't had any updates to the GitHub pages since
#5076, AFAICT.
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.

3 participants