Static tokens vs credential helpers: handling mid-operation token expiry in pnpm CI/CD
0 reputation · 20 Feb 2021, 14:31 UTC
0 reputation · 20 Feb 2021, 14:31 UTC
Configuring least-privilege registry authentication for pnpm in CI/CD pipelines requires choosing between two documented approaches: (a) static read-only tokens scoped to specific registries in .npmrc, rotated manually, or (b) a credential helper that fetches short-lived tokens per request. Both satisfy granular access control, but they diverge when a token expires during a long-running operation such as pnpm install with many dependencies.
pnpm delegates authentication to the npm registry client. On HTTP 401/403 the client retries the request, yet the retry logic does not re-invoke a configured credential helper. If a static token expires mid-operation the command fails; if a credential helper supplied the token, the helper is not called again to obtain a fresh one. This behavior is documented as a gap in the current retry implementation.
pnpm install longer than the shortest token TTL, which approach minimizes manual intervention without adding per-request latency?.npmrc change the retry behavior compared to a single global token?npm-registry-fetch layer. It resends the exact same Authorization header it sent on the first request; it never re‑invokes npm config get credentialHelper. This is consistent across all registries (npmjs.com, GitHub Packages, Artifactory, etc.) and is unchanged up to pnpm 9.x..npmrc (e.g. //registry.example.com/:_authToken=…) does not change the retry logic. The same header is reused on retry, so expiration handling remains identical. The only advantage is reduced blast radius if the token is compromised.npm-registry-fetch/lib/fetch.js and clones the request options but preserves the original headers object.npm-registry-fetch and pnpm show that a 401 triggers a single retry that re‑uses the same Authorization header.pnpm install run in your environment (e.g. run pnpm install --dry-run and measure)..npmrc scoped to the relevant registry:
//registry.example.com/:_authToken=YOUR_TOKEN
To fine‑tune the TTL, could you share the longest observed pnpm install duration in minutes for your pipeline? That will help set the token lifetime precisely.
Use comments to ask for clarification. Post a solution as an answer.
No question comments on this page.