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 | |
| parent | 75aa62d5920f4adf717ae780d7032c105cceb899 (diff) | |
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')
| -rw-r--r-- | config/git/config | 4 | ||||
| -rw-r--r-- | config/git/yubikey-git/config | 7 | ||||
| -rw-r--r-- | config/git/yubikey-git/hooks-config | 2 | ||||
| -rwxr-xr-x | config/git/yubikey-git/hooks/pre-push | 26 |
4 files changed, 39 insertions, 0 deletions
diff --git a/config/git/config b/config/git/config index 9225b2a..10594b1 100644 --- a/config/git/config +++ b/config/git/config @@ -6,6 +6,10 @@ ; the sections below it. git skips an include whose file is missing. [include] path = ~/.config/git/config-fleet +; Linked by `yubikey-git enable` (bin/yubikey-git): the pre-push guard for dot's +; clone on a machine that pushes through git.soarez.net with a YubiKey. +[include] + path = ~/.config/git/config-yubikey-git [include] path = ~/.config/git/config-local [core] diff --git a/config/git/yubikey-git/config b/config/git/yubikey-git/config new file mode 100644 index 0000000..d530ad7 --- /dev/null +++ b/config/git/yubikey-git/config @@ -0,0 +1,7 @@ +; Included from config/git/config once `yubikey-git enable` links it to +; ~/.config/git/config-yubikey-git. dot's clone through git.soarez.net, and +; nothing else, gets the pre-push guard beside this file: a push to master +; whose newest commit no YubiKey signed would be refused by the git host, so it +; is stopped here first, with the way through (bin/git-sz-push). +[includeIf "hasconfig:remote.*.url:git@git.soarez.net:sz/dot.git"] + path = ~/.config/git/yubikey-git/hooks-config diff --git a/config/git/yubikey-git/hooks-config b/config/git/yubikey-git/hooks-config new file mode 100644 index 0000000..5c46f67 --- /dev/null +++ b/config/git/yubikey-git/hooks-config @@ -0,0 +1,2 @@ +[core] + hooksPath = ~/.config/git/yubikey-git/hooks 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}" |
