Vault Dev Mode & the CLI
vault server -dev starts a complete Vault in one process: in-memory storage, already initialised and unsealed, a KV v2 engine at secret/, and a root token. It forgets everything when it stops. Every Vault session in this course starts it the same way:
vault server -dev -dev-root-token-id=root -dev-listen-address=127.0.0.1:8200 > vault.log 2>&1 &
for i in $(seq 50); do vault status > /dev/null 2>&1 && break; sleep 0.2; done # wait, but not forever
export VAULT_TOKEN=root-dev-root-token-id=rootpicks the root token instead of a random one.- The CLI finds the server through
VAULT_ADDR(the sandbox presetshttp://127.0.0.1:8200; dev mode has no TLS) and authenticates withVAULT_TOKEN(or the token file~/.vault-tokenthatvault loginwrites). - The wait loop is bounded: if the server fails to start, the session fails quickly instead of hanging.
Looking around
vault server -dev -dev-root-token-id=root -dev-listen-address=127.0.0.1:8200 > vault.log 2>&1 &
for i in $(seq 50); do vault status > /dev/null 2>&1 && break; sleep 0.2; done
export VAULT_TOKEN=root
vault status -format=json | jq '{initialized, sealed, version, storage_type, n: .n, t: .t}'
echo "--- secrets engines (mount paths)"
vault secrets list -format=json | jq -r 'to_entries[] | "\(.key)\t\(.value.type)\t\(.value.options.version // "-")"'
echo "--- auth methods"
vault auth list -format=json | jq -r 'keys[]'
echo "--- who am I"
vault token lookup -format=json | jq '.data | {display_name, policies, ttl}'{
"initialized": true,
"sealed": false,
"version": "2.2.1",
"storage_type": "inmem",
"n": 1,
"t": 1
}
--- secrets engines (mount paths)
agent-registry/ agent_registry -
cubbyhole/ cubbyhole -
identity/ identity -
secret/ kv 2
sys/ system -
--- auth methods
token/
--- who am I
{
"display_name": "token",
"policies": [
"root"
],
"ttl": 0
}
nandtare the Shamir share count and threshold: 1 of 1 in dev mode.secret/is KV version 2;cubbyhole/is a private per-token store;identity/holds entities and groups;sys/is the system backend (mounts, policies, health);agent-registry/is new in Vault 2.x.- The root token has the
rootpolicy andttl: 0, meaning it never expires. Real clusters revoke the initial root token after setup and create new ones only for emergencies (vault operator generate-root).
Every command is an API call
-output-curl-string prints the HTTP request a command would send, without sending it. That is the fastest way to learn the API for scripts and applications:
vault server -dev -dev-root-token-id=root -dev-listen-address=127.0.0.1:8200 > vault.log 2>&1 &
for i in $(seq 50); do vault status > /dev/null 2>&1 && break; sleep 0.2; done
export VAULT_TOKEN=root
vault kv put -output-curl-string -mount=secret linkly/db password=x | grep -oE "^curl -X [A-Z]+|-H \"X-Vault-Token: [^\"]+\"|-d '[^']*'|http://[^ ]+quot;
vault kv put -mount=secret linkly/db username=linkly password='c0rrect-h0rse' > /dev/null
# the same read, with curl and the HTTP API
curl -s -H "X-Vault-Token: $VAULT_TOKEN" $VAULT_ADDR/v1/secret/data/linkly/db | jq '.data.data'
# unauthenticated health endpoint: what load balancers probe
curl -s -o /dev/null -w 'sys/health -> HTTP %{http_code}\n' $VAULT_ADDR/v1/sys/health
# the same read without a token
curl -s $VAULT_ADDR/v1/secret/data/linkly/db | jq -c .curl -X PUT
-H "X-Vault-Token: $(vault print token)"
-d '{"data":{"password":"x"},"options":{}}'
http://127.0.0.1:8200/v1/secret/data/linkly/db
{
"password": "c0rrect-h0rse",
"username": "linkly"
}
sys/health -> HTTP 200
{"errors":["permission denied"]}
The printed command (shown in its parts, one per line) reads the token with vault print token instead of embedding it (the request body still contains the secret value, so treat the line with care). The last request had no token, and Vault answered with a plain permission denied. Note the data/ segment: KV v2 puts secret data under <mount>/data/<path> and metadata under <mount>/metadata/<path>. The -mount= flag lets the CLI build those paths for you; policies must name them explicitly (Policies).
sys/health returns different HTTP codes for different states (200 active, 429 standby, 503 sealed, 501 not initialised), which is how load balancers send traffic only to the active node.
Getting help from the server
vault path-help <path> asks the mounted engine to describe its own API, so it is always accurate for the version you run:
vault server -dev -dev-root-token-id=root -dev-listen-address=127.0.0.1:8200 > vault.log 2>&1 &
for i in $(seq 50); do vault status > /dev/null 2>&1 && break; sleep 0.2; done
export VAULT_TOKEN=root
vault path-help secret/ | sed -n '/^## PATHS/,$p' | grep -E '^ \^' | head -8 ^.*$
^config$
^data/(?P<path>.*?[^/]$)$
^delete/(?P<path>.*)$
^destroy/(?P<path>.*)$
^metadata/(?P<path>.*)$
^subkeys/(?P<path>.*)$
^undelete/(?P<path>.*)$
Output formats
| Flag | Use |
|---|---|
default (table) |
humans |
-format=json |
scripts, with jq |
-field=<name> |
one raw value, e.g. vault kv get -field=password … |
-format=yaml |
humans who prefer YAML |
Tables contain timestamps, request ids and accessors that differ on every run; the sessions in this course print selected fields to stay readable and reproducible.
Test yourself
Which two environment variables does the Vault CLI read to reach and authenticate to a server?
VAULT_HOSTandVAULT_PASSWORDVAULT_ADDRandVAULT_TOKENVAULT_URLandVAULT_KEYHTTP_PROXYandTOKEN
What is the API path of vault kv get -mount=secret linkly/db on KV v2?
/v1/secret/linkly/db/v1/secret/data/linkly/db/v1/kv/linkly/db/v1/sys/secret/linkly/db
How do you see the HTTP request a CLI command would make?
-verbose-output-curl-string-dry-run-debug