diff options
| author | Igor Soarez <igor@soarez.org> | 2026-11-17 10:27:22 +0000 |
|---|---|---|
| committer | Igor Soarez <igor@soarez.org> | 2026-11-17 10:27:22 +0000 |
| commit | 810877403e006bf8d145ed2cf236f0b3f1afc8d4 (patch) | |
| tree | 9889cee96ba43c1cf845eceb31cbdd2100a390d5 /config/git/yubikey-git/hooks | |
| parent | 75aa62d5920f4adf717ae780d7032c105cceb899 (diff) | |
git sz-push: sign master's newest commit with a YubiKey, and push it
One touch to sign, one to push, for a machine that pushes through
git.soarez.net with a YubiKey. yubikey-git enable also turns on a pre-push
guard for dot's clone, which stops a push to master that no YubiKey signed.
Diffstat (limited to 'config/git/yubikey-git/hooks')
| -rwxr-xr-x | config/git/yubikey-git/hooks/pre-push | 26 |
1 files changed, 26 insertions, 0 deletions
diff --git a/config/git/yubikey-git/hooks/pre-push b/config/git/yubikey-git/hooks/pre-push new file mode 100755 index 0000000..de37a96 --- /dev/null +++ b/config/git/yubikey-git/hooks/pre-push @@ -0,0 +1,26 @@ +#!/bin/bash +# Stops a push to master whose newest commit is not signed by one of the +# YubiKeys, before it leaves this machine: the git host checks the same and +# refuses it, as does every host that fetches it. `git sz-push` signs it, with +# one touch, and pushes. Not a security boundary, only a shorter way to the +# same answer; it also catches an agent's plain `git push`. +set -uo pipefail + +here="$(cd "$(dirname "$0")" && pwd -P)" +pubs="${here}/../../../ssh/yubikey-git" +signers="$(mktemp)" +trap 'rm -f "${signers}"' EXIT +for p in "${pubs}"/*.pub; do + read -r t k c < "${p}" && echo "${c} namespaces=\"git\" ${t} ${k}" +done > "${signers}" + +status=0 +while read -r _local_ref local_sha remote_ref _remote_sha; do + [[ "${remote_ref}" == refs/heads/master && ! "${local_sha}" =~ ^0+$ ]] || continue + if [[ "$(git -c gpg.format=ssh -c gpg.ssh.allowedSignersFile="${signers}" log -1 --format=%G? "${local_sha}" 2>/dev/null)" != G ]]; then + >&2 echo "pre-push: master's newest commit, ${local_sha:0:12}, is not signed by a YubiKey, so the git host would refuse it." + >&2 echo "pre-push: push it with: git sz-push" + status=1 + fi +done +exit "${status}" |
