News for hackers. Stuff that matters.
Re:We Executed a Critical Supply Chain Attack on PyTorch by o11c on Sunday January 14, 2024 @02:31PM (#38993609)
The problem is that there are fundamentally 2 different kinds of builds, but the current tooling is weak:

* 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.

Re:We Executed a Critical Supply Chain Attack on PyTorch by akx on Sunday January 14, 2024 @03:48PM (#38994312)
For the second point, PyPI's trusted publisher implementation does this very well: https://docs.pypi.org/trusted-publishers/
Re:We Executed a Critical Supply Chain Attack on PyTorch by LtWorf on Monday January 15, 2024 @12:54AM (#38997805)
Isn't that what's causing the problem?

Without that there would be no need to have an action to do an upload. It could be comfortably and safely done offline.

Re:We Executed a Critical Supply Chain Attack on PyTorch by trevyn on Sunday January 14, 2024 @04:10PM (#38994472)
It’s called GitHub secrets.

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.

Re:We Executed a Critical Supply Chain Attack on PyTorch by n2d4 on Sunday January 14, 2024 @04:39PM (#38994693)
Pytorch did use GH secrets for the valuables and you can see that this wasn't enough, right there in the OP, because the self-hosted runners are still shared
Re:We Executed a Critical Supply Chain Attack on PyTorch by adnanthekhan on Sunday January 14, 2024 @05:50PM (#38995257)
Yup! This is what makes this kind of attack scary and very unique to GitHub Actions. The baseline GITHUB_TOKEN just blows the door open on lateral movement via workflow_dispatch and and repository_dispatch events.

In several of our other operations, not just PyTorch, we leveraged workflow_dispatch to steal a PAT from another workflows. Developers tend to over-provision PATs so often. More often than not we'd end up with a PAT that has all scopes checked and org admin permissions. With that one could clean out all of the secrets from an organization in minutes using automated tools such as https://github.com/praetorian-inc/gato.

Re:We Executed a Critical Supply Chain Attack on PyTorch by trevyn on Sunday January 14, 2024 @06:23PM (#38995503)
To clarify, this secret stealing is not an issue with GitHub-hosted runners, correct?
Re:We Executed a Critical Supply Chain Attack on PyTorch by adnanthekhan on Sunday January 14, 2024 @06:43PM (#38995662)
Correct. For fork PR workflows on the pull_request trigger the GITHUB_TOKEN has read only permissions, so you can’t do anything with it.

The key thing with a non-ephemeral runner is that (after obtaining persistence) you can grab the GITHUB_TOKEN from a subsequent non-fork PR build or a build on another trigger, which will have write permissions unless restricted by the repository maintainers.

Re:We Executed a Critical Supply Chain Attack on PyTorch by lmeyerov on Monday January 15, 2024 @11:03AM (#39002325)
I think 'environments' was meant, where diff GHA environments get diff secrets, and policies dictate who gets to run what actions with what envs.

But that is real work to setup, audit, and maintain. It'd be better if, like phone app capabilities, the default would be no privs, any privs are explicitly granted, and if they aren't being used, the system detects that and asks if you want to remove specific ones.

Re:We Executed a Critical Supply Chain Attack on PyTorch by gabriel-samfia on Tuesday January 16, 2024 @07:40AM (#39012650)
Ouch! This is why ephemeral runners should be used. Preferably virtual machines. On an infrastructure that can define security group rules to prevent lateral movement.
Re:We Executed a Critical Supply Chain Attack on PyTorch by mlazos on Sunday January 14, 2024 @05:28PM (#38995075)
If they use the same runners, couldn’t the attacker just wait? The runners would need to be sequestered too
Re:We Executed a Critical Supply Chain Attack on PyTorch by kevin_nisbet on Sunday January 14, 2024 @05:57PM (#38995308)
Absolutely. The real difficulty is tests on PR are by definition remote code execution by an untrusted source, so a full risk analysis and hardening needs to be done.

Here's a similar mistake on an OSS repo a company I worked for made: https://goteleport.com/blog/hack-via-pull-request/

Re:We Executed a Critical Supply Chain Attack on PyTorch by LtWorf on Monday January 15, 2024 @12:55AM (#38997807)
> Not rocket science, people.

The smugness and overconfidence of someone who's about to be pwned?

Re:We Executed a Critical Supply Chain Attack on PyTorch by trevyn on Monday January 15, 2024 @04:16AM (#38998821)
Pwn me.
Re:We Executed a Critical Supply Chain Attack on PyTorch by snnn on Sunday January 14, 2024 @11:39PM (#38997518)
Ideally the builds for external PRs should not gain any access to any secret. But it is not practical. For example, you may want to use docker containers. Then you will need to download docker images from somewhere. For example, downloading ubuntu:20.04 from docker hub. That one requires a token, otherwise your request may get throttled. Even accessing most Github services requires a token. I agree with you that these things require a lot of care. In reality most dev teams are not willing to put enough time on securing their build system. That's why supply chain attacks are so common today.
Re:We Executed a Critical Supply Chain Attack on PyTorch by LtWorf on Monday January 15, 2024 @12:52AM (#38997798)
> These "need" privileges to upload the resulting artifacts somewhere.

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.

Re:We Executed a Critical Supply Chain Attack on PyTorch by Bognar on Tuesday January 16, 2024 @11:54AM (#39015507)
If you're using GHA to publish then you still need a trusted branch to provide secrets to. If you're not publishing using CI, then you can still upload to PyPI manually with an API Token.

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

Re:We Executed a Critical Supply Chain Attack on PyTorch by LtWorf on Tuesday January 16, 2024 @04:04PM (#39019121)
> If you're using GHA to publish then you still need a trusted branch to provide secrets to

The vulnerability was exactly that the secrets of the trusted branch can get leaked :)

> you can still upload to PyPI manually with an API Token

I can, BUT if you want to be a Trusted Publisher™ the only way is to do it via github.

https://docs.pypi.org/trusted-publishers/

Most likely the plan is to make it compulsory for all projects eventually, just like they made 2fa compulsory.

So less secure is considered as MORE secure by pypi :) Which is consistent with the idea that no PGP signature is more secure than signed uploads. Or the idea that a global token in a clear text file is somehow safer than a password that gets typed every time.