Skip to content

Rotate a compromised GPG key

Remove a compromised private key from every vault it could read and rotate the underlying secrets at their source. Applies whether the compromised key is yours or a teammate’s.

  1. Generate or import a replacement identity. If the compromised key is yours, generate a new pair (gpg --full-generate-key), publish the new public key, and have each teammate import it.

  2. Revoke the compromised fingerprint from every affected secret. Quote the wildcard so the shell does not expand it.

    Terminal window
    dotsecenv secret revoke "*" <COMPROMISED_FP> --all
  3. Add the replacement recipient.

    Terminal window
    dotsecenv secret share <SECRET_NAME> <NEW_FP> --all
  4. Rotate each affected secret at its source. Generate a new credential at the originating system (database, IDP, cloud provider, API issuer) and store it. This is what neutralizes the compromise.

    Terminal window
    echo "<new-value>" | dotsecenv secret store <SECRET_NAME>
  5. Verify. Every current secret should list the new key as a recipient and not the compromised one.

    Terminal window
    dotsecenv vault doctor
    dotsecenv vault describe
  6. Commit.

    Terminal window
    git add path/to/vault
    git commit -m "Rotate compromised key <COMPROMISED_FP>, rotate N secrets"
  • Erase a leaked entry from the vault file. Append-only by design. Rewriting git history with git filter-repo is possible, but anyone who already cloned the repo still has the old data and the compromised key still decrypts it.
  • Re-encrypt an existing entry to a different recipient set. secret share and secret revoke only affect future writes. Source rotation is the only fix.