Dit deel is nog niet vertaald. Je ziet de Engelse tekst.
$ als gewone gebruiker# als root (of met sudo)
Know it before you install
Vault stores everything encrypted. After every start it is sealed — it can not read its own data until enough unseal keys are given (Shamir: for example 3 of 5) or a cloud KMS unseals it automatically. People and apps log in (auth methods), get a token, and policies say which paths the token may use.
| Item | Value |
|---|---|
| Package | vault (HashiCorp repository) |
| Service | vault.service, runs as user vault |
| Config | /etc/vault.d/vault.hcl |
| Data (Raft) | /opt/vault/data/ |
| TLS files | /opt/vault/tls/ (the package makes a self-signed pair to start) |
| Ports | 8200/tcp (API and UI), 8201/tcp (cluster) |
| Client settings | VAULT_ADDR, VAULT_CACERT, VAULT_TOKEN |
Notitie
Vault uses the BSL license since 1.14. OpenBao is an open-source fork with the same ideas and commands (bao …).
Install on RHEL, Rocky, Alma and Fedora
Install on Ubuntu and Debian
curl -fsSL https://apt.releases.hashicorp.com/gpg | gpg --dearmor -o /usr/share/keyrings/hashicorp-archive-keyring.gpg
echo "deb [signed-by=/usr/share/keyrings/hashicorp-archive-keyring.gpg] https://apt.releases.hashicorp.com $(lsb_release -cs) main" > /etc/apt/sources.list.d/hashicorp.list
apt-get update
apt-get install -y vaultOp het werk
To learn the commands, vault server -dev starts an unsealed in-memory Vault with a root token in one second. Never use dev mode for real secrets — everything is lost at stop.
First configuration: storage, listener and TLS
Use a real certificate for vault.example.com (from your CA or Let's Encrypt) in /opt/vault/tls/, readable by the vault user.
ui = true
disable_mlock = true
cluster_name = "vault-prod"
storage "raft" {
path = "/opt/vault/data"
node_id = "vault1"
}
listener "tcp" {
address = "0.0.0.0:8200"
cluster_address = "0.0.0.0:8201"
tls_cert_file = "/opt/vault/tls/tls.crt"
tls_key_file = "/opt/vault/tls/tls.key"
tls_min_version = "tls12"
}
api_addr = "https://vault.example.com:8200"
cluster_addr = "https://vault.example.com:8201"| Setting | Why |
|---|---|
storage "raft" | Integrated storage: no extra database; add 2 more nodes later for high availability. |
listener … tls_* | Secrets travel only over TLS. Never tls_disable = true outside a lab. |
disable_mlock = true | Recommended with Raft storage (and turn off swap on the server instead). |
api_addr, cluster_addr | The addresses clients and other nodes use. |
ui = true | The web UI at https://vault.example.com:8200/ui. |
Open the firewall and start:
firewall-cmd --permanent --add-port={8200,8201}/tcp
firewall-cmd --reload
systemctl enable --now vault
export VAULT_ADDR=https://vault.example.com:8200
vault status
Sealed true
Initialized falseInitialize and unseal
Initialize once. Vault prints the unseal keys and the first root token — this is the most important moment:
vault operator init -key-shares=5 -key-threshold=3
Unseal Key 1: 4Xb…
Unseal Key 2: 9qK…
…
Initial Root Token: hvs.…
vault operator unseal
vault operator unseal
vault operator unseal
vault status
Sealed falseLet op
Give the 5 unseal keys to 5 different trusted people (or encrypt them with their PGP keys: -pgp-keys). If too many keys are lost, the data can never be read again. After the setup, revoke the root token (vault token revoke …) and make a new one only in an emergency (vault operator generate-root). In the cloud, use auto-unseal with AWS KMS, Azure Key Vault or Google Cloud KMS.
Store secrets, write policies, give apps a login
Log in, turn on the audit log first, then a KV (key/value) secrets engine:
vault login
mkdir -p /var/log/vault && chown vault: /var/log/vault
vault audit enable file file_path=/var/log/vault/audit.log
vault secrets enable -path=secret kv-v2
vault kv put secret/shop/db username=shop password='S3cret-long-random'
vault kv get secret/shop/db
vault kv get -field=password secret/shop/db
vault kv metadata get secret/shop/dbA policy that may only read the shop secrets:
path "secret/data/shop/*" {
capabilities = ["read"]
}vault policy write shop-read shop-read.hcl
vault auth enable approle
vault write auth/approle/role/shop token_policies=shop-read token_ttl=1h token_max_ttl=4h secret_id_ttl=24h
vault read -field=role_id auth/approle/role/shop/role-id
vault write -f -field=secret_id auth/approle/role/shop/secret-id
vault write auth/approle/login role_id=ROLE_ID secret_id=SECRET_IDThe app logs in with its role_id + secret_id, gets a 1-hour token, and can read only secret/shop/*. In Kubernetes use the kubernetes auth method (Pods log in with their service account) with the Vault Agent Injector or the Vault Secrets Operator.
Daily use: the commands and the real uses
vault status
vault secrets list
vault auth list
vault policy list
vault token lookup
vault kv rollback -version=2 secret/shop/db
vault operator raft list-peers
vault operator raft snapshot save /backup/vault-$(date +%F).snapReal uses at work:
- One place for all app and CI secrets, with an audit log of every read.
- Dynamic secrets: the database engine makes a new DB user for each app start and deletes it later.
- PKI engine: an internal CA that issues short-lived TLS certificates.
- CI pipelines read secrets with OIDC/JWT login — no static secrets in the CI tool.
Make it safe
Security checklist:
- TLS everywhere; firewall 8200 to app and admin networks; 8201 only between Vault nodes.
- Unseal keys split between people (or auto-unseal with KMS); root token revoked after setup.
- Audit device on from day one; ship the audit log to your SIEM.
- Least-privilege policies per app; short token TTLs; AppRole
secret_idwith TTL and CIDR limits. - Regular Raft snapshots, encrypted, stored elsewhere — and a restore test.
- Three nodes (Raft) for production; keep Vault updated.
Update and remove
Fix common problems
| Problem | Cause | Fix |
|---|---|---|
Vault is sealed (error 503) after a restart | Normal: Vault starts sealed. | vault operator unseal with enough keys, or set up auto-unseal. |
x509: certificate signed by unknown authority | The client does not trust the CA. | export VAULT_CACERT=/path/ca.pem (never VAULT_SKIP_VERIFY outside labs). |
permission denied (403) | The token's policy does not allow this path. | vault token lookup; for KV v2 the policy path needs secret/data/…. |
http: server gave HTTP response to HTTPS client | VAULT_ADDR uses https but the listener has no TLS (or the other way). | Make them match. |
Service does not start: permission denied on /opt/vault/data or the key | Wrong owner or mode. | chown -R vault: /opt/vault; key readable by vault. |
failed to lock memory: cannot allocate memory | mlock not allowed. | disable_mlock = true (with swap off), or give CAP_IPC_LOCK. |
| Lost unseal keys | — | Without enough keys the data can not be recovered. Keep keys with several people. |
Next steps
- Quick how-tos: Read secrets from Vault.
- Command page: vault — every command and option.
- Vault at work: The secret store. Secrets in Kubernetes: CKS — Secrets, GitOps secrets.
- Secrets in Git, encrypted: Command page: sops. The same repository: Install and set up Terraform.
1Vault was restarted and every request gives 503. What happened?
Vault starts sealed. Unseal it with enough unseal keys (or use auto-unseal).
2Your policy allows secret/shop/* but reading secret/shop/db is denied (KV v2). Why?
KV v2 stores data under secret/data/…; the policy path must be secret/data/shop/*.