@nzyme/bitwarden
v0.17.1
Published
Bitwarden Secrets Manager as a secret store for @nzyme/secrets
Readme
@nzyme/bitwarden
Bitwarden Secrets Manager as a store for @nzyme/secrets, with its own client
and WebCrypto; no bws binary, no native module. Why: docs/decisions/own-bitwarden-client-over-bws.md.
import { bitwarden } from '@nzyme/bitwarden/bitwarden.js';
const bw = bitwarden({ project: '1f0c…', prefix: 'DEV_' });project— the Secrets Manager project id; the store reads and writes only its secrets.prefix— optional. The store covers the project's secrets whose key starts with it:readAllreturns them with the prefix stripped, andwriteadds it. Empty (the default) covers the whole project.server— Bitwarden Cloud US by default.https://vault.bitwarden.eufor Cloud EU, or the base URL of a self-hosted server (which serves/identityand/api). It must usehttps:, except on localhost, so the token never travels unencrypted.keychainSuffix— keeps this store's token apart from other stores on the same server, for example one token per project or per Bitwarden organization. See Several tokens on one machine.
A readAll costs at most three requests (login, project listing, one fetch), however many keys.
Setup
A dedicated organization. Create a Bitwarden organization used only for Secrets Manager, not the one holding the team's passwords. A token's reach is then limited to that organization's secrets by construction, not only by its permissions.
Projects. One project per repo or per environment, as the repo's conventions expect (or one project with a
prefixper environment). Copy the project id intobitwarden({ project }).A machine account per machine, with read-write access to the project. A machine meant only to read (a server, a CI runner) gets a read-only machine account; its writes fail with 403.
Access tokens. Create an access token for each machine account and give it to whoever runs that machine.
Log in on each machine:
bun secrets loginThe token is read from a hidden prompt (or stdin), checked against the server, and stored in the OS keychain under the server's host, so a token is never sent to another server. One token serves reading and writing.
In CI, or on Linux without a keychain, set BWS_ACCESS_TOKEN instead; it takes the place of the
stored token, and secrets run removes it from the child's environment.
Several tokens on one machine
Without a suffix, every store on a server shares one stored token, so logging in from one project replaces it for the others. Give a project its own:
const bw = bitwarden({ project: '1f0c…', keychainSuffix: 'healed' });The token is stored as bitwarden:<host>#healed, so it stays bound to its server: the same suffix on
another server is a separate token.
- A project that adds a suffix runs
secrets loginagain. The unsuffixed token stays for the projects still using it, and a suffixed store never falls back to it. BWS_ACCESS_TOKEN, when set, still takes the place of any stored token.- Values cached by
cached()are kept per server, project and prefix, so stores with different suffixes reading one project share them.
Why a token cannot reach passwords
A machine-account token logs in with scope api.secrets, which the Bitwarden server accepts only on
Secrets Manager endpoints. The vault requires scope api, which a machine account cannot get. A
leaked token exposes the Secrets Manager projects its machine account can access, never vault items.
Keychain
Tokens, and values cached by cached(), are stored with Bun.secrets under the service
nzyme-secrets.
Any bun process of the same user can read them without a prompt: on macOS (Bun 1.4.4, checked 2026-11-02) a separate bun script read the tokens that secrets login had stored. The keychain protects them from other users and from a stolen disk, not from code you run. Linux is not checked yet.
