release: let npm authenticate itself instead of a placeholder token - #20
Merged
Conversation
setup-node's registry-url writes an .npmrc with _authToken pointing at NODE_AUTH_TOKEN, and sets that variable to a placeholder when no token is given. npm then authenticates with the literal placeholder and the registry answers 404 on the upload — after the provenance statement has already been signed and logged. A token in that file also beats the OIDC exchange trusted publishing exists to perform, so the fix is to write no file at all. npm whoami now proves the credential before anything is uploaded.
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
Add this suggestion to a batch that can be applied as a single commit.This suggestion is invalid because no changes were made to the code.Suggestions cannot be applied while the pull request is closed.Suggestions cannot be applied while viewing a subset of changes.Only one suggestion per line can be applied in a batch.Add this suggestion to a batch that can be applied as a single commit.Applying suggestions on deleted lines is not supported.You must change the existing code in this line in order to create a valid suggestion.Outdated suggestions cannot be applied.This suggestion has been applied or marked resolved.Suggestions cannot be applied from pending reviews.Suggestions cannot be applied on multi-line comments.Suggestions cannot be applied while the pull request is queued to merge.Suggestion cannot be applied right now. Please check back later.
The
npmjob of the v0.4.0 release failed. The crate published fine.A 404 on
PUTis npm's "not authorized" — it answers 404 rather than 403 so itdoes not leak whether a package exists. The cause is in the job's own env:
actions/setup-node'sregistry-urlwrites an.npmrccontaining//registry.npmjs.org/:_authToken=${NODE_AUTH_TOKEN}and sets that variable to aplaceholder when no token is supplied, so npm authenticated with the literal
string. A token in that file also takes precedence over the OIDC exchange, which
is the one thing trusted publishing exists to do — so
registry-urlis notmerely unnecessary here, it is what breaks it.
Provenance signed correctly because that needs only
id-token: write, which iswhy the failure surfaced after the statement had been pushed to the
transparency log.
The fix
registry-url, so no.npmrcis written and npm asks for its owncredential.
registry.npmjs.orgis the default; nothing needs to name it.npm whoamiafter the upgrade, so a missing or wrong credential failsbefore a provenance statement is signed and logged, rather than after.
Before this can work
Trusted publishing has to be configured for
@viict/treadon npmjs.com — repoviict/tread, workflowrelease.yml, environmentPackaging. If it is not,npm whoaminow says so immediately instead of the publish dying at the laststep.
v0.4.0 still needs publishing to npm by hand: a tag runs the workflow as it
existed at the commit it points at, so this fix takes effect from the next tag.