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
In a nutshell
  • VAULT_ADDR is the server address; its default is https://127.0.0.1:8200.
  • VAULT_TOKEN is the token the CLI sends; VAULT_NAMESPACE selects a namespace (Enterprise and HCP).
  • VAULT_FORMAT accepts table, json, yaml and jsonx.

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.

Shellexport VAULT_ADDR and VAULT_TOKENread byvault CLIrequestVault server

How it works

The core variables

VariablePurposeNotes
VAULT_ADDRAddress of the Vault serverDefault https://127.0.0.1:8200; flag -address
VAULT_TOKENToken the CLI uses to authenticateNo default
VAULT_NAMESPACEDefault namespace for commandsEnterprise and HCP; flags -namespace or -ns
VAULT_FORMATOutput formattable (default), json, yaml, jsonx; flag -format
VAULT_WRAP_TTLWrap CLI responses in a cubbyhole token with this TTLFlag -wrap-ttl; unset means no wrapping
VAULT_CLIENT_TIMEOUTHow long the CLI waits for a responseDefault 60s

TLS variables

VariablePurpose
VAULT_CACERTPath to a PEM CA certificate used to verify the server certificate
VAULT_CAPATHPath to a directory of PEM CA certificates
VAULT_CLIENT_CERTPath to a PEM client certificate; must match VAULT_CLIENT_KEY
VAULT_CLIENT_KEYPath to the private key for the client certificate
VAULT_SKIP_VERIFYSkip verification of the server certificate; not for production
VAULT_TLS_SERVER_NAMEServer 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

Command line flagoverridesEnvironment variableoverridesBuilt in default

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_LEVEL and VAULT_LOG_FORMAT control log output (trace, debug, info, warn, err; standard or json).
  • VAULT_MAX_RETRIES sets retries for HTTP 412 and 5xx responses (excluding 501); the default is 2, and 0 disables retries.
  • VAULT_AGENT_ADDR points the CLI at Vault Agent.
  • VAULT_LICENSE and VAULT_LICENSE_PATH supply 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_ADDR but 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_ADDR is the server address; its default is https://127.0.0.1:8200.
  • VAULT_TOKEN is the token the CLI sends; VAULT_NAMESPACE selects a namespace (Enterprise and HCP).
  • VAULT_FORMAT accepts table, json, yaml and jsonx.
  • VAULT_CACERT, VAULT_CAPATH, VAULT_CLIENT_CERT and VAULT_CLIENT_KEY configure TLS.
  • VAULT_SKIP_VERIFY disables certificate verification and is not for production.
  • Command line flags override environment variables.
Watch out

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_ADDR for the server address and VAULT_TOKEN for the token that authenticates the CLI.

  • Which wins when both VAULT_ADDR and -address are given?

    The -address flag wins for that command.

  • How do you make the CLI trust a private CA without skipping verification?

    Set VAULT_CACERT to the PEM CA certificate path, or VAULT_CAPATH to 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.