Sub topic 13
Expiry, Rotation, and Revocation
This chapter assumes you can already sign commits and tags with a GPG or SSH key, verify them locally, and register a key with a hosting platform. Keys do not last forever. You will plan for three events: a key expiring, a key being replaced, and a key being compromised.
What happens to old signatures
A signature is checked against a key. If that key later expires or is replaced, old commits do not change, because Git stores the signature inside the commit object. What changes is how verification tools judge it.
- GPG reports a signature made by an expired key as good but notes that the key has expired. The signature was made while the key was still valid.
- SSH keys have no built-in expiry. Expiry exists only if you add a validity interval to the allowed signers file.
- A revoked GPG key makes verification report a revoked key. A revoked key cannot tell you whether a commit was signed before or after the compromise, unless the revocation carries a date you trust.
Expiry for GPG keys
Set an expiry when you create the key. When gpg --full-generate-key asks how long the key is valid, choose a period such as 1y or 2y. An expiry limits the damage from a key you lose track of.
You can also extend an expiry later, as long as you still have the private key.
gpg --list-secret-keys --keyid-format=long
gpg --edit-key 3AA5C34371567BD2
# At the gpg> prompt:
# expire
# (answer the prompts, for example 1y)
# save
gpg --armor --export 3AA5C34371567BD2 > public-key.ascUpload the exported public key again to your hosting platform. The platform holds a copy of the old expiry date until you do.
Rotating a key
Rotation means replacing a key with a new one on a schedule, or earlier when you change machines or the key's strength becomes a concern. The steps are the same for GPG and SSH.
- Generate the new key.
- Register the new public key with your hosting platform.
- Switch Git to the new key with
git config --global user.signingkey. - Keep the old public key registered and in your allowed signers file, so old commits still verify.
- Remove the old key from your signing configuration, and from your SSH agent if you use one.
For SSH signing, add the new key to the allowed signers file next to the old one. A principal can have several lines.
ssh-keygen -t ed25519 -C "[email protected]" -f ~/.ssh/id_ed25519_signing_2027
echo "[email protected] $(cat ~/.ssh/id_ed25519_signing_2027.pub)" >> ~/.config/git/allowed_signers
git config --global user.signingkey ~/.ssh/id_ed25519_signing_2027.pubYou can limit an old key to the period when it was in use. An allowed signers entry accepts a valid-before option placed before the key type.
[email protected] valid-before="20271231" ssh-ed25519 AAAAC3...old-key
[email protected] valid-after="20280101" ssh-ed25519 AAAAC3...new-keyRevoking a compromised key
Revoke a key when the private key is lost, stolen, or exposed. For GPG, generate a revocation certificate while you still control the key, and store it somewhere safe and offline.
gpg --output revoke-3AA5C343.asc --gen-revoke 3AA5C34371567BD2If the key is compromised, import the certificate and publish the result.
gpg --import revoke-3AA5C343.asc
gpg --armor --export 3AA5C34371567BD2 > revoked-public-key.ascThen upload the revoked public key to your hosting platform and any keyserver you used. SSH has no revocation certificate. Remove the key from the allowed signers file and from your hosting account, then tell your collaborators.
Exercise
Your SSH signing key expires on a schedule you set in the allowed signers file, and you have just rotated to a new key. Why should you keep the old public key in the file?
Show answer
Old commits and tags were signed with the old key. Without its public key in the allowed signers file, git log --show-signature cannot verify them. Keep it, and use valid-before to limit it to the period when it was in use.
Exercise
You lose a laptop that holds your only GPG private key and you have a saved revocation certificate. What do you do?
Show answer
Import the revocation certificate with gpg --import, export the revoked public key, and upload it to your hosting platform and any keyserver. Then create a new key and configure Git to use it.