Secrets

Working with the CLI

The command-line tool secrets-tool works with the same files. Typical split: maintain values in the web app, read them on servers and in deploy scripts with the CLI.

Bring your key to the CLI

The easiest way is to let the CLI fetch it: after secrets-tool remote login, run secrets-tool identity pull. It asks for your vault password, checks the key with it and stores the identity.key in the right place. An existing file with a different key is only replaced with --force, and the old one is kept as a backup. If the CLI and the web app use different keys, status, the menu and remote login mention it as a hint; the "no slot" error recommends identity pull if the file is encrypted for your web key. A server or CI machine rightly has its own key: there, secrets-tool remote config identity-check off turns the hint off.

By hand: under My access download the identity.key and store it at:

Windows:   %APPDATA%\sareba\identity.key
Linux/Mac: ~/.config/sareba/identity.key

The file is encrypted with your vault password. The CLI asks for it; for scripts it can come from the environment variable SECRETS_TOOL_PASSWORD, or you unlock it for 30 minutes with secrets-tool unlock (see Unlocking below). On your own computer it also works with no password at all: secrets-tool unlock --device unlocks it (see Device unlock below).

Unlocking for 30 minutes

secrets-tool unlock asks for the password once. After that a small background process, the unlock agent, holds your private key for 30 minutes in memory only; all commands during that time run without a password prompt. Change the duration with SECRETS_TOOL_TTL in seconds (e.g. 3600 for one hour). When the time is up or you run secrets-tool lock, the agent ends itself and the key is gone. secrets-tool status shows the remaining time in the line [2] Unlocked.

Nothing is stored on disk: since 0.9.1.20 unlock no longer writes a key file. The CLI deletes the old unlock.sess file from versions up to 0.9.1.19 (under %LOCALAPPDATA%\sareba\cache or ~/.cache/sareba) by itself. Only your own account can talk to the agent: on Windows via a named pipe open only to your account, on Linux and macOS via a socket in a private directory (permissions 0700), and the agent also checks the process on the other end. Other users and system services cannot get at the key. The agent never hands out the private key; it only opens the data key of a file. Because no Windows data protection is needed, unlock also works over SSH.

Commands that need the key itself still ask for the password while unlocked: change-password, decrypt-identity and unlock --device.

Device unlock

secrets-tool unlock --device asks for the password once and then unlocks this computer: commands and deploy scripts run there without a password prompt. This works on Windows, on macOS and on Linux with a keyring (from 0.9.1.21). It needs secrets-tool remote login, because the unlock is tied to the device token. Connected does not mean unlocked, though: “Connect device” on the web only pairs; the unlock comes only from this command on the computer. secrets-tool status then shows “Device unlock: set up”. The key is then protected twice on the computer: encrypted with a share only the server knows, and bound to your account on exactly this computer – on Windows by Windows data protection, on macOS by a key in your keychain, on Linux by a key in the keyring of the desktop session (GNOME Keyring or KWallet; this needs secret-tool from the package libsecret-tools). Linux servers without a desktop have no device unlock; secrets-tool status says why. On every access the CLI briefly asks the server; if it cannot be reached, the password prompt comes back, and for one minute further commands do not ask again (a deploy script waits only once).

The unlock applies to your session at the computer. Over SSH with key login or in a scheduled task without a stored password, Windows data protection is not available or the keyring is locked: there the CLI asks for the password, secrets-tool status names the reason, and the unlock on the desktop stays in place. In such sessions secrets-tool unlock helps, as it needs neither Windows data protection nor a keyring, and for scripts SECRETS_TOOL_PASSWORD. The CLI deletes the unlock file only when the server reports the revocation, not on outages.

The unlock belongs to exactly one access (address and token). secrets-tool remote logout and a remote login with a new token remove it as well; set it up again afterwards with secrets-tool unlock --device. A different access, for example in a second user profile, leaves it alone. If the access file is briefly missing or unreadable, the unlock stays and works again as soon as the same access is back (from 0.9.1.25; before, it was lost in that case).

Laptop stolen or lost: under My access, API tokens, revoke the device token (or just Remove unlock). The server deletes its share and the file on the laptop becomes useless, even for someone signed in to the Windows account. To end it yourself: secrets-tool lock --device.

The most important commands

secrets-tool list                 # show keys
secrets-tool get DB_PASSWORD      # one value
secrets-tool set KEY              # set (asks for the value with hidden input)
secrets-tool pubkey               # own public key
secrets-tool list-recipients      # who is enrolled
secrets-tool check                # check the repository
secrets-tool                      # interactive menu

Interactive menu

If you do not want to remember commands, run secrets-tool (or st) without anything. The menu is sorted by goal: view and change secrets, load into a script, give colleagues access, connect to the web app, identity and password. On top of that, Stage: … switches, creates and compares stages, and Language sets the language. Select with the arrow keys and Enter or with the number in front, Esc goes back, q quits. You pick the value to read, change or delete from a list. Each entry shows the command behind it, so you learn the short form along the way. If a newer version exists, the menu says so at the top and Update program fetches it; a mandatory update is asked for before the menu opens. The menu never starts in scripts or pipes.

The header shows the state as a badge: LOCKED (asks for the password on the next access), UNLOCKED (unlock agent running), DEVICE UNLOCKED (device unlock), plus whether the project file exists yet and the active stage, e.g. PROD · READY. Below the list a short explanation of the selected entry. Success shows in green, warnings in yellow, errors in red; NO_COLOR=1 turns colors off. Direct commands and redirected output stay unchanged.

Language

The CLI speaks German or English throughout. Without a setting it follows the operating system: German if the system language is German, English otherwise (Windows: display language; Linux: LANGUAGE, LC_ALL, LC_MESSAGES, LANG; macOS: system locale). To change it permanently:

secrets-tool language en    # English (same as: secrets-tool sprache en)
secrets-tool language de    # German
secrets-tool language auto  # follow the system language again

In the menu use the entry Language. The setting is stored in cli.json next to the identity.key. For a single call, e.g. in a script, the environment variable SECRETS_TOOL_LANG=de or en sets the language; it takes precedence over the setting.