Geavanceerd
Zoeken inInstallatiegidsen
Zo zoek je
  • Plak een foutmelding tussen aanhalingstekens, bijv. "permission denied", om de oplossingstabel te vinden.
  • Kies een gebied en een deel van de gids (installeren, eerste instellingen, dagelijks gebruik, beveiliging, oplossingen) om direct naar de juiste stap te gaan.
  • "twee woorden" vindt precies die zin.
  • Gewone woorden vinden namen, teksten en voorbeelden.
  • ↑ ↓ bewegen · Enter openen · Esc sluiten · / zoeken
Probeer:

Gids 27HashiCorp Vault · Security

Install and set up HashiCorp Vault

Vault keeps secrets — passwords, API keys, certificates, database logins — in one safe place, gives each app only the secrets it may read, logs every access, and can even create short-lived database passwords and certificates on demand. This guide installs Vault from the HashiCorp repository on RHEL and Ubuntu, configures a single server with integrated storage (Raft) and TLS, initializes and unseals it, stores the first secret, writes a policy, and gives an app its own login with AppRole.

  • 11 Lessen
  • 12 Commando's

Dit deel is nog niet vertaald. Je ziet de Engelse tekst.

$ als gewone gebruiker# als root (of met sudo)

27.1

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.

ItemValue
Packagevault (HashiCorp repository)
Servicevault.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)
Ports8200/tcp (API and UI), 8201/tcp (cluster)
Client settingsVAULT_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 …).

Commando's in deze les

27.2

Install on RHEL, Rocky, Alma and Fedora

dnf -y install dnf-plugins-core
dnf config-manager --add-repo https://rpm.releases.hashicorp.com/RHEL/hashicorp.repo
dnf -y install vault
vault version

27.3

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 vault

Op 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.

27.4

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.

/etc/vault.d/vault.hcl
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"
SettingWhy
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 = trueRecommended with Raft storage (and turn off swap on the server instead).
api_addr, cluster_addrThe addresses clients and other nodes use.
ui = trueThe 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              false

27.5

Initialize 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                   false

Let 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.

Commando's in deze les

27.6

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/db

A policy that may only read the shop secrets:

shop-read.hcl
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_ID

The 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.

27.7

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).snap

Real 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.

27.8

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_id with TTL and CIDR limits.
  • Regular Raft snapshots, encrypted, stored elsewhere — and a restore test.
  • Three nodes (Raft) for production; keep Vault updated.

27.9

Update and remove

Back up first, then upgrade (standby nodes first in a cluster). Vault is sealed after the restart:

vault operator raft snapshot save /backup/vault-before-upgrade.snap
dnf -y upgrade vault
apt-get install --only-upgrade -y vault
systemctl restart vault
vault operator unseal

27.10

Fix common problems

ProblemCauseFix
Vault is sealed (error 503) after a restartNormal: Vault starts sealed.vault operator unseal with enough keys, or set up auto-unseal.
x509: certificate signed by unknown authorityThe 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 clientVAULT_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 keyWrong owner or mode.chown -R vault: /opt/vault; key readable by vault.
failed to lock memory: cannot allocate memorymlock 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.

27.11

Next steps

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/*.

Alle commando's in dit hoofdstuk