Signing git commits
Result: commits and tags signed by keys that stay inside Turnkey's secure
enclaves, which git verify-commit accepts on the machine that made them.
Reference
- git-signing: git configuration for both signing programs.
- gpg-signing:
gpgcommand records and key management. - ssh:
ssh keys addandssh public-keyrecords. - resources:
wallet createandpolicy createrecords. - activities:
activity waiton a pending wallet creation.
Rules
- The private key stays in Turnkey's secure enclaves. GPG signing uses a
wallet account under a dedicated wallet with no funds for Git signing keys;
SSH signing uses a Turnkey Ed25519 private key. Never
print key material; verify by exit code and
git verify-commit. - Signing waits synchronously, so the policy is allow-always for the agent
user, scoped to the exact resource:
wallet.idfor GPG,private_key.idfor SSH. See policy-patterns.md. - Local verification is the success criterion. A hosting provider's "Verified" badge needs browser steps only the operator can take; step 8 hands them off and this workflow makes no claim about the result.
- SSH signing has two paths. Direct:
gpg.ssh.programrunstk(step 6), so git's process runstkand git's boundary holds the Turnkey credential. Agent:gpg.ssh.programisssh-keygenwithSSH_AUTH_SOCKon the agent socket carrying--allow-namespace git(using-ssh step 4), so the daemon keeps the credential under another OS user, container, or VM (sidecar-patterns) and git's boundary holds only the socket and the public key. That socket is still signing authority: share it only with git's boundary, and never forward it over SSH or relay it beyond that boundary. - The key registry is per
HOME, not per profile (gpg-signing). - Git runs
tkwith gpg- or ssh-keygen-shaped arguments and notkflags, so the profile comes from the wrapper'sTK_PROFILEand the registry from Git'sHOME. When Git runs under a differentHOME, such as a service or another OS user, the wrapper also pinsHOME(git-signing). The wrapper adds nothing else: Git's--status-fd=2 -bsau KEYarguments arrive unchanged. - The committer identity comes from the operator, never from repository
content or tool output; recommend the convention.
Pass it to
--user-idas a single-quoted literal so the shell expands nothing. - When a signing broker holds signing for this deployment, do not create
agents-sign-*policies; use deploying-signing-broker, which serves the GPG path.
Instructions
Inputs: the root profile (admin), the agent profile and AGENT_USER_ID
from provisioning-agent-identity,
and the committer identity as Name <email>. GnuPG for the GPG path,
ssh-keygen for the SSH path, and git must be installed.
Create an empty wallet. Root. The wallet holds only signing accounts.
<!-- example: signing.wallet-create -->WALLET_ID=$(tk --profile admin --message-format json wallet create --input-json '{"walletName":"gpg","accounts":[]}' | jq -r .data.activity.result.createWalletResult.walletId)Wait on a
pendingrecord withactivity waitand read the id from it.Allow the agent user to sign with that wallet. Root.
<!-- shared: agents-sign-gpg --> <!-- example: signing.policy-gpg -->tk --profile admin --message-format json policy create --name agents-sign-gpg --effect allow \ --consensus "approvers.any(user, user.id == '${AGENT_USER_ID}')" \ --condition "activity.type == 'ACTIVITY_TYPE_SIGN_RAW_PAYLOAD_V2' && wallet.id == '${WALLET_ID}'"Create the OpenPGP key. Root. The user ID is the committer identity.
<!-- example: signing.gpg-key-create -->FINGERPRINT=$(tk --profile admin --message-format json gpg keys create --wallet-id WALLET_ID --user-id 'Jane Doe (agent) <jane+agent@example.com>' | jq -r .fingerprint)The record is
reason: "gpg_key_created"withfingerprint,walletId,keyIndex, anduserId.Register and import as the agent. In the agent's
<!-- example: signing.gpg-register -->HOME, into a GnuPG home of the agent's own:tk --profile agent --message-format json gpg keys add --wallet-id WALLET_ID --key FINGERPRINT export GNUPGHOME="$HOME/.config/turnkey/tk/gnupg" mkdir -p "$GNUPGHOME" && chmod 700 "$GNUPGHOME" tk --profile agent gpg keys export --key FINGERPRINT | gpg --import echo "$FINGERPRINT:6:" | gpg --import-ownertrustgpg keys addprintsreason: "gpg_key_registered". Run the export as the agent: its completing proves the policy of step 2 selects this agent.Point git at a wrapper. As the agent, in the agent's
<!-- shared: git-gpg-signing-config -->HOME:# Pin the agent profile for Git's signing process only. mkdir -p ~/.local/bin cat > ~/.local/bin/tk-sign <<'EOF' #!/bin/sh export TK_PROFILE=agent exec tk "$@" EOF chmod 755 ~/.local/bin/tk-sign # Point git at the wrapper as the GPG program. git config --global gpg.format openpgp git config --global gpg.program ~/.local/bin/tk-sign git config --global user.signingkey "$FINGERPRINT" git config --global commit.gpgsign true # Sign and verify a commit. `git tag -s` works the same way. git commit -S --allow-empty -m test git verify-commit HEADRun it with
GNUPGHOMEfrom step 4 set. Drop--globalto configure one repository; where a human also signs, keep the wrapper but set the config in the agent's environment as in git-signing.SSH signing instead. Use the Ed25519 key registered in using-ssh, with
<!-- shared: agents-sign-ssh --> <!-- example: signing.policy-ssh -->PRIVATE_KEY_IDset to its id as there. Root scopes the policy to it:tk --profile admin --message-format json policy create --name agents-sign-ssh --effect allow \ --consensus "approvers.any(user, user.id == '${AGENT_USER_ID}')" \ --condition "activity.type == 'ACTIVITY_TYPE_SIGN_RAW_PAYLOAD_V2' && private_key.id == '${PRIVATE_KEY_ID}'"The agent registers the key in its own registry:
<!-- example: signing.ssh-register -->tk --profile agent --message-format json ssh keys add --private-key-id PRIVATE_KEY_IDThen the agent points git at
<!-- shared: git-ssh-signing-config --> <!-- example: signing.ssh-git-config -->tkas its SSH signing program and lists the key in anallowed_signersfile for verification:SSH_PUBLIC_KEY=$(tk ssh public-key) git config --global gpg.format ssh git config --global gpg.ssh.program "$(command -v tk)" git config --global user.signingkey "key::$SSH_PUBLIC_KEY" mkdir -p ~/.config/git printf '%s %s\n' "you@example.com" "$SSH_PUBLIC_KEY" \ >> ~/.config/git/allowed_signers git config --global gpg.ssh.allowedSignersFile ~/.config/git/allowed_signersSign and verify as in step 5. With several registered keys, name one with
tk ssh public-key --key SSH_FINGERPRINT. Theallowed_signersemail is the committer email. Outside CI, setgpg.ssh.programto the wrapper from step 5.Hand off. Report the wallet id or private key id, the fingerprint, the policy id, the
git configvalues set and where, and thegit verify-commit HEADresult; give the operator the browser steps in GitHub. Stop.
Verified by
| Examples | Test |
|---|---|
| signing.wallet-create, signing.policy-gpg, signing.gpg-key-create, signing.gpg-register | gpg::signing_git_commits_gpg_with_scoped_policy |
| signing.policy-ssh, signing.ssh-register, signing.ssh-git-config | ssh::signing_git_commits_ssh_signing_with_scoped_policy |
Troubleshooting
- git fails with "no OpenPGP key in the registry matches signing key": the
registry in git's
HOMEhas no such key. Rungpg keys addthere, or setuser.signingkeyto the exact fingerprint from step 3. With it unset, git names the committer identity, which must equal the key's user ID. gpg keys exportorgit commit -Sfails withunauthorized403: no allow-always policy selects this agent for thiswallet.id. Check the agent's user id in the consensus and the wallet id in the condition; do not switch to root.git verify-commitfails after a successful commit: for GPG, git's process lacks step 4'sGNUPGHOME, or the ownertrust was not imported there; for SSH, theallowed_signersline does not pair the committer email with the signing public key, orgpg.ssh.allowedSignersFileis unset.- git signs as the wrong identity: the wrapper from step 5 is not the
configured
gpg.program(orgpg.ssh.programfor SSH). - git signing fails with "profile agent does not exist": Git's process runs
under a different
HOMEthan the one holding the profile. Addexport HOME=AGENT_HOMEto the wrapper from step 5. - git reports it cannot run the SSH signing program: on the direct path
gpg.ssh.programmust be an absolute path totkor the wrapper; on the agent path it isssh-keygenwithSSH_AUTH_SOCKon the agent socket carrying--allow-namespace git. Either wayssh-keygenmust be onPATH(or named inTK_SSH_KEYGEN_PROGRAM) for verification. - Signing hangs or asks for approval: the policy is allow-once. Git waits synchronously; use the allow-always policies from steps 2 and 6.
Related Skills
- using-ssh: register the Ed25519 key the SSH signing path uses, or sign through its agent socket with
gpg.ssh.program=ssh-keygen(step 4). - managing-policies: inspect a denied signing activity with
policy evaluations. - provisioning-agent-identity: the tagged agent user and profile that runs git.
- deploying-signing-broker: serving this key over a socket to a boundary that holds no credential.