Skip to content

[BUG] VLT_TOKEN_<registry> env vars are ignored by vlt install (documented CI auth recipe sends no Authorization header) #1844

Closed

Description

@ruy-bot

🐛 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 every process.env key with the VLT_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 configured registries URL (the client already has options.registries) as a candidate.
  • Add a request-level test: src/registry-client/test/auth.ts only exercises getToken() directly, which is why this was not caught.

🌍 Environment

  • OS: linux
  • Node: 24.18.1
  • vlt: 1.0.8 (auth.ts unchanged at current main)

🔄 Frequency

Always

Activity

  1. added
    bug
    cli
    on Sep 14, 2026
  2. ruy-bot commented on Sep 14, 2026

    @ruy-bot
    ContributorAuthor

    Related: #1845 (plain VLT_TOKEN only works with VLT_REGISTRY).

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Metadata

Metadata

Assignees

No one assigned

    Labels

    bugcliregistry

    Type

    No type

    Projects

    No projects

      Milestone

      No milestone

      Relationships

      None yet

      Development

      No branches or pull requests

      Issue actions