Skip to content

impl(058): every npm package carries provenance (A-87) - #555

Merged
bartekus merged 2 commits into
mainfrom
npm-provenance
Nov 7, 2026
Merged

bartekus merged 2 commits into
mainfrom
npm-provenance

Conversation

@bartekus

@bartekus bartekus commented Nov 7, 2026

Copy link
Copy Markdown
Contributor

Every npm package rustev releases now carries npm provenance (owner decision A-87, 2026-11-07, superseding A-74 for releases after 0.5.0).

What changes:

  • publish-npm keeps npm trusted publishing (OIDC) as the first path. When npm refuses the exchange ([BUG] OIDC trusted publishing fails with "package not found" for GitHub repos that use immutable OIDC subject claims npm/cli#9969, immutable OIDC subject, still open), npm falls back to a granular token held only by the npm-publish Environment as NPM_TOKEN. --provenance signs with the job's OIDC token on both paths. Without the secret the job is trusted publishing only.
  • The publisher refuses an npm version that is public with the run's integrity but without an SLSA build-provenance attestation (Lookup::Unattested). A hand publish now turns the release red instead of being recorded present. verify-release's registry observation refuses it too.
  • Spec 058 3.3.2, 3.3.4 and 3.5.2 amended; decision A-87 recorded.

Evidence: v0.4.0, v0.4.1 and v0.5.0 each failed publish-npm with ENEEDAUTH on the first attempt; npm lists every version as published by the owner's account; no @rustev/* version has dist.attestations.

Owner actions before 0.6.0:

  1. Recreate the expired trusted publishers for all nine @rustev/* packages (statecrafting/rustev, release.yml, environment npm-publish).
  2. Add a granular publish token for @rustev/* as the NPM_TOKEN secret of the npm-publish Environment (only needed while [BUG] OIDC trusted publishing fails with "package not found" for GitHub repos that use immutable OIDC subject claims npm/cli#9969 is open).

Checks: cargo test -p rustev-release --locked, clippy -D warnings, fmt, make gate. This changes .github/workflows/release.yml, so it needs the statecraft-review-exception approval.

@github-actions

github-actions Bot commented Nov 7, 2026

Copy link
Copy Markdown

AI review (findings)

Review of PR 0b79f34

Overview: This PR adds a fallback granular-token path for npm publishing when npm refuses the OIDC trusted-publishing exchange (npm/cli#9969), and enforces that every published npm package carries SLSA build-provenance attestation. Changes span the release workflow, spec 058, the release tool's lifecycle/hosted/tagged logic, and tests.

Mechanics

Workflow (release.yml): The configure step writes //registry.npmjs.org/:_authToken=${NPM_TOKEN} (literal ${NPM_TOKEN}, never the value) to $RUNNER_TEMP/.npmrc and sets NPM_CONFIG_USERCONFIG via $GITHUB_ENV only when the secret is non-empty. The publish step exposes NPM_TOKEN to the environment so npm can expand the reference at runtime. --provenance signs with the job's OIDC token independently of the auth path. This is structurally sound.

Provenance check (hosted.rs): npm_has_provenance requires both a non-empty dist.attestations.url and a predicateType starting with https://slsa.dev/provenance/. The JSON parsing refactor (unwrap_or_default() vs .ok()) produces identical results on parse failure (both reach Unknown { "npm response lacks integrity" }).

Lookup::Unattested variant (lifecycle.rs, tagged.rs): Correctly refused wherever presence is checked; two-arm coverage (pre-existing unattested package, and upload that lands without provenance) is verified by new tests.

Test coverage: release_workflow.rs now verifies that secrets.NPM_TOKEN appears exclusively inside publish-npm, which is a sound constraint.

Finding

observe_crates handles Lookup::Unattested — dead code for crates (tools/rustev-release/src/hosted.rs, line 17 of the diff)

lifecycle.rs documents the Unattested variant as "npm only (A-87)." The crates.io registry implementation is not shown in this diff, but nothing in the code path that calls observe_crates would produce this variant for a crates lookup; the arm is currently unreachable. It doesn't cause incorrect behavior — if ever reached it would correctly report a provenance error — but its presence is inconsistent with the "npm only" constraint documented one file away and may mislead maintainers into thinking crates provenance is enforced.

{"head": "0b79f34ac5edd395da31a18451f55927fb410347", "verdict": "findings", "findings": [{"path": "tools/rustev-release/src/hosted.rs", "line": 17, "severity": "low", "category": "correctness", "summary": "The Unattested arm in observe_crates is dead code: lifecycle.rs documents Unattested as npm-only, and the crates registry implementation does not produce this variant, creating a misleading inconsistency with the documented constraint."}]}

Subject: 186dbc9...0b79f34, diff digest 952756db86b69284532cb838dbd59ac789fdb1e1c7bf0f7097a63bdddd9f58a1, 1 call(s). An AI comment is not an approval.

@bartekus
bartekus temporarily deployed to statecraft-review-exception November 7, 2026 21:12 — with GitHub Actions Inactive
@github-actions

github-actions Bot commented Nov 7, 2026

Copy link
Copy Markdown

AI review (no-findings)

Reviewing the diff across all changed paths: workflow, decision record, spec, and the Rust implementation in tools/rustev-release.

.github/workflows/release.yml

The configure-token step correctly writes the literal string '//registry.npmjs.org/:_authToken=${NPM_TOKEN}' (single-quoted, so the shell never expands it) to $RUNNER_TEMP/.npmrc, then sets NPM_CONFIG_USERCONFIG via $GITHUB_ENV. npm expands ${NPM_TOKEN} from the environment when it reads the file. The token is only available as an env var in the two steps that declare it. Setting NPM_CONFIG_USERCONFIG in $GITHUB_ENV persists it for subsequent steps, but those steps (upload-artifact etc.) don't invoke npm and don't have NPM_TOKEN in their environment, so the .npmrc reference would resolve to an empty value rather than leaking the secret.

tools/rustev-release/src/hosted.rs — npm_response refactor

Old code chained .ok().and_then(...), returning Unknown on parse failure. New code uses unwrap_or_default() which gives Value::Null; indexing Null with string keys also gives Null, so .as_str() returns None and the branch still falls to Unknown { detail: "npm response lacks integrity" }. The two paths are equivalent on all inputs.

npm_has_provenance

Checks dist.attestations.url non-empty and dist.attestations.provenance.predicateType starts with https://slsa.dev/provenance/. This matches the spec text "its version document also names an SLSA build-provenance attestation (dist.attestations)". The prefix check is forward-compatible with SLSA v0.2 and v1.

tools/rustev-release/src/lifecycle.rs / tagged.rs / hosted.rs

Unattested is handled in every match arm where Lookup is consumed: initial presence check, post-upload poll loop, and the defensive arm in observe_crates (correctly refuses it rather than treating it as Visible, with an explanatory comment that crates.io never returns it).

Spec 058 / A-87

The spec accurately describes the new behaviour: trusted publishing first, granular-token fallback when refused, --provenance on both paths, refuse-not-republish on Unattested. Section 3.3.4's updated wording ("other than the OIDC tokens of trusted publishing and, in publish-npm only, the fallback token of 3.3.2") matches the actual workflow. The idempotency rule (3.5.2) now correctly requires attestation presence before accepting a version as present.

tools/rustev-release/tests/release_workflow.rs

The test verifies that secrets.NPM_TOKEN is the only secret read, and only inside publish-npm. The WORKFLOW.replace(&npm, "") removes the full job text (unique in the file) before counting remaining secret references.

tools/rustev-release/tests/tagged.rs

present_without_provenance_fails_and_republishes_nothing and an_upload_that_lands_without_provenance_fails correctly cover the two Unattested code paths. The assertion that fake.published == ["a"] and r.entries.is_empty() is consistent with the error being returned before "b" is processed and before any entry is recorded.

No concrete defects found.

{"head": "c8f1c479bd87825d1784a466455b33b255007d17", "verdict": "no-findings", "findings": []}

Subject: 186dbc9...c8f1c47, diff digest f86ad653bacd7d33b28febe13a917acbef196a52cf904cbf388e18aacee20b98, 1 call(s). An AI comment is not an approval.

@bartekus
bartekus temporarily deployed to statecraft-review-exception November 7, 2026 21:29 — with GitHub Actions Inactive
@bartekus
bartekus added this pull request to the merge queue Nov 7, 2026
@github-merge-queue
github-merge-queue Bot removed this pull request from the merge queue due to a conflict with the base branch Nov 7, 2026
@github-actions

github-actions Bot commented Nov 7, 2026

Copy link
Copy Markdown

AI review (no-findings)

Reviewing the diff for bugs, security defects, and inconsistencies against the governance context.

Workflow: .github/workflows/release.yml

The configure step writes //registry.npmjs.org/:_authToken=${NPM_TOKEN} as a literal string (single-quoted, shell won't expand) to $RUNNER_TEMP/.npmrc, then sets NPM_CONFIG_USERCONFIG in $GITHUB_ENV so subsequent steps pick it up. The publish step carries NPM_TOKEN in its env: block so npm can expand ${NPM_TOKEN} itself. The pattern is correct. The set -eu guard, the ${NPM_TOKEN:-} idiom for empty-variable safety, and the shellcheck suppression are all appropriate.

The secret is confined to publish-npm; no other job has an env: block referencing it. The new test in release_workflow.rs verifies this mechanically by extracting the job text and counting secrets. occurrences inside and outside it.

npm_response refactor (hosted.rs)

Old code: .ok().and_then(|v| …) — parse failure → None → Unknown { detail: "npm response lacks integrity" }. New code: unwrap_or_default() gives Value::Null on parse failure; Value::Null["dist"]["integrity"].as_str() is None, same branch. Semantically equivalent.

npm_has_provenance

Checks dist.attestations.url (non-empty) and dist.attestations.provenance.predicateType starting with "https://slsa.dev/provenance/", covering both v0.2 and v1 predicates. The test cases exercise the positive path, the wrong-domain negative, and the missing-attestations negative. No defect.

Lookup::Unattested handling

  • observe_crates: the crates.io path correctly treats Unattested as an error and returns a message rather than taking it as Visible — the defensive match is correct.
  • publish_items: immediate Err on pre-existing Unattested and on a poll that returns Unattested after upload. No republication attempt, consistent with spec 058 3.5.2 as amended.

Spec 058 amendments

Section 3.3.2 replaces hand-publication with the fallback-token path; 3.3.4 (registry-token scope) is updated to name the exception; 3.5.2 adds the provenance-required idempotency rule. All three are consistent with the code and with A-87.

Tests

present_without_provenance_fails_and_republishes_nothing and an_upload_that_lands_without_provenance_fails cover both pre-existing and post-upload Unattested paths. The Fake publisher's arm ordering (unattested before visible, both guarded on lag == 0) is correct.

No concrete defect found.

{"head": "aaa5a7baa73fd0fd1dc9805badf5fe7230bb96ec", "verdict": "no-findings", "findings": []}

Subject: e8f6653...aaa5a7b, diff digest ee0e0bf9d1387fd51aeeed0f931ee7a207e5d206549991b3187946ea536f78eb, 1 call(s). An AI comment is not an approval.

@bartekus
bartekus temporarily deployed to statecraft-review-exception November 7, 2026 22:22 — with GitHub Actions Inactive
@bartekus
bartekus added this pull request to the merge queue Nov 7, 2026
Merged via the queue into main with commit 583769b Nov 7, 2026
26 checks passed
@bartekus
bartekus deleted the npm-provenance branch November 7, 2026 23:47
bartekus added a commit that referenced this pull request Nov 8, 2026
…amends 031, 056 and 058)

Proposes spec 068 for #559. A-87 (#555) makes every npm release after
0.5.0 carry provenance at publication, but the qualification's npm step
still accepts a registry signature in place of provenance (A-74). The
draft makes the step require a verified SLSA build-provenance
attestation, bound to release.yml at the tag, for every version after
0.5.0; 0.1.0 to 0.5.0 keep A-74's rule. It records the NPM_TOKEN
fallback's removal as a conditional follow-up. It changes no code and
declares no extends edge; ratification is the owner's act.
bartekus added a commit that referenced this pull request Nov 8, 2026
…031, 056 and 058)

Spec 068 for #559, ratified by the owner on 2026-11-08 (A-88) with every
open question answered as recommended. A-87 (#555) makes every npm
release after 0.5.0 carry provenance at publication, but the
qualification's npm step still accepted a registry signature in place of
provenance (A-74). For every version after 0.5.0 the step now requires a
verified SLSA build-provenance attestation bound to the manifest
integrity and to release.yml at the tag, enforced in the harness and
again by rustev-release qualify; 0.1.0 to 0.5.0 keep A-74's rule. The
NPM_TOKEN fallback's removal is recorded as a conditional follow-up.
Declares the extends edge on tools/rustev-release/ (031, amending).
Decision row A-88. Target: the release after 0.6.0.

This branch was previously deployed

1 inactive deployment
statecraft-review-exception — aaa5a7ba Deployed Nov 7, 2026 by bartekus via review-exception #3745
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

1 participant