Are We PEP740 Yet?
trailofbits.github.io
trailofbits.github.io
The implementation is interesting - it's a static page built using GitHub Actions, and the key part of the implementation is this Python function here: https://github.com/trailofbits/are-we-pep740-yet/blob/a87a88...
If you read the code you can see that it's hitting pages like https://pypi.org/simple/pydantic/ - which return HTML - but sending this header instead:
Accept: application/vnd.pypi.simple.v1+json
Then scanning through the resulting JSON looking for files that have a provenance that isn't set to null.Here's an equivalent curl + jq incantation:
curl -s \
-H 'Accept: application/vnd.pypi.simple.v1+json' \
https://pypi.org/simple/pydantic/ \
| jq '.files | map(select(.provenance != null)) | length'It's quite interesting to see, but they rarely become particularly popular outside of that community.
In practice, that never really panned out (very few users actually attenuated their credentials). If we were to reimplement PyPI's API tokens today, I'd likely go with a more traditional design (even though all of this is a black box from a normal user's perspective - a Macaroon looks like a normal opaque token, just chunkier).
The vast majority of breaches are caused by credential theft, phishing, and exploiting vulnerabilities.
It doesn't matter that you can cryptographically verify that a package came from a given commit if that commit has accidentally-vulnerable code, or someone just gets phished.
https://www.wired.com/story/notpetya-cyberattack-ukraine-rus...
https://krebsonsecurity.com/2020/12/u-s-treasury-commerce-de...
Software supply chain attacks are rare, but when they happen, they're usually high-impact ordeals.
Where I work (highly regulated financial utility), we would absolutely love to have signed attestations for the provenance of python packages.
I also have personal experience of NotPetya; I produced the forensic analysis of how it compromised the whole of Maersk. Took less than 30 minutes to take out their entire global IT infrastructure, with a cost of about $400 million.
We are not there as long as Jenkins and most build infrastructure is basically Remote exploit as a service it is also going to take a long time. While Petya like in Ukraine is harder the more attestations you add there is always a hole, especially when all of your infrastructure needs to run things from some proprietary vendor.
They could instead use a cloud-based trusted execution environment on Azure, and get an attestation from some combination of Intel and Microsoft.
Or they could use a TPM and get an attestation from Infineon that the Microsoft-signed shim loaded a kernel blessed by a Microsoft-approved Linux vendor such as Canonical.
Seems to me that just trades one corporate attestation for another.
What would work better is if _everybody_ could run the same CI action to produce a release tarball, and it produced identical builds, and everyone doing this could publish their findings - we can federate a heterogenous network of verifiers, rather than trust a single source's attestation
This is just another step in increasing security. And of cause that is something you want to preferably do prior to breaches not only as a reaction.
Source: I wrote the contract for it.
Working on stuff outside of the top 99%+ of effective solutions deserves to be questioned.
As an alternative, they could have been investing time in a form of capabilities-based security for packages like Deno has where not every pip package can spawn info stealer processes at install time or runtime. That would address both the build compromise attacks and actually-common attacks like vulnerability exploitation.
Because it's a tractable problem that these devs can solve - and just because they're working on this doesn't meant they (or others) aren't also working on the other things.
> It doesn't matter that you can cryptographically verify that a package came from a given commit if ...
Sure, but just because it doesn't solve every single problem doesn't mean it's not worthwhile
So you get suit-compatible catch phrases like "SBOM" (notice how free software has been deliberately degraded to "materials" in that acronym!).
The corporations want to control open source, milk it, feed it to their LLMs, plagiarize it and so forth. And they pay enough "open" source developers who sell out the valuable parts that are usually written by other people.
As you say, it's partly security theater because of the other attack vectors that are especially relevant in an organization that has no stringent procedures, no open discussion culture or commitment to correctness like e.g. FreeBSD.
If that commit has accidentally-vulnerable code, or someone just gets phished and attacker added some malicious code to the repository with his creds, it is visible.
However, if the supply chain was secretly compromised and the VCS repo was always clean, only the release contains malware, then good luck finding it out.
We've all witnessed this earlier this year, in the xz accident, while the (encrypted) malicious code was presented in the source code repo as part of test data, the code to load and decrypt it only ever existed in release tarballs.
I thought this was about ensuring the code that developers pushed is what you end up downloading.
You might want to revisit the script of xz backdoor.
---
From the docs:
> PyPI's support for digital attestations defines a strong and verifiable association between a file on PyPI and the source repository, workflow, and even the commit hash that produced and uploaded the file.
I appreciate that it’s a community effort and compute isn’t free, but Launchpad did this correctly from the very beginning — dput your signed dsc and it will build and sign binary debs for you.
https://xkcd.com/2347/ all over again.
I'm also happy with the Launchpad approach, but even happier with debian's Reproducible Builds approach; you _can_ provide a binary package that you built on your own machine, but several other people will _also_ build it. With a reproducible build, they will all get _exactly_ the same result for a given architecture. If they don't... we've found a problem.
I'd prefer to trust:
* the creator of the package over the distributor of the package
* a multitude of independent distributors who can all vouch the package builds the same for them, over a single distributor who builds it themselves and says "trust me bro"
Code checked out from the repository was not the same that was used to build the actual release. These are not high-likelyhood incidents but when they do occur, they tend to have high impact.
And more recently, semantically similar code-vs-build mismatch: CrowdStrike. The broken release was modified after the actual build step, as per their own build process, and the modified artifact is what was released.
Yes, the thing wasn't caught because of missing QA. What I find even worse is that the build process for their "channel files" involved:
* building a release in CI, for which tests were run
* modifying the built artifact as a post-process step, and
* uploading this modified end result into their CDN infrastructure
In effect, what they actually built from their sources in the CI pipeline was not what was delivered to end users. You are correct in that attestations wouldn't help against such flagrant lies. And it wasn't a malicious act (although maliciously incompetent might qualify).That post-build modification step would fly in the face of the attestation concept. It wouldn't help against having an empty set of tests, but an attestation-friendly build process at least would discourage messing around with the artifacts prior to release.
This thing is a non-solution to a non-problem. (The adversaries won't be MiTM'ing Github or Pypi.)
The actual problem is developers installing "foopackage" by referencing the latest version instead of vetting their software supply chain. Fixing this implies a culture change where people stop using version numbers for software at all.
/"Rolls eyes" would be an understatement/
Attestations provide cryptographic proof linking published packages to specific code states. This proof can be verified independently of PyPI - reducing exclusive trust in the package index.
Worth noting, attestations aren't a complete defense against index compromises since an attacker could simply stop serving attestations (though this would raise alerts for users monitoring their dependencies' attestation status).
Is this a silver bullet? No. If an attacker compromises a project's source repository, attestations won't help. However, it meaningfully reduces certain attack vectors and moves us towards being able to cryptographically verify the entire chain from source code to deployed package.
(Disclaimer: I helped build this feature for PyPI)
But that's a huge attack surface.
Update: That a control doesn't solve all problems is irrelevant. By that measure, we would have no controls at all.
Does the community have any ideas about that?
Patch, apply principle of least privilege, make sure everyone uses strong authentication. Monitor the system.
For SCM specific controls we could also require signed commits, apply branch protection and any other system specific controls, and enforce code reviews before commit.
- Connects to HDMI
- Monitors any text that's on the screen
- Checks that the user is watching the screen (or at least is at the computer)
- Checks that any changes committed into the Git repository have been at least on the user's screen for X seconds, while they were sitting near the computer.
urllib3 does not have a recent release that could explain https://trailofbits.github.io/are-we-pep740-yet/ lagging behind.
However, they have not published a new version since the beginning of attestation support in PyPI. That's the meaning of the clock icon right to the package name.
Their workflow responsible for publishing new releases [1] has support for attestations. Thus, it will turn green on this page with the next project release.
[1] https://github.com/urllib3/urllib3/blob/main/.github/workflo...
"I am trusted."
It's basically the same model as HTTPS. Not sure if it has a name. "Too big to fail" security? Security by fiat?
Can I make my package green without having to compromise my integrity by utilising proprietary git hosting?
For many smaller packages in this top 360 list I could imagine this representing quite a bit of a learning curve.
If you're going to cast aspersions about hidden motives, you might as well cast them at the right entity.
If that's the case, it doesn't matter which megacorporation sponsors the work; it benefits all of them.
I'm not saying this specific security initiative is or isn't worthwhile, that remains to be seen. But whether it was intended or not, it's a windfall to Microsoft for an advocacy website to demand PEP740 when? and the most practical way to apply it right now is Microsoft's proprietary offering.
Also, if I'm reading this correctly, the docs warn you off setting up your own Trusted Publisher and steer you towards using an existing one... of which there is currently only one choice, Microsoft. That's just an endorsement with extra steps.
As I've said about 50 times in the last day: the only reason GitHub is being used for examples and was the first one enabled is because that's where the overwhelming majority of PyPI upload traffic comes from. It's not a commitment or an endorsement; it's a strictly strategic move to help the largest uploading demographic first.
The bigger problem is for projects that aren't hosting on GitHub and using GitHub Actions - I'm sure there are quite a few of those in the top 360.
I expect that implementing attestations without using the PyPA GitHub Actions script has a much steeper learning curve, at least for the moment.
I can speak for experience. Py4J is on that list and getting maintainers is very difficult (for various reasons). Packaging is also not something that naturally attracts contributions.