Dit deel is nog niet vertaald. Je ziet de Engelse tekst.
Wat het doet
Vault keeps secrets encrypted and gives them out only after authentication (token, userpass, OIDC, Kubernetes service account, AppRole, cloud identity) and policies (paths + capabilities). Secrets engines do the work: kv (static key/value, versioned), database (dynamic users with a lease), pki (certificates), transit (encryption as a service), aws/azure (dynamic cloud credentials). Every request is in the audit log.
A new Vault starts sealed; it must be unsealed (key shares or cloud KMS auto-unseal) before it serves data. OpenBao is the open-source fork with the same CLI (bao).
Zo schrijf je het
vault COMMAND [OPTIONS] [PATH] [KEY=VALUE ...]
export VAULT_ADDR=https://vault.lab.local:8200Belangrijkste delen
Commands
status- Sealed? HA mode? Version.
operatorinit/unseal/seal- Start, unlock and lock Vault.
login[-method=M]- Log in.
kvput|get|list|delete|metadataPATH- Static secrets (KV v2).
read/write/list/deletePATH- Any path of any engine.
secretsenable|listENGINE- Turn on secrets engines.
authenable|listMETHOD- Turn on auth methods.
policywrite|read|listNAME- Access policies.
tokencreate|lookup|revoke- Tokens.
leaserenew|revoke- Leases of dynamic secrets.
auditenablefile- Turn on the audit log.
operatorraftsnapshotsave- Back up integrated storage.
Opties 7
Meest gebruikt
Common flags and variables
Niets past bij dit filter.
Voorbeelden 10
$ als gewone gebruiker# als root (of met sudo)
1Start a dev server to learn
vault server -dev -dev-root-token-id=root & export VAULT_ADDR=http://127.0.0.1:8200 VAULT_TOKEN=root vault status2Initialize and unseal a real server
vault operator init -key-shares=5 -key-threshold=3 vault operator unseal vault status | grep Sealed3Store and read a static secret
vault secrets enable -path=secret kv-v2 vault kv put -mount=secret shop/db username=shop password='S3cr3t!x' vault kv get -mount=secret shop/db vault kv get -mount=secret -field=password shop/db4See versions and roll back
vault kv metadata get -mount=secret shop/db vault kv rollback -mount=secret -version=1 shop/db5Write a least-privilege policy
cat shop-read.hcl path "secret/data/shop/*" { capabilities = ["read"] } vault policy write shop-read shop-read.hcl6Let Kubernetes pods log in with their service account
vault auth enable kubernetes vault write auth/kubernetes/config kubernetes_host=https://kubernetes.default.svc:443 vault write auth/kubernetes/role/shop bound_service_account_names=shop bound_service_account_namespaces=shop policies=shop-read ttl=1h7Dynamic database users (short lived)
vault secrets enable database vault write database/config/shop plugin_name=postgresql-database-plugin connection_url="postgresql://{{username}}:{{password}}@db1:5432/shop" allowed_roles=shop-app username=vaultadmin password='ChangeMe!' vault write database/roles/shop-app db_name=shop default_ttl=1h max_ttl=24h creation_statements="CREATE ROLE \"{{name}}\" WITH LOGIN PASSWORD '{{password}}' VALID UNTIL '{{expiration}}'; GRANT SELECT ON ALL TABLES IN SCHEMA public TO \"{{name}}\";" vault read database/creds/shop-app8Encrypt data without storing it (transit)
vault secrets enable transit vault write -f transit/keys/shop vault write transit/encrypt/shop plaintext=$(echo -n "4111-1111" | base64)9Turn on the audit log
vault audit enable file file_path=/var/log/vault/audit.log10Back up Vault (Raft storage)
vault operator raft snapshot save vault-$(date +%F).snap
Niets past bij dit filter.
Let op
- Never use
-devor the root token in production; revoke the root token after setup. - Keep unseal keys with different people (or use cloud KMS auto-unseal).
- Secrets read into environment variables can leak in logs and
ps— prefer files or the agent injector.
Bestanden
/etc/vault.d/vault.hcl- Server configuration.
~/.vault-token- Your token after
vault login.
Tips om te onthouden
- In Kubernetes use the Vault Agent Injector, the Vault Secrets Operator or External Secrets Operator.
Exitcodes
0 | Success. |
1 | Local error (bad arguments). |
2 | Remote error (Vault said no, sealed, not found). |