# scripts/release.sh: a release only from a tag the pinned signer signed. # Real git and SSH-signed tags, in a throwaway repo with keys made for the # test (repo.sh), and a goreleaser that writes a small dist/. # The system's commands, not the stubs (ssh-keygen's): git signs with # ssh-keygen. [!exec:git] skip env GIT_CONFIG_NOSYSTEM=1 env PATH=$WORK/bin:/usr/bin:/bin chmod 755 bin/goreleaser exec bash repo.sh # An unsigned tag: refused. exec git -C repo tag -a v1.2.3 -m v1.2.3 ! exec repo/scripts/release.sh stderr '^release: tag v1.2.3 isn''t signed by a key git trusts' # Signed, but no pin: refused. exec bash tag.sh other ! exec repo/scripts/release.sh stderr '^release: no packaging/release-signer' # Signed by another key git trusts: refused. exec bash pin.sh good ! exec repo/scripts/release.sh stderr '^release: tag v1.2.3 is signed by SHA256:\S+, not a key in packaging/release-signer$' # Signed by the pinned key: past the check (it stops at the missing # minisign key). exec bash tag.sh good ! exec repo/scripts/release.sh ! stderr release-signer stderr '^release: no packaging/minisign.pub in v1.2.3' ! exists log # The pin is this checkout's, not the tagged commit's: the tagged commit # pins the other key, this checkout the good one. exec bash pin.sh other exec git -C repo add -A exec git -C repo commit -qm pin exec bash tag.sh other exec bash pin.sh good ! exec repo/scripts/release.sh stderr 'not a key in packaging/release-signer$' ! exists log # The release keys a tag's devvm and install.sh check releases with: # none, as until the real keys are made, with install.sh's lines empty, # or all three, each a different key, not the old release key, none of # them marked PLACEHOLDER, and each the same as install.sh's line. # Anything else is refused before anything is built, by --check and # --tag too, though a snapshot, a test build, may have a placeholder. chmod 755 bin/minisign exec bash -c 'printf ''untrusted comment: test\nRW%054d\n'' 7 | tr 0-9 A-J > repo/packaging/minisign.pub && touch key' env DEVVM_MINISIGN_KEY=$WORK/key exec bash keys.sh marked ! exec repo/scripts/release.sh stderr '^release: v1.2.3''s packaging/keys/release-cosign.pub is a placeholder key: make the real release keys first \(docs/content/docs/contributing/github-setup.md, step 1\)$' ! exec repo/scripts/release.sh --check stderr 'release-cosign.pub is a placeholder key' ! exec repo/scripts/release.sh --tag v1.2.3 stderr 'release-cosign.pub is a placeholder key' ! exec repo/scripts/release.sh --head ! stderr 'placeholder' exec bash keys.sh nokeyline ! exec repo/scripts/release.sh stderr '^release: v1.2.3''s install.sh has release_ci_key=RW\S+, but packaging/keys has no release keys: add them all, or empty its line$' ! exec repo/scripts/release.sh --check stderr 'but packaging/keys has no release keys' exec bash keys.sh old ! exec repo/scripts/release.sh stderr '^release: v1.2.3''s packaging/keys/release-recovery.pub is the old release key, packaging/minisign.pub''s' exec bash keys.sh partial ! exec repo/scripts/release.sh stderr '^release: v1.2.3 has 2 of the 3 release keys in packaging/keys, which a devvm can''t upgrade with: add release-recovery.pub \(see docs/content/docs/contributing/maintaining.md\)$' exec bash keys.sh same ! exec repo/scripts/release.sh stderr '^release: v1.2.3''s packaging/keys/release-recovery.pub is another role''s key' exec bash keys.sh notakey ! exec repo/scripts/release.sh stderr '^release: v1.2.3''s packaging/keys/release-cosign.pub holds no minisign public key' exec bash keys.sh differs ! exec repo/scripts/release.sh stderr '^release: v1.2.3''s install.sh has release_cosign_key=\S*, not packaging/keys/release-cosign.pub''s key$' ! exists log # Three good keys pass, and so do none, with install.sh's lines empty or # not there; a tag without install.sh is refused before anything is built. exec bash keys.sh good ! exec repo/scripts/release.sh ! stderr 'keys' exec bash keys.sh none ! exec repo/scripts/release.sh ! stderr 'keys' exec bash keys.sh nolines ! exec repo/scripts/release.sh ! stderr 'keys' exec bash -c 'git -C repo rm -q install.sh && git -C repo commit -qm no-install' exec bash tag.sh good ! exec repo/scripts/release.sh stderr '^release: no install.sh in v1.2.3$' ! exists log -- keys.sh -- # keys.sh MODE: the tag v1.2.3, signed with the good key, on a commit with # release keys in packaging/keys and install.sh's lines: good (three # real-looking keys), marked (a key marked PLACEHOLDER), partial (two # keys), same (one key twice), old (the old release key as one), notakey # (a file that holds none), differs (install.sh's line another key), none # (no keys, and install.sh's lines empty), nolines (no keys, and no lines), # nokeyline (no keys, but install.sh's lines have them). set -eu k() { printf 'RW%054d' "$1" | tr 0-9 A-J; } ci=$(k 1) cosign=$(k 2) recovery=$(k 3) comment="release key" icosign= rm -rf repo/packaging/keys mkdir -p repo/packaging/keys case $1 in none | nolines | nokeyline) ;; *) [[ $1 != same ]] || recovery=$ci [[ $1 != old ]] || recovery=$(sed -n 2p repo/packaging/minisign.pub) for r in ci cosign recovery; do [[ $1 != partial || $r != recovery ]] || continue c=$comment [[ $1 != marked || $r != cosign ]] || c="PLACEHOLDER $comment" v=$(eval echo "\$$r") [[ $1 != notakey || $r != cosign ]] || v=nope printf 'untrusted comment: %s\n%s\n' "$c" "$v" > "repo/packaging/keys/release-$r.pub" done ;; esac [[ $1 != differs ]] || icosign=$(k 9) [[ $1 != none ]] || ci="" cosign="" recovery="" { printf '#!/bin/sh\nrelease_version=""\nminisign_key=""\n' [[ $1 == nolines ]] || printf 'release_ci_key=%s\nrelease_cosign_key=%s\nrelease_recovery_key=%s\n' "$ci" "${icosign:-$cosign}" "$recovery"; } > repo/install.sh git -C repo add -A git -C repo commit -qm "keys $1" bash tag.sh good -- repo.sh -- # A repo with release.sh, the formula, an install.sh to fill in and # VERSION 1.2.3, and two SSH keys git trusts (good, other). set -eu mkdir -p repo/scripts repo/packaging/homebrew keys cp "$DEVVM_REPO/scripts/release.sh" repo/scripts/ cp "$DEVVM_REPO/packaging/homebrew/devvm.rb" repo/packaging/homebrew/ echo 1.2.3 > repo/VERSION printf '#!/bin/sh\nrelease_version=""\nminisign_key=""\n' > repo/install.sh for n in good other; do ssh-keygen -q -t ed25519 -N '' -C "$n" -f "keys/$n"; done { printf 'e@e %s\n' "$(cat keys/good.pub)"; printf 'e@e %s\n' "$(cat keys/other.pub)"; } > keys/allowed git -C repo init -q git -C repo config user.email e@e git -C repo config user.name e git -C repo config gpg.format ssh git -C repo config gpg.ssh.allowedSignersFile "$PWD/keys/allowed" git -C repo add -A git -C repo commit -qm r -- tag.sh -- # Tag v1.2.3 (again), signed with key $1. set -eu git -C repo tag -d v1.2.3 >/dev/null 2>&1 || true git -C repo -c user.signingkey="$PWD/keys/$1" tag -s v1.2.3 -m v1.2.3 -- pin.sh -- # Pin key $1 in the checkout's packaging/release-signer. set -eu printf '# the release signer\n%s\n' "$(ssh-keygen -lf "keys/$1.pub" | awk '{ print $2 }')" > repo/packaging/release-signer -- bin/minisign -- #!/bin/sh # Never reached: the checks stop first. exit 1 -- bin/goreleaser -- #!/bin/bash # Logs its call and writes a dist/ like GoReleaser's: the source tarball, # SHA256SUMS and this host's binary, which prints $GR_VERSION, else # $DEVVM_VERSION. set -eu echo "$* DEVVM_VERSION=$DEVVM_VERSION GORELEASER_CURRENT_TAG=${GORELEASER_CURRENT_TAG:-}" >> "$WORK/log" os=$(uname -s | tr '[:upper:]' '[:lower:]') case $(uname -m) in arm64 | aarch64) arch=arm64 ;; *) arch=amd64 ;; esac mkdir -p "dist/devvm_${os}_$arch" git archive --prefix="devvm-$DEVVM_VERSION/" HEAD | gzip -n > "dist/devvm-$DEVVM_VERSION.tar.gz" (cd dist && { sha256sum "devvm-$DEVVM_VERSION.tar.gz" 2>/dev/null || shasum -a 256 "devvm-$DEVVM_VERSION.tar.gz"; } > SHA256SUMS) printf '#!/bin/sh\necho %s\n' "${GR_VERSION:-$DEVVM_VERSION}" > "dist/devvm_${os}_$arch/devvm" chmod 755 "dist/devvm_${os}_$arch/devvm"