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 /bin/yubikey-git | |
| 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 'bin/yubikey-git')
| -rwxr-xr-x | bin/yubikey-git | 32 |
1 files changed, 32 insertions, 0 deletions
diff --git a/bin/yubikey-git b/bin/yubikey-git index 6e46c1f..5653acb 100755 --- a/bin/yubikey-git +++ b/bin/yubikey-git @@ -26,6 +26,12 @@ # ~/.config/ssh/enabled.d/yubikey-git.conf # a link to its config, which is what turns it # on: config/ssh/entry includes enabled.d/*.conf +# ~/.config/git/yubikey-git a link to config/git/yubikey-git: the +# pre-push guard for dot's clone +# ~/.config/git/config-yubikey-git +# a link to its config, which config/git/config +# includes: it turns the guard on for a clone +# of git@git.soarez.net:sz/dot.git only # # On macOS it also needs Homebrew's OpenSSH, and installs it if Homebrew is # there: Apple's ssh cannot talk to a security key. git runs whichever ssh is @@ -42,6 +48,11 @@ keys=(id_ed25519_sk_git_main_nfc id_ed25519_sk_git_backup_nfc id_ed25519_sk_git) cfg="${HOME}/.config/ssh" dir_link="${cfg}/${name}" conf_link="${cfg}/enabled.d/${name}.conf" +# git's half: the pre-push guard for dot's clone (config/git/yubikey-git), and +# `git sz-push`, which signs master's newest commit with the YubiKey. +gcfg="${HOME}/.config/git" +git_dir_link="${gcfg}/${name}" +git_conf_link="${gcfg}/config-${name}" die() { >&2 echo "${name}: $*"; exit 1; } @@ -58,6 +69,7 @@ resolve_repo() { } src_dir="$(resolve_repo)/config/ssh/${name}" [[ -f "${src_dir}/config" ]] || die "no ${src_dir}/config -- is this the dotfiles checkout?" +git_src_dir="$(resolve_repo)/config/git/${name}" # A link we made points at exactly this target; anything else there is not ours. ours() { [[ -L "$1" && "$(readlink "$1")" == "$2" ]]; } @@ -106,6 +118,22 @@ enable() { fi ln -sfn "${dir_link}/config" "${conf_link}" + # Where a private layer is installed, its own hooks check dot's clones, and + # this one's hooksPath would replace them. + if [[ -e "${gcfg}/config-fleet" ]]; then + echo "${name}: a private layer's git config is here (${gcfg}/config-fleet); its hooks check dot, so no git guard" + else + mkdir -p "${gcfg}" + if [[ -e "${git_dir_link}" || -L "${git_dir_link}" ]] && ! ours "${git_dir_link}" "${git_src_dir}"; then + die "${git_dir_link} exists and is not this repo's; move it aside first" + fi + ln -sfn "${git_src_dir}" "${git_dir_link}" + if [[ -e "${git_conf_link}" || -L "${git_conf_link}" ]] && ! ours "${git_conf_link}" "${git_dir_link}/config"; then + die "${git_conf_link} exists and is not this repo's; move it aside first" + fi + ln -sfn "${git_dir_link}/config" "${git_conf_link}" + fi + # Fail now, not at the first push: a config ssh cannot parse breaks every ssh. if ! ssh -G git.soarez.net 2>&1 | grep -qix "identityfile ~/.ssh/id_ed25519_sk_git"; then ssh -G git.soarez.net > /dev/null || true @@ -115,12 +143,15 @@ enable() { echo "${name}: enabled. With one of the YubiKeys plugged in:" echo " git clone git@git.soarez.net:sz/<name>.git" + echo "and, in dot's clone, push master with: git sz-push" } disable() { local k key ours "${conf_link}" "${dir_link}/config" && rm "${conf_link}" ours "${dir_link}" "${src_dir}" && rm "${dir_link}" + ours "${git_conf_link}" "${git_dir_link}/config" && rm "${git_conf_link}" + ours "${git_dir_link}" "${git_src_dir}" && rm "${git_dir_link}" for k in "${keys[@]}"; do key="${HOME}/.ssh/${k}" if [[ -f "${key}" ]] && cmp -s "${key}" "${src_dir}/${k}"; then @@ -134,6 +165,7 @@ status() { local on=y k key if ours "${conf_link}" "${dir_link}/config"; then echo "ssh config: enabled (${conf_link})"; else echo "ssh config: not enabled"; on=""; fi if ours "${dir_link}" "${src_dir}"; then echo "config dir: ${dir_link}"; else echo "config dir: missing"; on=""; fi + if ours "${git_conf_link}" "${git_dir_link}/config" && ours "${git_dir_link}" "${git_src_dir}"; then echo "git guard: ${git_conf_link}"; else echo "git guard: not enabled"; on=""; fi for k in "${keys[@]}"; do key="${HOME}/.ssh/${k}" if [[ -f "${key}" ]] && cmp -s "${key}" "${src_dir}/${k}"; then echo "key handle: ${key}"; else echo "key handle: ${k} missing"; on=""; fi |
