Chapter 27 / 28
Production Hardening Guide
HashiCorp Vault For Beginners6 min read
Vault is designed to be secure by default, but in production, defaults alone won’t save you. Hardening your Vault deployment is not just about compliance—it’s about protecting the most sensitive data in your entire infrastructure.
This chapter covers everything you need to lock down Vault in production, including:
- Network security
- TLS and certificates
- Authentication controls
- Audit logging
- OS and file system hardening
- Token and lease management
- Rate limiting
- Recommended configuration flags
1. Use TLS Everywhere
Vault requires TLS in production. This protects the Vault API from eavesdropping, MITM attacks, and credential theft.
Generate and Use Strong Certificates
- Use an internal CA or Vault's PKI engine to generate trusted certs.
- Avoid self-signed certificates unless Vault is deployed in complete isolation.
Example (via OpenSSL):
openssl req -x509 -nodes -days 365 \
-newkey rsa:4096 \
-keyout vault.key \
-out vault.crt \
-subj "/CN=internal.vault.local"
Vault Configuration for TLS
listener "tcp" {
address = "0.0.0.0:8200"
tls_cert_file = "/etc/vault/tls/vault.crt"
tls_key_file = "/etc/vault/tls/vault.key"
}
2. Restrict Network Access
Vault should never be exposed directly to the public internet.
Limit Access via Firewalls or Security Groups
Allow access to Vault only from:
- Internal services that authenticate to Vault
- Admin networks or bastion hosts
Recommended ports:
| Port | Description |
|---|---|
| 8200 | Vault API / UI |
| 8201 | Cluster communication (Raft) |
Block 8200 from all external IPs.
3. Run Vault as a Non-Root User
Vault does not need root privileges to function.
Create a vault user:
useradd --system --home /etc/vault.d --shell /bin/false vault
Set ownership:
chown -R vault:vault /etc/vault.d /opt/vault
Update your vault.service:
[Service]
User=vault
Group=vault
4. Enable Memory Locking (mlock)
This prevents secrets from being written to disk (via swap).
[Service]
LimitMEMLOCK=infinity
Also give the Vault binary permission to lock memory:
setcap cap_ipc_lock=+ep /usr/local/bin/vault
5. Disable the Root Token
The root token should not be used beyond initial bootstrapping. Revoke it and rely on tightly scoped policies and real authentication methods.
Use Role-Based Auth Methods
Recommended production methods:
userpassorLDAPfor adminsAppRole,Kubernetes, orTLSfor apps
6. Enable Audit Logging
Audit logs are the only way to track who did what in Vault.
Configure File-Based Audit Log
vault audit enable file file_path=/var/log/vault_audit.log
Ensure file is owned by vault and not world-readable.
7. Configure Token and Lease Security
Set tight defaults for:
# vault.hcl
default_lease_ttl = "1h"
max_lease_ttl = "24h"
Set these in your auth methods as well (e.g., AppRole):
vault write auth/approle/role/my-app \
token_ttl=60m \
token_max_ttl=2h \
secret_id_ttl=30m
8. Enable Rate Limiting
Vault can be overwhelmed if a client loops or is misconfigured. Rate limiting protects Vault from unintentional DoS.
9. Use Integrated Storage with Raft
Avoid file-based or dev backends in production.
Use:
storage "raft" {
path = "/opt/vault/data"
node_id = "vault-1"
}
- Highly available
- Supports snapshots
- Secure and robust
10. Harden the Vault via OS
- Use Ubuntu LTS or RHEL Minimal
- Disable unnecessary services (
systemctl disable) - Remove compilers, shells, user tools
- Use
iptablesorufwto lock ports - Apply automatic security updates
11. Automate Backups & Snapshots
Set up regular Vault snapshots:
vault operator raft snapshot save /backups/vault-$(date +%F).snap
Use cron and back them up securely.
12. Enforce Configuration Checks
Vault’s config is plaintext—treat it as sensitive.
Use automated scanners to detect issues:
- Ownership
- Permissions
- TLS enabled
- Token TTLs
Recap
| Area | Recommendation |
|---|---|
| TLS | Always enabled, use valid certs |
| Network | Internal only, restrict 8200/8201 |
| Audit Logs | File-based, protected |
| Auth Methods | Root token disabled, roles used |
| OS User | Vault runs as non-root |
mlock | Enabled with systemd & setcap |
| Storage | Raft, secured, regularly backed up |
| Rate Limiting | Via proxies or service mesh |
| Snapshots | Scheduled, versioned backups |
Trust, but verify. Every auth method, secret engine, and configuration should be revisited periodically. Secrets don’t expire—you have to rotate them.