Repository navigation
Description
🐛 Bug Report
The documented CI recipe for authenticating vlt install against the vlt registry does not work: VLT_TOKEN_<registry> environment variables are never consulted by the request-level token lookup, so requests go out without an Authorization header and the registry answers 401.
Both registry/using-packages.mdx ("Installing in CI") and registry/tokens.mdx ("Using tokens in CI") recommend exactly this form:
VLT_TOKEN_https_registry_vlt_io_acme_npm="<service token>" \
VLT_TOKEN_https_registry_vlt_io_acme_main="<service token>" \
vlt install✅ Expected Behavior
Setting VLT_TOKEN_<normalized registry URL> for each configured registry (as documented in cli/auth.mdx and the registry docs) is enough for vlt install to send Authorization: Bearer <token> on every request to that registry.
❌ Actual Behavior
No Authorization header is sent. Reproduced against a local logging registry (Node HTTP server that records method, path and authorization, always answers 401) with vlt.json registries.npm = http://127.0.0.1:4899/acme/npm/, an empty keychain and fresh XDG dirs:
| env | Authorization sent |
|---|---|
VLT_TOKEN_http_127_0_0_1_4899_acme_npm=x (documented form) |
none → 401 |
VLT_TOKEN_http_127_0_0_1_4899=x (origin form) |
none |
VLT_REGISTRY=http://127.0.0.1:4899/acme/npm/ VLT_TOKEN_http_127_0_0_1_4899_acme_npm=x |
Bearer x (works only because VLT_REGISTRY seeds a candidate) |
scoped @acme/utils → main registry, VLT_TOKEN_http_127_0_0_1_4899_acme_main=x (with or without VLT_REGISTRY) |
none |
Consequence: there is no env-only way to authenticate two registries (npm mirror + private main) from CI, which is the standard vlt.io setup produced by vlt setup.
Root cause
getTokenByURL() in src/registry-client/src/auth.ts builds its candidate list from runtime tokens, VLT_REGISTRY and keychain keys only. VLT_TOKEN_* env vars are never enumerated. The fallback at the end of the function:
// Fall back to origin-only match (handles VLT_TOKEN_* env vars
// which we can't enumerate by URL).
return getToken(requestUrl, identity)passes the full request URL, so getToken() looks up VLT_TOKEN_http_127_0_0_1_4899_acme_npm_lodash (or ..._acme_npm_lodash_lodash_4_17_21_tgz) which never matches. The comment is also inaccurate: normalizeRegistryKey keeps the pathname, so this is not an origin-only match.
Fix sketch
- In
getTokenByURL, add everyprocess.envkey with theVLT_TOKEN_prefix to the candidate list (the normalized key can be recovered by matching the_-mangled form against the normalized request URL), and/or add every configuredregistriesURL (the client already hasoptions.registries) as a candidate. - Add a request-level test:
src/registry-client/test/auth.tsonly exercisesgetToken()directly, which is why this was not caught.
🌍 Environment
- OS: linux
- Node: 24.18.1
- vlt: 1.0.8 (
auth.tsunchanged at currentmain)
🔄 Frequency
Always
Activity
ruy-bot commentedon Sep 14, 2026
Related: #1845 (plain
VLT_TOKENonly works withVLT_REGISTRY).registry-client: fix env vars by request URL (#1869)
registry-client: send VLT_TOKEN_<registry> (vltpkg#1962)