Stackbook Logo
operations

Secrets Rotation Framework

Intent

Limit the exposure window of leaked credentials by rotating secrets automatically on a defined schedule and on demand.

Problem

Long-lived passwords, API keys, and certificates accumulate in config files, CI variables, and developer laptops. When one leaks, it often remains valid for years. Manual rotation is error-prone, so it is postponed until an incident forces it.

Forces

    Solution

    Secrets Rotation Framework

    Every secret should be treated as temporary. A rotation framework defines how secrets are stored, delivered, replaced, and revoked so that a leak has a bounded impact and replacement is routine rather than an emergency.

    The strongest rotation strategy is to remove the secret entirely. Workload identity, federated tokens, and IAM roles let services authenticate without stored values, so apply rotation mainly to what remains: third-party keys, legacy database accounts, signing keys, and certificates.

    How it works

    A secrets manager holds versioned values and exposes them through an API with fine-grained access control. Workloads authenticate with their platform identity and fetch secrets at start-up or on a refresh interval. Rotation uses a two-phase pattern: create a new version, make the backend accept both, update consumers, verify, and then retire the old version. For databases, dynamic credentials issue a unique user per lease that expires automatically.

    Implementation steps

    1. Inventory secrets by type, owner, location, and current age, using scanners on repositories and CI.
    2. Classify by blast radius and set maximum lifetimes, for example 30 days for database passwords and 90 days for third-party API keys.
    3. Move secrets into the managed store and remove them from code, images, and CI variables.
    4. Make applications reload credentials without restart, or use sidecar agents that renew files.
    5. Implement rotation functions with a validation step before retiring the old version.
    6. Alert on secrets nearing expiry and on failed rotations.
    7. Write and rehearse a break-glass revocation runbook.

    Start with the highest-risk secrets, such as production database administrators and cloud root credentials, then expand outward. Early success on a few critical items builds support for the wider program.

    Common pitfalls

    • Rotating a secret in the store but not in the consuming system, breaking authentication.
    • Deleting the old version before every consumer has switched.
    • Caching secrets in memory forever.
    • Forgetting certificates and signing keys, which expire quietly.

    Metrics to watch

    Maximum and median secret age, percentage of secrets rotated automatically, rotation failure rate, time to revoke a compromised secret, and the number of secrets found by repository scanners.

    Pair rotation metrics with detection signals such as access anomalies from the secrets manager audit log. Rotation reduces the window of exposure, while monitoring tells you when a window was actually used.

    Example rotation policy

    secret: orders-db-password
    owner: orders-team
    store: managed-secrets
    rotation:
      interval_days: 30
      strategy: dual-user
      steps:
        - create_new_credential
        - grant_same_privileges
        - publish_new_version
        - verify_connections_for_minutes: 15
        - revoke_previous_credential
    alerts:
      expiry_warning_days: 7
      on_failure: page-oncall
    

    Key takeaways

    • Inventory first, then set lifetimes by blast radius.
    • Overlap old and new versions to rotate without downtime.
    • Applications must tolerate reloads.
    • Rehearse emergency revocation before you need it.

    ✓ When to Use

    • •Applications use static database or API credentials
    • •Compliance requires documented rotation intervals
    • •Certificates expire and have caused outages before
    • •After a suspected credential leak or staff departure

    ✗ When Not to Use

    • •When consumers cannot reload secrets without restart and no workaround exists
    • •For secrets that are better eliminated through workload identity
    • •When secrets are not yet inventoried

    Pros

    • +Shrinks the usable lifetime of leaked secrets
    • +Removes manual, error-prone rotation work
    • +Gives an audit trail of access and change
    • +Enables fast incident response

    Cons

    • −Consumers must handle reloads gracefully
    • −Rotation failures can cause outages
    • −Initial inventory and migration effort is large
    • −Adds dependency on the secrets platform

    Cost Profile

    Infrastructure

    Operational

    Cognitive

    Failure Modes

      Alternatives

        Related Patterns

          Competency Domains

          security compliancereliability opsdata state