Vault Architecture Fundamentals · Topic 3 of 3
Configuring Environment Variables
Vault Associate (003): key CLI environment variables - VAULT_ADDR, VAULT_TOKEN, VAULT_NAMESPACE, VAULT_FORMAT, TLS settings - and flag precedence.
- 4 min
VAULT_ADDRis the server address; its default ishttps://127.0.0.1:8200.VAULT_TOKENis the token the CLI sends;VAULT_NAMESPACEselects a namespace (Enterprise and HCP).VAULT_FORMATacceptstable,json,yamlandjsonx.
What it is
The Vault CLI reads settings from environment variables, so you do not retype the server address or token on every command. You set them in your shell once and every vault command in that session uses them.
The two you use most are VAULT_ADDR, which says where the server is, and VAULT_TOKEN, which says who you are.
How it works
The core variables
| Variable | Purpose | Notes |
|---|---|---|
VAULT_ADDR | Address of the Vault server | Default https://127.0.0.1:8200; flag -address |
VAULT_TOKEN | Token the CLI uses to authenticate | No default |
VAULT_NAMESPACE | Default namespace for commands | Enterprise and HCP; flags -namespace or -ns |
VAULT_FORMAT | Output format | table (default), json, yaml, jsonx; flag -format |
VAULT_WRAP_TTL | Wrap CLI responses in a cubbyhole token with this TTL | Flag -wrap-ttl; unset means no wrapping |
VAULT_CLIENT_TIMEOUT | How long the CLI waits for a response | Default 60s |
TLS variables
| Variable | Purpose |
|---|---|
VAULT_CACERT | Path to a PEM CA certificate used to verify the server certificate |
VAULT_CAPATH | Path to a directory of PEM CA certificates |
VAULT_CLIENT_CERT | Path to a PEM client certificate; must match VAULT_CLIENT_KEY |
VAULT_CLIENT_KEY | Path to the private key for the client certificate |
VAULT_SKIP_VERIFY | Skip verification of the server certificate; not for production |
VAULT_TLS_SERVER_NAME | Server name used for SNI in the TLS handshake |
VAULT_CACERT takes precedence over VAULT_CAPATH.
Setting them
export VAULT_ADDR="https://127.0.0.1:8200"
export VAULT_TOKEN="<your-token>"
export VAULT_FORMAT=json
vault status
A dev-mode server listens on 127.0.0.1:8200 without TLS, so a dev setup typically uses an http:// address:
export VAULT_ADDR="http://127.0.0.1:8200"
The dev server also prints a root token. Set it in VAULT_TOKEN so the CLI authenticates with it.
Precedence
A flag overrides the matching environment variable for that one command. For example -address overrides VAULT_ADDR.
export VAULT_ADDR="https://vault-a.example.com:8200"
vault status -address="https://vault-b.example.com:8200"
The second command talks to vault-b, because the flag wins. The next command, without the flag, goes back to vault-a.
A worked example
export VAULT_ADDR="http://127.0.0.1:8200"
export VAULT_TOKEN="<your-token>"
vault secrets list
vault secrets list -format=json
The first vault secrets list uses the address and token from the environment and prints a table. The second adds -format=json for one command, so only that call prints JSON. If VAULT_TOKEN is unset and you have not logged in, the command does not list engines.
What the variables do not do
Environment variables only configure the client, which is the vault command on your machine. They do not change the server, and they do not unseal it.
Server settings come from the server configuration file, not from the CLI environment. To change how the server behaves you edit its configuration, while the variables here only change what your CLI sends and where it sends it.
Other variables you may meet
VAULT_LOG_LEVELandVAULT_LOG_FORMATcontrol log output (trace,debug,info,warn,err;standardorjson).VAULT_MAX_RETRIESsets retries for HTTP 412 and 5xx responses (excluding 501); the default is 2, and 0 disables retries.VAULT_AGENT_ADDRpoints the CLI at Vault Agent.VAULT_LICENSEandVAULT_LICENSE_PATHsupply a license for Vault Enterprise.
How the exam asks about this
- "Which variable sets the Vault server address for the CLI?"
VAULT_ADDR. - "A script sets
VAULT_ADDRbut a command passes-address." The flag wins for that command. - "Which variable makes CLI output JSON?"
VAULT_FORMAT=json.
What to remember for the exam
VAULT_ADDRis the server address; its default ishttps://127.0.0.1:8200.VAULT_TOKENis the token the CLI sends;VAULT_NAMESPACEselects a namespace (Enterprise and HCP).VAULT_FORMATacceptstable,json,yamlandjsonx.VAULT_CACERT,VAULT_CAPATH,VAULT_CLIENT_CERTandVAULT_CLIENT_KEYconfigure TLS.VAULT_SKIP_VERIFYdisables certificate verification and is not for production.- Command line flags override environment variables.
VAULT_SKIP_VERIFY turns off certificate verification. It is documented as not for production, so never use it as a permanent fix.
Common mistakes
Forgetting VAULT_ADDR outside dev. The default is https://127.0.0.1:8200. Against any other server, the CLI talks to the wrong place until you set the variable.
Using VAULT_SKIP_VERIFY to fix a certificate problem. It hides the problem and removes protection. Set VAULT_CACERT to the right CA certificate instead.
Expecting the environment to beat a flag. Flags are more specific, so they win for the command they appear on.
Check yourself
Which two variables do most CLI sessions set first?
VAULT_ADDRfor the server address andVAULT_TOKENfor the token that authenticates the CLI.Which wins when both
VAULT_ADDRand-addressare given?The
-addressflag wins for that command.How do you make the CLI trust a private CA without skipping verification?
Set
VAULT_CACERTto the PEM CA certificate path, orVAULT_CAPATHto a directory of them.
Topic 3 of 3 in Vault Architecture Fundamentals
Test yourself on Vault Architecture Fundamentals
The full HashiCorp Vault Associate 003 question bank has 600 questions, with timed practice exams and an explanation for every answer.
This study guide is independent and is not affiliated with, endorsed by, or sponsored by HashiCorp. Vendor names, certification names and exam codes are trademarks of their respective owners and are used for identification only.