ci: add zizmor check and configuration#396451
Conversation
|
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. |
|
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. |
LeSuisse
left a comment
There was a problem hiding this comment.
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 💚
|
Still need to get to this, but want to fix up some things on Zizmor's end first. |
There was a problem hiding this comment.
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.
treefmt-nix is now shipping zizmor: numtide/treefmt-nix#354 |
|
@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. |
|
Go for it, @LeSuisse! |
|
@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>
|
Rebased the changes, resolved the conflicts and the remaining Zizmor issues. The Zizmor workflow has been replaced by the use of |
wolfgangwalther
left a comment
There was a problem hiding this comment.
LGTM; thank you!
Found a typo in the commit message of the second commit: "Explainations" -> "Explanations".
`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>
|
Typo fixed, thanks! The recent changes done on the CI have helped quite a lot to make this as straightforward as possible 💚 |
This comment was marked as outdated.
This comment was marked as outdated.
1 similar comment
This comment was marked as outdated.
This comment was marked as outdated.
|
Successfully created backport PR for |
| # For more info, see the documentation: https://woodruffw.github.io/zizmor/usage/#ignoring-results | ||
|
|
||
| rules: | ||
| dangerous-triggers: |
There was a problem hiding this comment.
This was the source of https://ptrpa.ws/nixpkgs-actions-abuse, correct?
There was a problem hiding this comment.
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.
There was a problem hiding this comment.
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
There was a problem hiding this comment.
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_targetorpull_request. - Contributors to those files will need to know that they are actually in a
pull_request_targetcontext - despite this trigger being written in a separate file. So they can't really tell from theon: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.
There was a problem hiding this comment.
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?
There was a problem hiding this comment.
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.
zizmoris 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
nix.conf? (See Nix manual)sandbox = relaxedsandbox = truenix-shell -p nixpkgs-review --run "nixpkgs-review rev HEAD". Note: all changes have to be committed, also see nixpkgs-review usage./result/bin/)Add a 👍 reaction to pull requests you find important.