🧠 What is Secrets Management?
Secrets management is the secure storage, distribution, and access control of sensitive data such as:
- API keys
- Database passwords
- Access tokens
- Certificates
- SSH keys
- Encryption keys
The goal is to protect secrets from exposure, while still making them available to applications that need them.
🔐 Why Secrets Management is Needed
Without a proper secrets management system, teams often:
- Hardcode secrets in code or config files (❌ unsafe)
- Store secrets in environment variables without encryption (❌ risky)
- Struggle with rotating credentials securely
Secrets management ensures:
- Secrets are encrypted at rest and in transit
- Access is audited, controlled, and revocable
- Secrets can be rotated automatically
🏗️ Components of a Secrets Management System
| Component | Description |
|---|---|
| Secret Store | Encrypted database that stores secrets securely |
| Access Control | Defines who or what can access secrets (via roles/policies) |
| Audit Logs | Records all access and usage |
| Rotation | Ability to rotate secrets automatically |
| Integration | Works with apps, CI/CD, and cloud environments |
⚙️ Tools for Secrets Management
Two popular tools:
1️⃣ HashiCorp Vault
2️⃣ Kubernetes Secrets
🧱 1️⃣ HashiCorp Vault
🔹 What It Is
Vault is a centralized secrets management system created by HashiCorp. It securely stores and controls access to tokens, passwords, certificates, and encryption keys.
🔹 Key Features
| Feature | Description |
|---|---|
| Dynamic Secrets | Vault can generate secrets on-demand (e.g., temporary DB credentials) |
| Encryption as a Service | Apps can encrypt/decrypt data without handling keys |
| Secret Leasing & Revocation | Secrets have a TTL (time-to-live) and can be revoked |
| Audit Logging | All access attempts are logged |
| Fine-Grained Access Policies | Uses ACL policies via Vault’s internal authentication |
🔹 Example
Step 1: Store a secret
vault kv put secret/db password=MySecurePassword
Step 2: Retrieve a secret
vault kv get secret/db
Step 3: App reads it securely (Java example)
String vaultToken = "s.xxxxx";
VaultConfig config = new VaultConfig()
.address("https://vault.mycompany.com")
.token(vaultToken)
.build();
Vault vault = new Vault(config);
LogicalResponse response = vault.logical().read("secret/db");
String password = response.getData().get("password");
Vault ensures:
- Secrets are encrypted at rest (AES-256)
- Access is authenticated via tokens, IAM, or Kubernetes auth
- Passwords can expire automatically
🧩 2️⃣ Kubernetes Secrets
🔹 What It Is
In Kubernetes, Secrets are objects used to store small pieces of sensitive data — such as passwords, OAuth tokens, or SSH keys.
Stored in the Kubernetes API and base64-encoded (not encrypted by default).
🔹 Example
apiVersion: v1
kind: Secret
metadata:
name: db-secret
type: Opaque
data:
username: bXl1c2Vy # base64 encoded 'myuser'
password: TXlQYXNzIQ== # base64 encoded 'MyPass!'
Use it in a Pod:
env:
- name: DB_USERNAME
valueFrom:
secretKeyRef:
name: db-secret
key: username
🔹 Security Enhancements
- Enable encryption at rest in Kubernetes (via
EncryptionConfiguration) - Use RBAC to restrict who can access Secrets
- Integrate with Vault for dynamic and encrypted secrets
🔄 Vault + Kubernetes Integration
Vault can be integrated with Kubernetes for dynamic secret injection:
- App authenticates using Kubernetes Service Account token
- Vault verifies and issues a temporary token
- App retrieves secrets dynamically from Vault
🔹 Benefits:
- No hardcoded secrets in YAML files
- Secrets rotate automatically
- Vault handles encryption & auditing
🧰 Example Use Case
Scenario: A microservice needs a DB password.
Without Secrets Management:
- Password stored in Git config file ❌
With Vault + Kubernetes:
- Vault dynamically generates a DB password valid for 1 hour
- Service fetches it securely using a Vault token
- Password auto-expires after TTL ⏳
🧠 Summary
| Feature | HashiCorp Vault | Kubernetes Secrets |
|---|---|---|
| Encryption | Yes (strong AES-256) | Base64 by default, can enable encryption |
| Dynamic Secrets | ✅ Yes | ❌ No |
| Secret Rotation | ✅ Auto | ⚠️ Manual |
| Authentication | Tokens, IAM, AppRole, K8s | ServiceAccount |
| Best For | Multi-environment, enterprise setups | Simpler K8s apps |
🧩 Analogy
Think of Vault as a high-security vault in a bank 🏦 Only authorized users with valid ID (token) can open specific boxes (secrets). Kubernetes Secrets, on the other hand, are like lockers with passcodes — simple but less secure unless you add extra locks (encryption + RBAC).