by simonw · 2y ago · 0 comments
Problem: you need to be a "contributor" to the repo for your PR to trigger workflows without someone approving them first.
So: "We needed to be a contributor to the PyTorch repository to execute workflows, but we didn’t feel like spending time adding features to PyTorch. Instead, we found a typo in a markdown file and submitted a fix."
I really don't like this aspect of GitHub that people who have submitted a typo fix gain additional privileges on the repo by default. That's something GitHub can fix: I think "this user gets to trigger PRs without approval in the future" should be an active button repo administrators need to click, maybe in the PR flow there could be "Approve this run" and "Approve this run and all future runs by user X" buttons.
Is the issue here that a self-hosted runner was needed for some hardware tests?
* pre-merge builds on PRs. These should not have privileges, but making the distinction between the two cases requires a lot of care.
* official builds of "master" or a feature branch from the main repo. These "need" privileges to upload the resulting artifacts somewhere. Of course, if all it did was wake up some daemon elsewhere, which could download straight from the CI in a verified way based on the CI's notion of the job name, it would be secure without privileges, but most CI systems don't want to preserve huge artifacts, and maintaining the separate daemon is also annoying.
Only because pypi removed support for gpg and their only "signature" now basically is "was uploaded from a gh action".
Otherwise a maintainer could do it offline without needing to give microsoft total access to uploading to pypi.
> without needing to give microsoft total access to uploading to pypi
I assume you're referring to Trusted Publishers here? It's a per-project configuration using the industry standard of OIDC that you don't have to opt in to, so "total access" is a silly characterization. Also if you're insinuating that MS is going to generate fraudulent OIDC tokens to compromise a PyPI package, then you might want to start weaning yourself off the kool-aid.
Without that there would be no need to have an action to do an upload. It could be comfortably and safely done offline.
Builds off of main get the secrets, pull requests from randos don’t.
And public repos don’t pay for CI on GitHub.
Not rocket science, people.
The smugness and overconfidence of someone who's about to be pwned?
When there are no side effects and no in-container secrets and the hosting is free or reasonably limited to prevent abusers, ideally yes.
Outside that, heck no, that'd be crazy. You're allowing randos to run arbitrary code on your budget. Locking it down until it's reviewed is like step 1, they can validate locally until then.
The issue is that now the pull requests don't get tested at all. I have to manually, locally, get all the commits, make a branch on the main repository with them, and then the actions run.
Challenge there is that if the pr changes, it's a bit clunky to retrigger the CI (you have to remove, then re-add).
I guess you could also do this with comments - can you trigger a workflow based on a specific comment being added from a specific user?
Afaict, a huge portion of this attack came from persistence on the self-hosted runner.
Absent that, they would have needed a container jailbreak as well, which substantially ups the difficulty.
And if a repo is running <100 builds a day, spin up + kill container seems a small per-build price to pay for the additional security isolation.
https://docs.github.com/en/actions/hosting-your-own-runners/...
^So you could reject a PR that tries to add a bitcoin-mining workflow only to have it start bitcoin-mining on close. Or leaking secrets, releasing nonsense, etc. (I don't recall if non-/contributor status was also a factor. I think it was also ignoring that check.)
What privileges do they gain? Anything other than the one you mentioned?
This was definitely not obvious to me, so thanks for bringing it up!
NONE, CONTRIBUTOR, COLLABORATOR, MEMBER, OWNER
There are some cases where people use checks for that as part of gating for workflows that run on pull_request_target/issue_comment, but might confuse contributor and collaborator (which requires explicitly adding someone to the repository). Ultimately this is a misconfiguration on part of the maintainer but another example where fixing a typo can play a part in an attack.