Is there a way to configure an npm package to *require* provenance and fail any publish attempts that don’t have it? I don’t think the Trusted Publisher stuff has that option, if I’m reading it correctly.
Also posted to Bluesky.
23 replies
maybe a cheeky and very optional cc to @notwes.bsky.social
There is no way today.
One of the many gaps I’ve been asking them to fill.
Despite me saying that providence is completely pointless, if they are going to push this then they should at least do it right.
Joking aside, the reason they can’t enforce this is because there’s a whole bunch of gaps in the way that the system works. It’s why most of the folks who tried publishing with providence had to disable it in some cases.
Even the new pnpm feature is not easily turned on for many repos.
@zachleat Could you add a check to the prepublishOnly command? https://docs.npmjs.com/cli/v7/using-npm/scripts#:~:text=for%20more%20info.-,prepublishOnly,-Runs%20BEFORE%20the
@zachleat The prepare command doesn't run on --dry-run so possibly that's a better place to hook?
@castastrophe ah, yeah — I am mostly thinking about security footprint here. If a token is compromised, this might help prevent malicious code (because it would need that code to exist in the repo too)
If you have Trusted Publishing enabled and enforced, which attack vector are you trying to guard against here?
as far as I can tell, you can use Trusted Publishing *without* Provenance. so if your CI is compromised, an attacker could still publish untracked malicious code, no? I want all of the code published to have a “paper trail” tied to GitHub commits
There is at least one case it is required to be turned off when used with OIDC/TP: when the name of the package does not match the repo name.
At least this was true last month, I haven't tested again since.
> I want all of the code published to have a “paper trail” tied to GitHub commits
FWIW, you have always had this:
curl registry.npmjs.com/@11ty/eleventy | jq '.versions["3.1.2"].gitHead'
What provenance adds is theater on top of this. Not only does it add nothing to verify the reproducibility of that tarball from that git commit, it only stores a link to the GHA that built it which expires after 90 days.
I see what you mean, especially if you’re doing a lot of prepublish transpilation (et al).
I’m curious if _requiring_ provenance would be good enough to fix most of the big leaks in simpler projects. (I also wonder separately if TP would have been better without the option to disable provenance?)
The stuff is hard to go into detail over posts here. But the TLDR is neither providence nor trusted publishing fix the root of the problems that have been leading to our recent spree of attacks.
Enforcing 2FA would.
The automated publishing attacks have relied on two things:
- Local tokens
- compromised CIThose only apply to the second, and if you compromise the CI you can publish *from* the CI with provenance and TP checked passing.
It changes the attack, but it doesn’t fix it.
And for local publishing you can enforce 2FA. Which is explicitly not allowed with trusted publishing “by design”.
Is it? Seems like the npm metadata is user controlled (a nice signal, little more) while TP provenance does give some guarantee (backed by GitHub) that the code at the recorded commit hash generated the output.
Stores the commit hash as well, so GHA history would be nice but not strictly necessary.
It’s definitely somewhat different, and if it was implemented differently, it could provide a stronger signal.
We’ve had a bunch of public conversations about this topic, and I’m not gonna rehash years of context every time this discussion comes up on here.
The theory is great. What shipped is an incomplete and often misleading mess. I have used the above method for the past four years responding to real security incidents.
Not once has providence helped, and trusted publishing has removed one critical feature rely on (the publishing user).
The first time that they githead is spoofed I will absolutely change my opinion on this. But that has not happened once that I have seen.