Harden gitconfig with portable SSH commit + tag signing#16
Open
akan72 wants to merge 2 commits into
Open
Conversation
- Enable SSH-based signing (gpg.format = ssh) using the existing ~/.ssh/id_ed25519 key — no GPG keyring needed, works identically on remote hosts (e.g. EC2) - Pin user.signingkey to ~/.ssh/id_ed25519.pub so the key is explicit, not ambient - Set commit.gpgsign = true and tag.gpgsign = true so commits and tags are signed by default and show GitHub's Verified badge Note: upload ~/.ssh/id_ed25519.pub to GitHub as a *signing* key for verification.
Drop the hardcoded `signingkey = ~/.ssh/id_ed25519.pub` in favor of `gpg.ssh.defaultKeyCommand = sh -c 'printf "key::%s\n" "$(ssh-add -L | head -n1)"'` so the same gitconfig works on any machine without per-host edits. Why: - Hardcoded path breaks on machines without that exact file (e.g. the current laptop has only ~/.ssh/id_rsa.pub, so the previous form would silently fail at commit time). - ssh-add -L returns whatever the active ssh-agent exposes — including hardware-resident keys (YubiKey ed25519-sk, 1Password's SSH agent) where no .pub file exists on disk. - git's source (gpg-interface.c) explicitly searches defaultKeyCommand output for the literal "key::" prefix; the printf wrapper adds it (many tutorials show bare `ssh-add -L | head -n1`, which doesn't actually work in modern git). Operational requirement: whichever key ssh-add -L returns on a given machine must be uploaded to GitHub as a *Signing* key (separate from the Authentication key registration). Confirm with: ssh-add -L | head -n1
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
Add this suggestion to a batch that can be applied as a single commit.This suggestion is invalid because no changes were made to the code.Suggestions cannot be applied while the pull request is closed.Suggestions cannot be applied while viewing a subset of changes.Only one suggestion per line can be applied in a batch.Add this suggestion to a batch that can be applied as a single commit.Applying suggestions on deleted lines is not supported.You must change the existing code in this line in order to create a valid suggestion.Outdated suggestions cannot be applied.This suggestion has been applied or marked resolved.Suggestions cannot be applied from pending reviews.Suggestions cannot be applied on multi-line comments.Suggestions cannot be applied while the pull request is queued to merge.Suggestion cannot be applied right now. Please check back later.
Summary
Harden
gitconfigwith SSH-based commit + tag signing, resolved at sign-time so the same config works across machines without per-host edits.gpg.format = ssh— sign with SSH keys instead of GPG (no keyring to manage)gpg.ssh.defaultKeyCommand— pulls the first key from whicheverssh-agentis exposed on the current machine, rather than hardcoding~/.ssh/id_ed25519.pubuser.signingkeyleft unset (resolved bydefaultKeyCommand)commit.gpgsign = trueandtag.gpgsign = true— signed by default; GitHub shows the Verified badgeWhy dynamic resolution (vs hardcoded path)
A previous version of this PR set
user.signingkey = ~/.ssh/id_ed25519.pub. That path doesn't exist on every machine (e.g. the current laptop only has~/.ssh/id_rsa.pub), so signing would silently fail at commit time.defaultKeyCommandresolves the key at sign-time by reading fromssh-agent, which means:id_rsa,id_ed25519,id_ed25519_sk, …) — no per-host override file.ed25519-sk, 1Password's SSH agent) where there may be no.pubfile on disk at all.gitconfigchange — just changeSSH_AUTH_SOCK.The
key::prefix is required: git's source (gpg-interface.c) explicitly searches the command output for that literal substring. Many tutorials show baressh-add -L | head -n1, which actually does not work in modern git. Theprintfwrapper adds the prefix.Action required after merge + re-assimilate
ssh-add -L | head -n1returns is the one you want for signing.ForwardAgent).Why & alternatives
commit.gpgsign = truetag.gpgsign = truegpg.format = sshdefaultKeyCommand = ssh-add -L | head -n1user.signingkey = ~/.ssh/<file>.pub— simpler but fragile across machines. (b)[includeIf]per-host override — more moving parts.