Skip to content

3.2.0

Choose a tag to compare

@kurok kurok released this 06 Nov 19:41
· 7 commits to master since this release
aea042e

Upgrading from 3.1.x needs no code change for most setups. What behaves differently is covered
below:

  • Redirects are followed only within the origin of api.url (#232). An http:// api.url that
    a load balancer redirects to https://, or a Vault HA standby that redirects to an active node
    on another origin, now fails. Use the final URL, or set api.requestOptions.redirect: 'follow'
    for the 3.1.x behaviour.
  • A 403 on a secret request is checked with auth/token/lookup-self, and a token Vault no
    longer accepts is replaced by one new login (#235). A policy denial is returned as before.
  • New warn lines: a plain http:// api.url off this machine, and an IAM login without
    iam_server_id_header_value (part of #202). VaultClient.clear() with a name that is not a
    string emits a DeprecationWarning (#239). None of them changes what the client does.

Changes in this release:

  • CI / release tooling (#229). The publish job holds the npm trusted-publishing credential
    (id-token: write). It no longer fetches and runs tooling from outside the lockfile, and what
    it must fetch is kept away from that credential.

    • The job no longer runs npm install -g npm@latest (npm latest had moved to 12.x). It uses
      the npm bundled with Node 24 and fails if that is older than 11.5.1, which trusted publishing
      needs.
    • npm ci --ignore-scripts in the publish job. No locked package has an install script today;
      this keeps a future one from running there.
    • test/verify-package.mjs still installs the packed tarball's runtime dependencies from the
      registry, as a consumer would, but with --ignore-scripts and without the OIDC request,
      Actions runtime and npm/GitHub token variables, both for the install and for the checks that
      load the package.
    • config is locked as a devDependency (^4.4.2, inside the unchanged >=1 <5 peer range)
      instead of npm install config in three CI jobs.
    • test/workflows.test.mjs fails if a workflow run: command fetches packages at run time
      (npm install/add/update/exec, npx, yarn add, pnpm, @latest), if a publish
      npm ci loses --ignore-scripts, if the npm check goes, or if verify-package stops
      scrubbing the environment.

    Library code and runtime dependencies are unchanged; the packed package.json now also lists
    config under devDependencies, which consumers do not install.

  • A warning for an IAM login without iam_server_id_header_value (part of #202). The signed
    STS GetCallerIdentity request then names no Vault server, so it could be replayed to another
    Vault server that trusts the same AWS principal. With the value missing, empty or only
    whitespace, the iam backend now logs one warn line on its first login, once per Vault server,
    namespace and mount for each logger (clients on the default logger share one, so once per
    process), and logs in as before, sending the same request. logger: false silences it without
    using it up for other clients. A client that never logs in, or whose config is rejected, logs
    nothing. README: "iam_server_id_header_value".

  • Tests: the e2e suites exit without --exit (#220). Plain mocha on e2e.test.mjs or
    e2e.kv2.test.mjs hung after the summary. Two clients holding renewable tokens were never
    closed, so their renewal timers kept the event loop alive: the AppRole "with secret ID" test,
    and the KV path-validation suite shared by both files (a one-hour service token). The renewal
    tests named in the issue already closed theirs. Both now close their clients, and the
    test:e2e* scripts load test/e2e/renewal-timer-guard.mjs. If a renewal timer is still armed
    after the last test, it fails the run, naming the test or hook in which that client was first
    used, and cancels the timer so the run exits even without --exit. --exit stays in the
    scripts. Test-only; no library change.

  • A warning for a plain http:// api.url off this machine (part of #202). When api.url is
    http:// and its host is not this machine (localhost, 127.0.0.0/8 also as
    ::ffff:127.x.y.z, ::1, 0.0.0.0, ::), the client now logs one warn line on its first
    request, because the token and secrets would cross the network unencrypted. It names only the
    host and port, is logged once per host and port for each logger (clients on the default logger
    share one, so once per process), and changes nothing else: the client connects and works as
    before, and a logger that throws does not fail the request (the client tries again on its next
    one). With the default logger it goes to console.warn; logger: false silences it without
    using it up for other clients. README: "Plain http:// api.url".

  • Security: redirects are followed only within the origin of api.url (#232). Requests
    used fetch()'s redirect: 'follow', which sends every header but Authorization, Cookie
    and Proxy-Authorization to whatever origin a Location names. X-Vault-Token went with it, a
    307 or 308 on a login replayed the credentials in its body, and the other origin's answer was
    returned as Vault data. Requests are now sent with redirect: 'manual', and the client follows
    a redirect itself only to the same origin (scheme, host and port), as fetch() would: up to 20
    hops, method and body kept on a 307 or 308, a GET without a body on a 303 and on a 301 or 302
    after a POST. A redirect to another origin rejects with a VaultError before anything is
    sent there. That includes https: to http:, and http: to https: on the same host.

    • Compatibility. Same-origin redirects, such as Vault's own for a // in a path, behave as
      before. A test sends each redirect status with GET, POST, PUT, PATCH and DELETE both ways and
      compares the method, path, body and headers the server receives. Where fetch() gave up
      (more than 20 hops, a Location that does not parse, is not http(s) or carries
      credentials), the request still rejects with TypeError: fetch failed. Changed:
      • An http:// api.url that a load balancer redirects to https:// now fails. Use the
        https:// URL.
      • A Vault HA standby answers with a 307 to the active node's api_addr when request
        forwarding fails. If that address is another origin, the request now fails instead of
        following it.
      • A redirect in api.requestOptions is passed to fetch() as it is; 'follow' restores
        the old behaviour. redirect: null, which fetch() rejected on every request, now reads
        as not set.
      • fetch() now receives redirect: 'manual' instead of 'follow', with api.timeout: 0
        too. Code that stubs fetch() and checks its options will see this.
    • README: "Redirects and the Vault token" describes the policy and the opt-out.
  • Fixed: close() during a login no longer leaves a renewal timer behind (#251). A login that
    was still in flight when close() ran, such as the first read of a client closed before it
    settled, armed a refresh timer when it finished, so the process still never exited. Such a login
    now resolves and caches its token as before, but arms no timer; a debug line says so. Calls
    that join that login after close() share its token and get no timer either. A login that starts
    after close() arms one as before. Dropping a token Vault no longer accepts (#235) does not count
    as a close(): the token from the next login is renewed. The warnings a login logs when it
    cannot renew its token are unchanged, and a subclass that overrides cancelTokenRefresh(), with
    or without super, keeps both behaviours.

  • Fixed: a token lookup without a usable ttl no longer yields a NaN expiry (#236). Without
    expire_time, the expiry is creation_time (or last_renewal_time) plus ttl. A
    lookup-self answer where either was missing or not a number made that NaN, so
    getExpiresAt() returned NaN and the token counted as renewable. Such a token now has a
    null expiry, as one with ttl: 0 and no expire_time already had, and is not renewable.

    • Compatibility. The token is still used until it is replaced: a NaN deadline never passed,
      and a null one means none. No timer is armed for it, as before. The log output is the same:
      the renewal timer still logs token renewal stopped (accessor=…): token has no usable expiry; … once, after a login or a renewal, when Vault marked the token renewable. A numeric-string
      ttl or creation_time is read as before. One more case changes: a numeric string too long
      to fit in a number used to give a deadline in the past, so every call logged in again. Real
      Vault always sends a numeric ttl, so this only affects proxies, mocks and test doubles.
  • Fixed: a token revoked on the Vault side is replaced on the next request (#235). The client
    logged in again only once its own clock said the token had expired. After a server-side
    revocation, every request failed with VaultHttpError 403 until then, even when the auth backend
    could log in again at once. Now a 403 on a secret request (the KV methods, request(), and the
    autoDetect mount detection) is checked with auth/token/lookup-self. If Vault no longer accepts
    the token, the client drops it with its renewal timer, logs in again and sends the request once
    more.

    • Compatibility. A policy denial is returned as before and costs no login, so an AppRole
      secret_id with limited uses is not spent on it. It does cost one extra lookup-self request
      (with autoDetect, also for a mount the token may not see), which counts against a token with
      limited uses. Each request is sent again at most once, and one login serves every request
      rejected with the same token. When that attempt fails, the call rejects with its error (a
      failed login, a 404, a timeout) rather than the dead token's 403. A 403 on the login itself
      and any 403 under token auth are returned as before, without a lookup. Other statuses are
      untouched.
    • Revoking a client's token no longer locks it out: it logs straight back in. To cut a client
      off, also revoke or rotate its login credential.
    • README: "Tokens revoked on the Vault side".
  • Fixed: VaultClient.get() and boot() with a name such as "toString" (#238). The named
    instances lived in a plain object, so a name matching an Object.prototype member found that
    member. get("toString") returned Object.prototype.toString instead of throwing
    InvalidArgumentsError, and boot("constructor", options) treated Object as an existing
    instance and threw a TypeError. The registry is now a Map, so every name, __proto__
    included, behaves like any other.

    • Compatibility. Names are keyed exactly as object properties were: a number is the same
      name as its string (boot(1) then get('1') returns that instance), and a symbol, or an
      object that converts to one, stays a symbol. clear() with no name still leaves
      symbol-named instances registered, as the old for...in loop did. clear('toString') and
      the like, which threw a TypeError, now do nothing when no such instance was booted.
  • A warning when VaultClient.clear() gets a name that is not a string (#239). Only a
    string clears one named instance; anything else, such as clear(42), clear(null) or clear
    used as a callback that receives an exit code or a resolved value, closes and removes every
    instance except symbol-named ones. That was silent and rarely meant. The behaviour is unchanged,
    but the first such call in a process now emits a DeprecationWarning (code
    NVC_DEP_CLEAR_NON_STRING) that names the argument's type, never its value. Call clear() with
    no argument to clear every instance. Node delivers warnings on the next tick, so inside a
    process.on('exit') listener it is not shown; --no-deprecation silences it.

  • Fixed: Lease.getValue() returned inherited members as secret values (#240). It threw
    only when data[key] was undefined, so getValue('constructor') returned Object and
    getValue('__proto__') returned Object.prototype. It now returns only the response data's
    own fields and throws Requested key does not exist for anything else.

    • Compatibility. Own fields are returned as before, null, false, 0 and '' included,
      and so is a field Vault sent under a name such as constructor. Numeric keys and array
      indexes work as before. When a response's data is JSON null, a string or a number, the
      call now throws Requested key does not exist, where null gave a TypeError and a string
      gave one of its characters or its length.
  • Fixed: a missing Kubernetes service-account token file threw out of read() (#241).
    kubernetes auth read the token file before its promise chain, so a missing or unreadable
    file made read(), write() and every other operation throw synchronously instead of
    returning a rejected promise. A caller that only chained .catch() got an uncaught
    exception. The file is now read inside the chain, as jwt auth already did with jwtPath.
    The login also turns a synchronous throw from any auth backend into a rejection.

    • Compatibility. The operation now rejects with the same fs error (for example
      code: 'ENOENT', with the same message) instead of throwing it, so handle it with await or
      .catch(): a try/catch around a call that is not awaited no longer catches it. As with
      any other failed operation, it is now logged at error (read secret failed: ENOENT: …).
      Vault is still not contacted. Calls made while that login is still pending share its error;
      the next call after it tries the file again, as before.
  • Fixed: each caller gets its own mount-detection error (part of #202). With
    api.kv.autoDetect, requests whose paths share a first segment wait for one in-flight
    detection. When it failed, every one of them got the same VaultError, whose message named
    the first caller's path. Each caller now gets its own VaultError, naming its own path. The
    underlying error stays on cause, shared by all.

    • Compatibility. The failure is still shared: one detection request, whatever it answered
      (a 403, a rate limit, a failed login), so the request count is unchanged. The message
      format, the first caller's message and the error class (VaultError, not VaultHttpError)
      are unchanged. The status is still only on err.cause.statusCode. Copying it onto the error
      would let a "403 means use a default" handler swallow a mistyped mount, because Vault answers
      403 for a mount that does not exist.