Skip to content

Vault — alert when a secret has not rotated in N days

Compliance mandates rotating DB credentials every 90 days. Vault static-creds engine should do it, but someone set max_ttl=0 — the secret lives forever. The auditor finds it first.

Recipe

bash
#!/usr/bin/env bash
# /etc/cron.d/vault-rotation
# 0 6 * * * root /opt/vault-rotation.sh

export VAULT_ADDR=${VAULT_ADDR}
export VAULT_TOKEN=${VAULT_TOKEN}
PATHS=${PATHS:-database/static-creds/app1,database/static-creds/app2}
MAX_DAYS=${MAX_DAYS:-90}

NOW=$(date +%s)
STALE=""
IFS=',' read -ra LIST <<< "$PATHS"
for P in "${LIST[@]}"; do
  TS=$(vault read -format=json "$P" 2>/dev/null \
    | jq -r '.data.last_vault_rotation // ""')
  [ -z "$TS" ] && continue
  EPOCH=$(date -d "$TS" +%s 2>/dev/null || echo 0)
  DAYS=$(( (NOW - EPOCH) / 86400 ))
  if [ "$DAYS" -gt "$MAX_DAYS" ]; then
    STALE="$STALE$P=${DAYS}d,"
  fi
done

if [ -n "$STALE" ]; then
  curl -fsS "$HEARTBEAT_URL" --data-urlencode "stale_secrets=$STALE"
  exit 2
fi
echo "OK (all secrets rotated within ${MAX_DAYS}d)"

Same thing in Enterno.io

Wrap in an Enterno heartbeat with 365-day retention — the auditor sees "we knew and fixed it" instead of "found on audit day".

Set up API monitor → ← All recipes

Related recipes