Skip to content

ci: add zizmor check and configuration#396451

Merged
wolfgangwalther merged 2 commits intoNixOS:masterfrom
winterqt:zizmor
Oct 27, 2025
Merged

ci: add zizmor check and configuration#396451
wolfgangwalther merged 2 commits intoNixOS:masterfrom
winterqt:zizmor

Conversation

@winterqt
Copy link
Copy Markdown
Member

@winterqt winterqt commented Apr 6, 2025

zizmor is a tool that uses static analysis to find potential security issues in GitHub Actions 0. (Yes, it's a bit absurd that GitHub made a CI system so complicated that tools like this were created, but I digress.)

Given our increase in GHA usage recently, I think this is a good step towards keeping our security posture in tip-top shape. (It also keeps with the theme of automating as many things as possible!)

There are a few false positives (stemming from two rules), so I've excluded them per-usage (well, mostly, see 1) instead of globally or per-file, so that new usages of them get caught so we can determine if we can avoid using the footgun(s), or if we should ignore it.

Things done

  • Built on platform(s)
    • x86_64-linux
    • aarch64-linux
    • x86_64-darwin
    • aarch64-darwin
  • For non-Linux: Is sandboxing enabled in nix.conf? (See Nix manual)
    • sandbox = relaxed
    • sandbox = true
  • Tested, as applicable:
  • Tested compilation of all packages that depend on this change using nix-shell -p nixpkgs-review --run "nixpkgs-review rev HEAD". Note: all changes have to be committed, also see nixpkgs-review usage
  • Tested basic functionality of all binary files (usually in ./result/bin/)
  • 25.05 Release Notes (or backporting 24.11 and 25.05 Release notes)
    • (Package updates) Added a release notes entry if the change is major or breaking
    • (Module updates) Added a release notes entry if the change is significant
    • (Module addition) Added a release notes entry if adding a new NixOS module
  • Fits CONTRIBUTING.md.

Add a 👍 reaction to pull requests you find important.

@github-actions github-actions bot added 6.topic: continuous integration Affects continuous integration (CI) in Nixpkgs, including Ofborg and GitHub Actions 6.topic: policy discussion Discuss policies to work in and around Nixpkgs backport release-24.11 labels Apr 6, 2025
@github-advanced-security
Copy link
Copy Markdown

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.

@winterqt
Copy link
Copy Markdown
Member Author

winterqt commented Apr 6, 2025

As part of this PR being merged, I would like to enable code scanning merge protection, so that PRs that do not pass zimor's checks will not be able to be merged.

Given that @infinisil is an org owner alongside myself, a +1 should be sufficient for either of us to enable this setting while merging.

@github-actions github-actions bot added 10.rebuild-darwin: 0 This PR does not cause any packages to rebuild on Darwin. 10.rebuild-linux: 0 This PR does not cause any packages to rebuild on Linux. labels Apr 6, 2025
Copy link
Copy Markdown
Member

@LeSuisse LeSuisse 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 dealing with that, it was on my todo list since the moment I added the zizmor package into nixpkgs but I did not find the time to do it since then 💚

@winterqt
Copy link
Copy Markdown
Member Author

Still need to get to this, but want to fix up some things on Zizmor's end first.

Copy link
Copy Markdown
Contributor

@wolfgangwalther wolfgangwalther left a comment

Choose a reason for hiding this comment

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

With the recent changes around running more checks via treefmt (#405684) and future changes about being able to run most of CI locally (#404466), we need to rethink the workflow part of this. Since this is static analysis of code, I think it would fit in with treefmt very nicely.

I'm just not sure how we can report results to upload to GitHub from fmt.check, I have not looked into treefmt / treefmt-nix too much, yet.

@wegank wegank added the 2.status: merge conflict This PR has merge conflicts with the target branch label May 17, 2025
@wolfgangwalther
Copy link
Copy Markdown
Contributor

With the recent changes around running more checks via treefmt (#405684) and future changes about being able to run most of CI locally (#404466), we need to rethink the workflow part of this. Since this is static analysis of code, I think it would fit in with treefmt very nicely.

treefmt-nix is now shipping zizmor: numtide/treefmt-nix#354

@LeSuisse
Copy link
Copy Markdown
Member

@winterqt Are you fine with me taking over the PR? I would like to rebase it, leverage treefmt and deal with the remaining changes so we can hopefully merge it.

@winterqt
Copy link
Copy Markdown
Member Author

Go for it, @LeSuisse!

@qweered
Copy link
Copy Markdown
Contributor

qweered commented Oct 26, 2025

@LeSuisse Have you been able to work on it yet? I am also intrested in implementing this

Co-authored-by: Thomas Gerbet <thomas@gerbet.me>
@nixpkgs-ci nixpkgs-ci bot removed the 2.status: merge conflict This PR has merge conflicts with the target branch label Oct 26, 2025
@nix-owners nix-owners bot requested a review from MattSturgeon October 26, 2025 19:23
@LeSuisse
Copy link
Copy Markdown
Member

Rebased the changes, resolved the conflicts and the remaining Zizmor issues. The Zizmor workflow has been replaced by the use of treefmt.

Copy link
Copy Markdown
Contributor

@wolfgangwalther wolfgangwalther left a comment

Choose a reason for hiding this comment

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

LGTM; thank you!

Found a typo in the commit message of the second commit: "Explainations" -> "Explanations".

@nixpkgs-ci nixpkgs-ci bot added the 12.approvals: 1 This PR was reviewed and approved by one person. label Oct 26, 2025
`zizmor` is a tool that uses static analysis to find potential security
issues in GitHub Actions [0]. (Yes, it's a bit absurd that GitHub
made a CI system so complicated that tools like this were created, but
I digress.)

Given our increase in GHA usage recently, I think this is a good step
towards keeping our security posture in tip-top shape. (It also keeps
with the theme of automating as many things as possible!)

The rule related to the usages of dangerous-triggers have been disabled
to avoid false-positives. Explanations about the usage of
`pull_request_target` and expectations around its usage can be found in
`.github/workflows/README.md`.

[0]: https://woodruffw.github.io/zizmor/

Co-authored-by: Thomas Gerbet <thomas@gerbet.me>
@LeSuisse
Copy link
Copy Markdown
Member

Typo fixed, thanks!

The recent changes done on the CI have helped quite a lot to make this as straightforward as possible 💚

@nixpkgs-ci nixpkgs-ci bot added 12.approvals: 2 This PR was reviewed and approved by two persons. and removed 12.approvals: 1 This PR was reviewed and approved by one person. labels Oct 27, 2025
@wolfgangwalther wolfgangwalther added this pull request to the merge queue Oct 27, 2025
Merged via the queue into NixOS:master with commit 8e19f0f Oct 27, 2025
59 of 62 checks passed
@nixpkgs-ci

This comment was marked as outdated.

1 similar comment
@nixpkgs-ci

This comment was marked as outdated.

@nixpkgs-ci
Copy link
Copy Markdown
Contributor

nixpkgs-ci bot commented Oct 27, 2025

Successfully created backport PR for release-25.05:

@github-actions github-actions bot added the 8.has: port to stable This PR already has a backport to the stable release. label Oct 27, 2025
Copy link
Copy Markdown
Contributor

@philiptaron philiptaron 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 stoked to see this land. Thanks to @winterqt and @LeSuisse for authorship!

# For more info, see the documentation: https://woodruffw.github.io/zizmor/usage/#ignoring-results

rules:
dangerous-triggers:
Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

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

This was the source of https://ptrpa.ws/nixpkgs-actions-abuse, correct?

Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

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

One of the 3 factors, yes. Since we can not get rid of pull_request_target, we must focus on the other two instead. That trigger being dangerous means we must use it in the safest way possible. We do use explicit trusted/ and untrusted/ folders for all the checkouts to make it obvious when untrusted code is executed. And we committed to move away from Bash recently. I think we're in a good spot.

Copy link
Copy Markdown
Member

Choose a reason for hiding this comment

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

Can't we disable this on a per-usage basis? Globally disabling it whilst this is a thing we actually got pwned by seems to kind of defeat the purpose of the tool. I want this to fail hard in CI and have people add a #zizmor-ignore comment if they really want to use dangerous triggers

Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

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

We decided to disable it globally in #396451 (comment). The exclusion list was almost every workflow file back then - so there was really no point in doing it differently.

This is different by now - since we rely much more on re-usable workflows which are triggered in a single parent workflow. Still, we have pull_request_target 4x, and pull_request only a single time. The latter is an exception for a very specific use-case.

Due to the way that the workflows are structured:

  • New jobs will not be added in new workflow files, so people are not going to write new triggers the majority of time. When they do, they are likely implementing something that needs permissions, because it's something outside the regular PR workflow - which means it's some kind of automation. But even for more automation, it's unlikely that anyone will actually write a new workflow with pull_request_target or pull_request.
  • Contributors to those files will need to know that they are actually in a pull_request_target context - despite this trigger being written in a separate file. So they can't really tell from the on: part of the workflow file they are in anyway, due to those re-usable workflows. Also, these workflows are designed to be run in both triggers, depending on the parent workflow.

a thing we actually got pwned by

Again, no. We were not pwned by using this trigger. We were pwned by using it wrong. The idea of marking this trigger "dangerous" is kinda stupid to begin with. If you were to never use this kind of trigger, then, sure, you have fewer risks. But also, you can't make use of any secrets or elevated permissions in CI. So once you start putting secrets into GHA configuration, you'll have to start thinking about this. Is putting secrets in via GHA's configuration specifically designed for that considered "bad practice"? I don't think so.


I won't oppose somebody changing this to put these comments in these 4 places - but I'll also say that this won't make any meaningful difference for security. If you feel better when removing this global option, but adding individual disable comments - then I'm afraid you are not seeing the real threats that we have to deal with for CI: Injection and running untrusted code. These are far more likely to mess up.

Copy link
Copy Markdown
Member

Choose a reason for hiding this comment

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

Side note, I also noticed we have one usage of workflow_run which can also be problematic

Maybe we should also add a note in .github/workflows/README.md?

https://securitylab.github.com/resources/github-actions-new-patterns-and-mitigations/#security-boundaries-and-workflow_run-event

Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

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

We will very likely have more workflow_run and also issue_comment soon. All of which are giving access to secrets, yes.

The default assumption for everything in CI must be that it will run in these contexts, where elevated permissions are possible and secrets are available.

To put it differently: Of the 16 workflow files we have, only two workflow files can be considered "safe" according to the "dangerous triggers" definition. All other 14 workflow files have access to secrets and permissions.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

6.topic: continuous integration Affects continuous integration (CI) in Nixpkgs, including Ofborg and GitHub Actions 6.topic: policy discussion Discuss policies to work in and around Nixpkgs 8.has: port to stable This PR already has a backport to the stable release. 10.rebuild-darwin: 0 This PR does not cause any packages to rebuild on Darwin. 10.rebuild-linux: 0 This PR does not cause any packages to rebuild on Linux. 12.approvals: 2 This PR was reviewed and approved by two persons.

Projects

None yet

Development

Successfully merging this pull request may close these issues.

10 participants