Sub topic 1
What a signature proves, and what it does not
Git records an author name and email in every commit. Nothing checks them. A signature adds a cryptographic claim to a commit or tag. This chapter explains exactly what that claim is, so you can judge how much trust a "valid signature" deserves.
Prerequisites
This chapter assumes you can:
- Use basic Git: commit, tag, log, and
git config. - Work in a command-line shell.
- Describe public and private keys in general terms. A private key makes signatures, and the matching public key checks them.
You don't need a signing key yet. Later chapters create one.
The problem: identity in Git is self-declared
Git reads the author name and email from configuration, or from environment variables. It does not authenticate either one. You can try this in a scratch repository:
git init demo && cd demo
git -c user.name="Linus Torvalds" -c user.email="[email protected]" \
commit --allow-empty -m "Looks official"
git log -1 --format='%an <%ae>'The log prints Linus Torvalds <[email protected]>. Git accepted the identity without question. A malicious contributor, a compromised script, or a careless typo can all produce commits with someone else's name on them.
Pushing to a server does not fix this. The server authenticates the person who pushes. It does not check the author field of each commit in the push. A maintainer can push a commit authored by someone else, and that is normal. Commits from a patch series work this way.
What a signature adds
When you sign a commit, Git builds the commit object and sends its content to a signing program. The program returns a signature, and Git stores it in the commit as a gpgsig header. Here is a signed commit as git cat-file -p HEAD shows it, with the long signature body shortened:
tree 9c1f0e7d2b6a4c8e5f3a1b2c3d4e5f60718293a4
parent 5b2e8d1a7c9f4036e1d2b3a4c5d6e7f801928374
author Alice <[email protected]> 1767225600 +0000
committer Alice <[email protected]> 1767225600 +0000
gpgsig -----BEGIN PGP SIGNATURE-----
(signature data)
-----END PGP SIGNATURE-----
Add release notesThe signature covers every other line of the object. That includes the tree hash, the parent hashes, the author and committer lines with their timestamps, and the message. If anyone changes one byte of any of those, the signature no longer matches.
A valid signature establishes these facts:
- Origin of the signature. Someone who held the private key produced this signature.
- Integrity. The commit has not changed since it was signed. The content you see is the content that was signed.
- Content of the whole snapshot. The signed commit contains the tree hash, so the signature commits to every file in that snapshot.
- History linkage. The commit contains its parent hashes. Changing any earlier commit changes its hash, which changes every descendant. A signature on the tip therefore protects the history behind it, although earlier unsigned commits are still unsigned as claims about authorship.
What a valid signature does not prove
A "Good signature" message is narrower than it sounds. The following table lists claims people often assume and what the signature does about each.
| Claim people assume | Does the signature prove it? | Why not |
|---|---|---|
| The author line names the real author | No | The signer and the author field are independent. Alice can sign a commit that says `Bob` is the author. |
| The signer is the person you think | Only if you trust the key's binding | The signature proves a key was used. Something outside the signature must link the key to a person. |
| The code is correct or safe | No | A signer can sign buggy or malicious code, deliberately or not. |
| The commit was made at the stated time | No | The timestamps are fields the committer can set to any value. |
| The commit belongs on this branch | No | A signed commit can be applied to any branch or repository that contains its parents. |
| The private key is still under its owner's control | No | A stolen key makes valid signatures. Nothing in the signature shows the theft. |
| The signer had permission to change this repository | No | Permission is enforced by the server, not by the signature. |
The key must be tied to a person
A signature is only as meaningful as the link between the key and an identity. Each signing method links them differently:
- With GnuPG, you decide how much you trust a public key. You can check its fingerprint in person, or rely on certifications from other keys you trust. Chapter material on verification covers this.
- With SSH signing, Git checks the signature against an allowed signers file that you maintain. Each line lists an identity and a public key. The file is your statement of who you trust.
- On a hosting platform, the platform marks a commit as verified if the signing key is registered on the account that matches the committer email. You are trusting the platform's account system.
In every case, the verification step answers "was this signed by key K?" Deciding whether K belongs to Alice is a separate decision. If you skip it, a valid signature from an unknown key tells you almost nothing.
The following diagram shows the two questions separately.
Tags are signed separately
An annotated tag is its own object. It names a target commit, a tagger, a date, and a message. Signing a tag signs that object. The signature then covers the target commit hash, and through it the whole snapshot and history. A signed tag is the usual way to say "this exact state is release 1.0.0".
Two edge cases matter:
- Lightweight tags cannot be signed. A lightweight tag is only a reference to a commit and has no object of its own. Only annotated tags carry a signature.
- A signed tag does not sign the commits beneath it individually. It vouches for the hash of the target. Because hashes chain, the target hash does pin the history. But the signature on the tag says the tagger approved that state. It does not say each earlier author did.
Signing a commit versus signing a push
Git also supports signed pushes with git push --signed. The signature then covers a certificate that records which refs were updated and to what. This is different from signing a commit, and servers must be configured to accept it. Most workflows rely on signed commits and tags only, so this tutorial does the same.
Failure modes to keep in mind
Unsigned commits on top of signed ones. A signature on commit B says nothing about commit C that was added later. Check the commits you actually care about, or require signatures for every commit in a range.
Replay and re-use. The signature is bound to the commit content, not to a place. An attacker can take a genuine signed commit from your public repository and put it in a different repository or branch. The signature will still verify. If the context matters, a signed tag naming the release, or a policy on the server, has to supply it.
Rewrites drop signatures. Rebasing, cherry-picking, and amending create new commits with new hashes. The old signature does not carry over. Git signs the new commits only if you ask it to, or if commit.gpgsign is on. A later chapter covers this.
Merges made by a platform. When a hosting platform creates a merge or squash commit for you, it signs that commit with its own key. The result shows as verified, but the signer is the platform, not the original author.
Expired or revoked keys. A signature made while a key was valid can later fail or warn when the key expires or is revoked. Whether to keep trusting old signatures is a policy decision, and the key lifecycle chapter returns to it.
Weak local verification. Git prints a signature status only when you ask for it, for example with git log --show-signature. Fetching, merging, or checking out a commit does not verify anything by default. A signature that nobody checks protects nobody.
A practical way to think about it
Treat a signature as a tamper seal plus a name tag. The seal is strong: any change to the content breaks it. The name tag is only as good as your process for connecting keys to people. Use signatures to answer "did this come from a key I have decided to trust, and is it unchanged?" Use code review, access control, and release processes to answer everything else.
Exercises
Exercise
A teammate says, "Every commit in our repository shows Good signature, so we know each author wrote and reviewed their own code." Name two claims in that statement that a valid signature does not support.
Show answer
First, a valid signature shows a key signed the commit. It does not show the key's owner is the person in the author field, because author and signer are independent. Second, a signature says nothing about whether the code was written carefully or reviewed. Signers can sign flawed or malicious code. (Timestamps and branch placement are also unproven.)
Exercise
You run git tag v2.0 with no other options and then try to sign it. Why is there nothing to sign, and what kind of tag should you create instead?
Show answer
git tag v2.0 creates a lightweight tag, which is only a reference to a commit and has no object to attach a signature to. Create an annotated tag, for example with git tag -s v2.0 -m "Release 2.0", which creates a tag object and signs it.
Exercise
An attacker copies a genuine, signed commit from your public repository into a fork and applies it to a different branch. Will the signature still verify, and why?
Show answer
Yes. The signature covers the commit's own content (tree, parents, author, committer, message), not the branch or repository it lives in. As long as the commit object is unchanged, it verifies anywhere. Branch policy or a signed release tag must provide that context.