Sub topic 13
Expiry, Rotation, and Revocation
This chapter assumes you can already sign commits and tags with a GPG or SSH key and verify them locally. You should know what gpg.format does and how an allowed signers file works. Keys do not last forever. Laptops get replaced, keys leak, and people leave teams. This chapter covers how to plan for those events so old signatures stay meaningful and new ones stay trustworthy.
Why key lifecycle matters
A signature ties a commit to a key. It does not tie the commit to a person, and it does not say when the key stopped being safe. If a private key is stolen, the thief can sign commits that look exactly like yours. A lifecycle plan answers three questions:
- How long should a key be valid? This is expiry.
- How do you move to a new key without breaking verification? This is rotation.
- How do you tell others a key must no longer be trusted? This is revocation.
GPG and SSH handle these differently. GPG has built-in expiry and revocation certificates. SSH keys have no expiry in the key itself, so you manage lifecycle through the allowed signers file, certificates, and your hosting platform.
Expiry in GPG
A GPG key carries an expiry date inside its public part. When you ran gpg --full-generate-key, you chose a validity period. Many people pick one to two years.
An expired key cannot create new signatures. GnuPG refuses to sign with it. Verification of old signatures is more subtle. GnuPG checks whether the key was valid when the signature was made, but its output may still flag the key as expired. Treat that flag as informational for old commits, and as a stop sign for new ones.
Expiry is a safety net. If you lose a key and never revoke it, expiry still ends its useful life. This is why a finite expiry is better than "never expires".
Inspecting and extending expiry
You can change the expiry of an existing key without creating a new one. Extending works even after the key has expired, as long as you still have the private key.
gpg --list-secret-keys --keyid-format=long
gpg --edit-key 3AA5C34371567BD2Inside the interactive prompt, run these commands:
gpg> expire
Key is valid for? (0) 1y
gpg> saveAfter extending, export the updated public key and re-upload it to your hosting platform and any keyserver you use. Others will not see the new date until they refresh your public key. A common mistake is extending locally and then wondering why the hosting platform still shows the key as expired.
gpg --armor --export 3AA5C34371567BD2 > public-key.ascSubkeys
A GPG key is usually a primary key plus subkeys. By default, the primary key has the certify capability ([SC] in the listing means sign and certify), and you can add a dedicated signing subkey. A subkey has its own expiry and can be revoked on its own.
This lets you keep the primary key offline and rotate only the subkey that lives on your laptop. The identity people trust stays the same while the exposed key changes. The cost is more setup and more commands to remember.
Expiry for SSH signing keys
An ordinary SSH key has no expiry date. Two places can add one.
First, each line in the allowed signers file can carry a valid-after and valid-before option. Git passes these to ssh-keygen, which checks them against the commit timestamp.
[email protected] valid-after="20260101" valid-before="20270101" ssh-ed25519 AAAAC3NzaC1lZDI1NTE5AAAA...Second, you can use SSH certificates, where a certificate authority signs your public key with a validity window. This suits organizations that already run an SSH CA. It is more machinery than most small teams need.
Note that the allowed signers file is local. The date window only protects people who use that file. Your hosting platform has its own list of keys and does not read your file.
Rotation
Rotation means replacing a key before you have to. Do it on a schedule, when you change machines, or when you suspect exposure. The goal is to keep every older signature verifiable while new commits use the new key.
The safe order is: add the new key everywhere, switch signing, then retire the old key.
# 1. Create the new SSH signing key
ssh-keygen -t ed25519 -C "[email protected]" -f ~/.ssh/id_ed25519_signing_2027
# 2. Trust both keys locally during the transition
echo "[email protected] $(cat ~/.ssh/id_ed25519_signing_2027.pub)" >> ~/.config/git/allowed_signers
# 3. Point Git at the new key
git config --global user.signingkey ~/.ssh/id_ed25519_signing_2027.pubDo not delete the old public key from the allowed signers file. If you do, git log --show-signature will report old commits as unverifiable, even though they were fine when made. Keep old entries, and add a valid-before date so the old key cannot be accepted for commits made after the switch.
Rotation checklist
- Generate the new key and protect it with a passphrase or a hardware token.
- Register the new public key with your hosting platform as a signing key.
- Add the new key to the allowed signers file used by you and your team.
- Update
user.signingkeyin your Git configuration. - Make a test commit and verify it locally and on the platform.
- Add an end date to the old key in the allowed signers file.
- Remove the old key from your hosting platform only after you have decided what to do about old commit badges (see below).
What happens to old badges
Hosting platforms differ in how they treat commits after you remove a key. Some keep the stored verification result for existing commits. Others re-evaluate and may show the commit as unverified. Check your platform's documentation before deleting a key. If badges on historic commits matter to you, leave the old key registered, or keep it with an expired status if the platform supports it.
Revocation
Revocation is for when a key must not be trusted anymore, usually because the private key leaked or the device was lost. It is different from expiry. Expiry is planned. Revocation is a statement that the key is compromised.
Revoking a GPG key
Create a revocation certificate right after you create the key, and store it somewhere safe and separate from the key. If you lose the private key and its passphrase, the certificate is the only way to revoke it.
gpg --output revoke-3AA5C34371567BD2.asc --gen-revoke 3AA5C34371567BD2GnuPG asks for a reason, such as "key has been compromised". To revoke, import the certificate into your keyring, then publish the result.
gpg --import revoke-3AA5C34371567BD2.asc
gpg --armor --export 3AA5C34371567BD2 > revoked-public-key.asc
gpg --keyserver keys.openpgp.org --send-keys 3AA5C34371567BD2Upload the revoked public key to your hosting platform as well. Revocation only works as far as it spreads. Anyone who never refreshes your key will not learn about it.
Treat the revocation certificate like a private key. Anyone who gets it can revoke your key, which is annoying but not dangerous. It is much less sensitive than the key itself.
Revoking an SSH signing key
SSH has no standard public revocation system for signing keys. You revoke in the places that matter:
- Remove the key from your hosting platform's signing key list.
- Remove it from the allowed signers file, or mark it with
valid-beforeset to the date of compromise. - Tell your team to update their copies of the shared allowed signers file.
- If you use SSH certificates, add the key to a revoked keys file.
ssh-keygen can verify against a revocation list with the -r option when you verify a signature manually. Git does not configure this for you, so teams that need it must script their own checks.
The compromise problem
A revoked key raises a hard question. Which commits signed by that key can you still trust?
Signatures carry no trustworthy timestamp. A commit's date is set by the author and can be faked. An attacker with your stolen key can create a commit dated last year. Because of that, revocation cannot cleanly separate good old commits from bad new ones.
You have a few options, each with trade-offs:
| Approach | Benefit | Cost |
|---|---|---|
| Mark the key invalid from the date of compromise | Keeps earlier history verified | Relies on dates the attacker could forge |
| Treat all commits by the key as untrusted | Safest | Large review effort and many "unverified" badges |
| Review commits since the suspected exposure and re-sign tags | Focused and practical | Needs a reliable estimate of when exposure began |
| Rely on the hosting platform's push log | Platform records when it received commits | Not available as a signature, only as an audit record |
For tags, a practical fix is to re-sign important release tags with the new key after reviewing the tagged commit. Delete and recreate a tag only if your team agrees, because changing a published tag surprises everyone who already fetched it.
Choosing a policy
A reasonable default for a small team:
- GPG: one to two year expiry, a revocation certificate stored offline, and a calendar reminder a month before expiry.
- SSH: a new signing key every year or on device change, a shared allowed signers file kept in version control, and
valid-beforedates on retired keys. - Everyone: protect private keys with a passphrase or hardware token, and rehearse the rotation steps once before you need them.
Putting the allowed signers file under version control gives you a history of who trusted which key and when. Be careful about where it lives. A file that the same people can edit freely is only as trustworthy as the process that reviews changes to it.
Common mistakes
- Letting a GPG key expire with no reminder, then finding that commits fail to sign on the day of a release.
- Generating a key without a revocation certificate.
- Removing an old public key from the allowed signers file and breaking verification of history.
- Extending a GPG key locally but never re-uploading it to the hosting platform.
- Assuming a revoked key's signatures all become worthless. Revocation says to stop trusting the key, and you still have to decide about each past commit.
Exercise
You rotate your SSH signing key to a new one. A teammate then reports that git log --show-signature shows your commits from last year as unverified. What is the most likely cause, and how should you have retired the old key?
Show answer
The old public key was removed from the allowed signers file, so Git can no longer match old signatures to a trusted key. Keep the old entry and add a valid-before date set to the switch date. This keeps old commits verifiable and stops the old key from being accepted for new commits.
Exercise
Why is a GPG revocation certificate best generated at key creation time rather than when you need it?
Show answer
A revocation needs the private key and its passphrase to be created. If the key is lost or the passphrase is forgotten, you can no longer produce a certificate. A certificate made in advance and stored separately lets you revoke the key even then.