Use a custom token helper
A token helper is a program or script that saves, retrieves, or erases a saved authentication token.
By default, the Vault CLI includes a token helper that caches tokens from any
enabled authentication backend in a ~/.vault-token
file. You can customize
the caching behavior with a custom token helper.
Step 1: Script your helper
Your token helper must accept a single command-line argument:
Argument | Action |
---|---|
get | Fetch and print a cached authentication token to stdout |
store | Read an authentication token from stdin and save it in a secure location |
erase | Delete a cached authentication token |
You can manage the authentication tokens in whatever way you prefer, but your helper must adhere to following output requirements:
- Limit
stdout
writes to token strings. - Write all error messages to
stderr
. - Write all non-error and non-token output to
syslog
or a log file. - Return the status code
0
on success. - Return non-zero status codes for errors.
Step 2: Configure Vault
To configure a custom token helper, edit (or create) a CLI configuration file
called .vault
under your home directory and set the token_helper
parameter
with the fully qualified path to your new helper:
Tip
Make sure the script is executable by the Vault binary.
Example token helper
The following token helper manages tokens in a JSON file in the home directory
called .vault_tokens
.
The helper relies on the $VAULT_ADDR
environment variable to store and
retrieve tokens from different Vault servers.