HashiCorp Vault
HashiCorp Vault
A secrets management tool. Dynamic secrets, encryption, and access control.
HashiCorp Vault
A secrets management tool. Dynamic secrets, encryption, and access control.
HashiCorp Vault is a tool for securely storing, accessing, and managing secrets (passwords, API keys, certificates, etc.). It is not just a storage system but a complete secrets management platform that provides dynamic secret generation, encryption services, fine-grained access control, and audit logging.
One of Vault's core features is Dynamic Secrets. Each time database access is needed, it generates temporary credentials and automatically revokes them after a TTL (Time To Live). Even if a secret is leaked, its short lifespan limits the damage. It supports various backends such as AWS, GCP, Azure, PostgreSQL, and MySQL.
The Transit secrets engine provides a data encryption service. Applications do not manage encryption keys directly; instead, they perform encryption and decryption through the Vault API. Key rotation, support for various encryption algorithms, and HSM (Hardware Security Module) integration are available.
Vault provides various authentication methods (LDAP, OIDC, Kubernetes, AWS IAM, etc.) and fine-grained policy-based access control. All operations are recorded in audit logs, satisfying compliance requirements. In Kubernetes environments, secrets can be automatically injected into Pods using the Vault Agent Injector.
# Vault CLI κΈ°λ³Έ μ¬μ©
# 1. KV (Key-Value) μν¬λ¦Ώ μ μ₯/μ‘°ν
vault kv put secret/myapp/config \
db_host="db.example.com" \
db_user="app_user" \
db_password="super-secret-123"
vault kv get secret/myapp/config
vault kv get -field=db_password secret/myapp/config
# 2. λμ λ°μ΄ν°λ² μ΄μ€ μν¬λ¦Ώ μ€μ
# PostgreSQL μν¬λ¦Ώ μμ§ νμ±ν
vault secrets enable database
# λ°μ΄ν°λ² μ΄μ€ μ°κ²° μ€μ
vault write database/config/mydb \
plugin_name=postgresql-database-plugin \
connection_url="postgresql://{{username}}:{{password}}@db.example.com:5432/mydb" \
allowed_roles="app-role" \
username="vault_admin" \
password="admin-password"
# μν μμ± (μμ μ격 μ¦λͺ
ν
νλ¦Ώ)
vault write database/roles/app-role \
db_name=mydb \
creation_statements="CREATE ROLE \"{{name}}\" WITH LOGIN PASSWORD '{{password}}' VALID UNTIL '{{expiration}}'; \
GRANT SELECT, INSERT, UPDATE ON ALL TABLES IN SCHEMA public TO \"{{name}}\";" \
default_ttl="1h" \
max_ttl="24h"
# λμ μ격 μ¦λͺ
μμ± (1μκ° ν μλ νκΈ°)
vault read database/creds/app-role
# username: v-token-app-role-xxx
# password: A1b2C3d4E5F6...
# lease_duration: 1h
# --------------------------------------------------------
# Node.jsμμ Vault μ¬μ©
import Vault from 'node-vault';
const vault = Vault({
apiVersion: 'v1',
endpoint: 'https://vault.example.com:8200',
token: process.env.VAULT_TOKEN
});
// KV μν¬λ¦Ώ μ‘°ν
async function getSecrets() {
const result = await vault.read('secret/data/myapp/config');
return result.data.data; // { db_host, db_user, db_password }
}
// λμ DB μ격 μ¦λͺ
νλ
async function getDatabaseCredentials() {
const result = await vault.read('database/creds/app-role');
return {
username: result.data.username,
password: result.data.password,
leaseId: result.lease_id,
leaseDuration: result.lease_duration
};
}
// Transit μμ§μΌλ‘ λ°μ΄ν° μνΈν
async function encryptData(plaintext: string) {
const result = await vault.write('transit/encrypt/my-key', {
plaintext: Buffer.from(plaintext).toString('base64')
});
return result.data.ciphertext; // vault:v1:xxxxx
}
async function decryptData(ciphertext: string) {
const result = await vault.write('transit/decrypt/my-key', {
ciphertext: ciphertext
});
return Buffer.from(result.data.plaintext, 'base64').toString();
}
In the DevSecOps transition:
"Hardcoding secrets in .env files was flagged in a security audit. Adopting Vault enables centralized secrets management, access logging, and even dynamic credentials. If you're on Kubernetes, you can integrate it using the External Secrets Operator."
In a technical interview:
"What are the advantages of dynamic secrets?" - "Static passwords pose a permanent risk if leaked, but dynamic secrets are generated with a short TTL and automatically revoked. Even if an attacker steals one, it is likely to have already expired."
In architecture design:
"How do you set up Vault HA?" - "Use a cluster of at least 3 nodes with Raft storage. It has a leader-follower structure, and a new leader is automatically elected if the leader fails. In production, Auto Unseal (such as AWS KMS) is also essential."
Take a mock interview on this topic β WIA SOOM AI Interview Β· Start for free