← Course Index

5.8 Secrets Management & Dynamic Credentials:
Vault Architecture, Leases & Rotation

Centralizing Secret Storage, Issuing Short-Lived & Renewable Leases, Enforcing Least-Privilege Policies & Auditing Access

Module 5: Cloud & Container Security Secrets Management Dynamic Leases & Rotation

1. Reducing Static Secret Exposure with Dynamic Leases

Hardcoding API tokens, database passwords, or cloud keys in source code, environment files, or CI configs creates long-lived blast radius if leaked. A centralized secrets manager like HashiCorp Vault authenticates workloads via trusted identities, enforces fine-grained policies, and—where supported—issues short-lived credentials backed by leases with time-to-live (TTL), renewal, and revocation.

Short-Lived Over Long-Lived: Credentials with bounded leases and straightforward revocation limit exposure compared to static secrets that stay valid until someone remembers to rotate them manually.
CLIENT / WORKLOAD Authenticate via Identity Request Secret or Lease Renew or Revoke as Needed VAULT POLICY & SECRETS CORE Auth & Policy Evaluation Verify identity & path capabilities Secrets Engines & Leases KV, dynamic creds, TTL & renewal Audit & Revocation Log requests • Revoke leases/tokens Monitor seal & health status SECURITY BENEFITS • No Plaintext Secrets in Repo • Bounded Credential Lifetime • Auditable Access & Revoke
Figure 5.8: Secrets Management Flow Covering Identity Auth, Policy Checks, Lease Lifecycle, and Auditability.

2. Key Secrets Management & Rotation Practices

Concept What It Does Operational Guidance
Scoped Policies Restricts which paths and operations (read, create, update, delete, list) a policy allows. Grant only the exact secret paths and capabilities a workload or role needs.
Leases, TTL & Revocation Tracks active credential lifetimes, supports lease renewal, and enables revoking leases when needed. Keep TTLs appropriately short and revoke leases promptly during incidents or deprovisioning.
Rotation & Secret Scanning Refreshes credentials periodically and catches accidental secrets in code or commits before exposure. Automate rotation where supported and run secret checks in local/CI workflows.
Never Log or Commit Raw Secrets: Avoid printing secret values in CI build logs, shell histories, or screenshots, and revoke and rotate any secret that may have been exposed.

3. Practical Secrets Management, Lease & Audit Examples (10 Scenarios)

Example 1: Vault HCL Policy — Least-Privilege Read Access to a Service Path

HCL (Vault Policy) — Granting Read/List on One App Secret Path Only
path "secret/data/payments/prod/*" {
  capabilities = ["read", "list"]
}
SAMPLE OUTPUT
Success! Uploaded policy: payments-prod-reader

Example 2: Checking Vault Status & Seal State via CLI

Shell (vault) — Inspecting Vault Server Status
vault status
SAMPLE OUTPUT
Key             Value
---             -----
Seal Type       shamir
Initialized     true
Sealed          false
Total Shares    5
Threshold       3
Version         1.17.2

Example 3: Reading a Secret from KV v2 via Vault CLI

Shell (vault kv) — Retrieving Secret Metadata or Fields
vault kv get -mount=secret payments/prod/api-config
SAMPLE OUTPUT
=== Metadata ===
Key              Value
---              -----
created_time     2026-11-20T08:15:00.123456Z
current_version  2
max_versions     10

=== Data ===
Key       Value
---       -----
endpoint  https://api.payments.example.internal

Example 4: Inspecting and Renewing a Lease via Vault CLI

Shell (vault lease) — Checking Lease Details and Renewing TTL
vault lease lookup database/creds/readonly/lease-abc123
vault lease renew -increment=1800 database/creds/readonly/lease-abc123
SAMPLE OUTPUT
Key             Value
---             -----
expire_time     2026-11-26T12:15:00+05:30
last_renewal    2026-11-26T11:45:00+05:30
renewable       true
ttl             29m58s

Example 5: Revoking a Specific Lease via Vault CLI

Shell (vault lease) — Revoking an Active Lease Immediately
vault lease revoke database/creds/readonly/lease-abc123
SAMPLE OUTPUT
All revocation operations queued!

Example 6: Scanning a Directory for Common Secret Patterns (Python)

Python (re) — Checking Text Files for Sample Token/Key Assignment Patterns
import re

pattern = re.compile(r"(?i)\b(api_key|secret_key|password)\s*=\s*['\"][^'\"]{8,}['\"]")
lines = [
    "db_host = 'localhost'",
    "api_key = 'sk_test_example_placeholder_12345'",
]

for idx, line in enumerate(lines, start=1):
    if pattern.search(line):
        print(f"Line {idx}: potential secret assignment matched")
SAMPLE OUTPUT
Line 2: potential secret assignment matched

Example 7: Hunting Suspicious Secret or Key Access in Logs (KQL)

KQL (Microsoft Sentinel) — Reviewing Vault / Secret Read or Lease Events
DeviceProcessEvents
| where Timestamp > ago(24h)
| where FileName in~ ("vault", "vault.exe")
| summarize
    Commands = count(),
    Hosts = dcount(DeviceName),
    SampleCmds = make_set(ProcessCommandLine, 5)
  by AccountName, FileName
| order by Commands desc
SAMPLE OUTPUT
AccountName FileName Hosts SampleCmds
----------- -------- ----- ----------
app_runner  vault    2     ["vault lease renew -increment=1800 database/creds/readonly/lease-abc123"]

Example 8: Velociraptor VQL — Checking Environment Variable Names on a Host

VQL (Velociraptor) — Listing Running Processes for Audit
SELECT
  Pid,
  Name,
  Exe
FROM pslist()
WHERE Name =~ "(?i)^(vault|vault\\.exe)$"
SAMPLE OUTPUT
Pid   Name  Exe
---   ----  ---
2840  vault /usr/local/bin/vault

Example 9: Wazuh Rule — Alerting on Secret or Config File Changes

XML (Wazuh Rule) — Flagging Changes to Monitored Secret/Config Paths

  
    550
    /etc/vault.d/|/opt/secrets/
    Monitored secrets or vault configuration file changed on $(agent.name)
  
SAMPLE OUTPUT
** Alert 1795696104.88120: - local,secrets_management,audit
2026 Nov 26 11:32:09 (vault-node-01) 10.20.3.15->syscheck
Rule: 101601 (level 10) -> 'Monitored secrets or vault configuration file changed on vault-node-01'

Example 10: Checking Vault CLI Availability & Address Config (Bash)

Bash — Checking Vault CLI & VAULT_ADDR Configuration
command -v vault >/dev/null 2>&1 && echo "vault: available" || echo "vault: not found"
echo "VAULT_ADDR=${VAULT_ADDR:-unset}"
SAMPLE OUTPUT
vault: available
VAULT_ADDR=https://vault.example.internal:8200

4. Interactive Secrets & Lease Simulator

Select a secrets management scenario below to review the operational steps and security guidance:

← Previous: 5.7 Static Application Security Testing (SAST) Return to Course Index →