blob: de37a9602eb948d0a57056c8e23385152cc7fb3d (
plain)
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
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}"
|