release: pin the release key instead of scanning the keyring
CI / test (push) Successful in 49s

`sign` fell back to "the first secret key in the keyring" whenever
REGENT_GPG_KEY was unset. On the release laptop that was an unrelated
key, so 0.9.0-0.9.2 were signed (tarball and tag) by it, and its
fingerprint was baked into the AUR recipe's `validpgpkeys`.

Pin the release key (RELEASE_KEY_FPR) and never scan the keyring. Fail
unless the key has a secret half and, without an explicit override,
unless it is the pin; log the uid before signing; assert the tag is
signed by that same key. The pin is Râu Cao <raucao@kosmos.org>, which
is on WKD and both keyservers, so makepkg can still fetch it.

Add build-aux/resign-release.sh to re-sign an already-published release
in place: the same tarball bytes (sha256 and every `sha256sums` stay
valid), the same commit re-tagged, and the signature, exported key and
PKGBUILD asset refreshed. It also regenerates the release's PKGBUILD
asset, because the published ones are stale: 0.9.0's is the initial
placeholder with `sha256sums=('SKIP' 'SKIP')` (no integrity check) and
0.9.1's is 0.9.0's recipe.

Also fix usage(), which printed only one line: sub() mutates $0, so the
second awk rule saw the stripped line and exited immediately.
This commit is contained in:
raucao committed 2026-12-01 14:33:09 +04:00
1 parent 3ac9b24d76
commit 5c8b7cc9b0
6 files changed
+282 -15

No files matched your search

+9 -1
View File
@@ -55,7 +55,15 @@ gpg --import regent-signing-key.asc
gpg --verify regent-<version>.tar.xz.asc regent-<version>.tar.xz
```
The same key fingerprint is pinned in the AUR package's `validpgpkeys`.
Releases are signed by this key:
```
Râu Cao <raucao@kosmos.org>
5306 FC8F 1361 E469 C2E4 CF56 3703 6C35 6E56 CC51
```
It is discoverable via WKD (`raucao@kosmos.org`) and on the usual keyservers,
and the same fingerprint is pinned in the AUR package's `validpgpkeys`.
## Repositories & Contributions
+15
View File
@@ -101,6 +101,11 @@ the UI is tested. `build-aux/deploy-dev.sh` runs on the build host,
sha256, and the signing fingerprint (`validpgpkeys`, with the `.asc` in
`source`), then pushes to `aur.archlinux.org`; the in-repo copy is updated in a
post-release commit, because the sha cannot exist before the tarball does.
The fingerprint is the **pinned** `RELEASE_KEY_FPR` in `release.sh`, not
whatever key `gpg` finds first — the old "first secret key in the keyring"
fallback signed 0.9.0–0.9.2 with an unrelated key and pinned its fingerprint
in the recipe. `sign` fails on any key but the pin unless `REGENT_GPG_KEY`
overrides it for a rotation.
`build-aux/regent-dev/` is the *working-tree* package the dev deploy's `--pkg`
builds, not an AUR one.
- **Every PKGBUILD sets `options=('!lto')`.** makepkg's default `lto` appends
@@ -110,6 +115,16 @@ the UI is tested. `build-aux/deploy-dev.sh` runs on the build host,
(`undefined symbol: rustsecp256k1_v0_10_0_…`) — the AUR build fails while a
plain `cargo`/`regent-deploy` build on the same machine links fine. `!lto`
only turns off makepkg's *C-flag* LTO; Rust's own `lto = true` stays.
- **`resign-release.sh <version>…` re-signs an already-published release** with
the pinned key, for the case where one went out under the wrong key. It
re-signs the *same* tarball bytes (the sha256 and every `sha256sums` stay
valid), re-tags the same commit, and re-uploads the signature, the exported
key and the release's PKGBUILD asset — the last is **regenerated**, not just
re-pointed, because 0.9.0's published recipe was the placeholder with
`sha256sums=('SKIP' 'SKIP')` and 0.9.1's was 0.9.0's. It also moves the AUR
recipe's `_fingerprint` if the recipe points at a re-signed version. It force-pushes
the tags, so Gitea's `v*` protection has to be relaxed first. Idempotent, and
`--no-push` previews without touching a remote.
- **Nostr is a mirror.** `.ngit/release.yaml` publishes the same tarball to
Blossom (`blossom.kosmos.org`) under NIP-82, signed by the fixed release
identity (one npub, forever). Gitea stays canonical, and a Nostr failure is not
+1 -1
View File
@@ -10,7 +10,7 @@ pkgname=regent
pkgver=0.9.2
pkgrel=1
_tag=0.9.2
_fingerprint=A180EE9789FA15E71B1C2F6BC4FC4AAA54ED62FF
_fingerprint=5306FC8F1361E469C2E4CF5637036C356E56CC51
pkgdesc="Remote signer for Nostr (NIP-46)"
arch=('x86_64')
url="https://gitea.kosmos.org/raucao/regent"
+38 -11
View File
@@ -29,7 +29,8 @@
#
# Environment:
# REGENT_SSH_SIGNING_KEY SSH public key for the release commit (prepare)
# REGENT_GPG_KEY GPG key id/fingerprint for signing (sign, publish)
# REGENT_GPG_KEY GPG key id/fingerprint for signing (sign, publish);
# overrides the pinned RELEASE_KEY_FPR for a rotation
# REGENT_BUILD_HOST ssh target to pull dist/ from (sign)
# REGENT_REPO_PATH repo path on the build host (default: ~/src/regent)
# REGENT_REMOTE git remote (default: origin)
@@ -43,12 +44,20 @@ log() { printf 'release: %s\n' "$*" >&2; }
warn() { printf 'release: warning: %s\n' "$*" >&2; }
die() { printf 'release: error: %s\n' "$*" >&2; exit 1; }
hdr() { printf '\n\033[1m== %s\033[0m\n' "$*" >&2; }
usage() { awk 'NR>1 && /^#/ {sub(/^# ?/,""); print} NR>1 && !/^#/ {exit}' "${BASH_SOURCE[0]}"; }
# One action per line: `sub()` mutates $0, so a second `!/^#/` pattern would see
# the stripped line and exit after the first line of the comment block.
usage() { awk 'NR>1 { if (/^#/) { sub(/^# ?/,""); print } else exit }' "${BASH_SOURCE[0]}"; }
ROOT=$(cd "$(dirname "${BASH_SOURCE[0]}")/.." && pwd)
cd "$ROOT"
APP_ID=org.kosmos.raucao.Regent
# The Regent release key — Râu Cao <raucao@kosmos.org>, published on WKD and on
# keyserver.ubuntu.com / keys.openpgp.org (makepkg fetches it from a keyserver
# for `validpgpkeys`). Pinned on purpose: `sign` must never pick a key by
# scanning the keyring, or an unrelated key signs a release and its fingerprint
# is baked into the AUR recipe. Rotate with REGENT_GPG_KEY (and update this).
RELEASE_KEY_FPR=5306FC8F1361E469C2E4CF5637036C356E56CC51
REMOTE=${REGENT_REMOTE:-origin}
NOSTR_REMOTE=${REGENT_NOSTR_REMOTE:-nostr}
AUR_REGENT=${REGENT_AUR_REGENT:-ssh://aur@aur.archlinux.org/regent.git}
@@ -157,14 +166,15 @@ probe_ssh_sign() {
}
resolve_gpg_key() {
local key=${REGENT_GPG_KEY:-}
if [ -z "$key" ]; then
# `|| true`: with pipefail an empty keyring would otherwise abort the script
# silently here, never reaching the message below.
key=$(gpg --batch --list-secret-keys --with-colons 2>/dev/null | awk -F: '/^sec:/ {print $5; exit}' || true)
fi
[ -n "$key" ] || die "no GPG key: set REGENT_GPG_KEY, or import one (gpg --import)"
printf '%s' "$key"
# The pinned key, or an explicit override for a rotation. Deliberately no
# keyring scan: "the first secret key" once signed a whole release series with
# an unrelated key, and its fingerprint went into the AUR `validpgpkeys`.
printf '%s' "${REGENT_GPG_KEY:-$RELEASE_KEY_FPR}"
}
gpg_uid() {
gpg --batch --list-keys --with-colons "$1" 2>/dev/null \
| awk -F: '/^uid:/ {print $10; exit}' || true
}
gpg_fingerprint() {
@@ -328,7 +338,17 @@ stage_sign() {
gpg_key=$(resolve_gpg_key)
fpr=$(gpg_fingerprint "$gpg_key")
[ -n "$fpr" ] || die "could not read the fingerprint of GPG key $gpg_key"
log "signing with GPG key $gpg_key ($fpr)"
# The private half must be present, or the first gpg --detach-sign fails after
# the tarball's previous signature has already been removed.
gpg --batch --list-secret-keys "$fpr" >/dev/null 2>&1 \
|| die "no secret key for $fpr — import it, or set REGENT_GPG_KEY"
# A key other than the pinned one is only ever a deliberate rotation.
if [ -z "${REGENT_GPG_KEY:-}" ] && [ "$fpr" != "$RELEASE_KEY_FPR" ]; then
die "resolved key $fpr is not the pinned release key $RELEASE_KEY_FPR"
elif [ -n "${REGENT_GPG_KEY:-}" ] && [ "$fpr" != "$RELEASE_KEY_FPR" ]; then
warn "REGENT_GPG_KEY overrides the pinned release key ($RELEASE_KEY_FPR) — rotating?"
fi
log "signing with $fpr ($(gpg_uid "$fpr"))"
hdr "signing the tarball"
rm -f "$DIST/regent-$version.tar.xz.asc" "$DIST/regent-signing-key.asc"
@@ -343,6 +363,13 @@ stage_sign() {
hdr "tagging"
git -c gpg.format=openpgp -c user.signingkey="$gpg_key" tag -s "$tag" -m "Regent $version"
git tag -v "$tag" >&2 || die "could not verify the tag just created"
# A tag signed by a different key than the tarball would be worse than no tag:
# the two are advertised as the same signer, and `publish` records one
# fingerprint for the AUR. --raw's VALIDSIG carries both the signing key and
# the primary, so matching the fingerprint anywhere in the line covers a
# signing subkey.
git verify-tag --raw "$tag" 2>&1 | grep '^\[GNUPG:\] VALIDSIG' | grep -q "$fpr" \
|| die "tag $tag is not signed by $fpr"
if [ "$push" = yes ]; then
hdr "pushing the tag"
git push "$REMOTE" "$tag"
+186
View File
@@ -0,0 +1,186 @@
#!/usr/bin/env bash
# Re-sign already-published releases with the pinned release key.
#
# One-off repair, kept as a script because doing it by hand three times is how
# the problem happened: releases 0.9.0-0.9.2 were signed (tarball and tag) by an
# unrelated key, because `release.sh sign` used to fall back to "the first secret
# key in the keyring". That fingerprint is baked into the AUR recipe and into
# every release's PKGBUILD asset. This re-signs the *same* tarball bytes (so the
# sha256 never changes and `sha256sums` stays valid) with the pinned key, re-tags
# the same commit, and refreshes the signature, the exported key and the
# release's PKGBUILD asset (regenerated, because the published ones for 0.9.0
# and 0.9.1 are also stale — see the note at the regeneration step).
#
# Runs on the machine that holds the pinned key. Idempotent: re-running just
# produces a fresh signature.
#
# build-aux/resign-release.sh 0.9.0 0.9.1 0.9.2
# build-aux/resign-release.sh --no-push 0.9.2 # preview, touch nothing
#
# Environment:
# REGENT_GITEA_URL release host (default https://gitea.kosmos.org/raucao/regent)
# REGENT_REMOTE git remote for the tags (default origin)
# REGENT_NOSTR_REMOTE Nostr git remote (default nostr; best-effort)
# REGENT_AUR_REGENT AUR clone URL (default ssh://aur@aur.archlinux.org/regent.git)
set -euo pipefail
log() { printf 'resign: %s\n' "$*" >&2; }
warn() { printf 'resign: warning: %s\n' "$*" >&2; }
die() { printf 'resign: error: %s\n' "$*" >&2; exit 1; }
hdr() { printf '\n\033[1m== %s\033[0m\n' "$*" >&2; }
usage() { awk 'NR>1 { if (/^#/) { sub(/^# ?/,""); print } else exit }' "${BASH_SOURCE[0]}"; }
ROOT=$(cd "$(dirname "${BASH_SOURCE[0]}")/.." && pwd)
cd "$ROOT"
GITEA=${REGENT_GITEA_URL:-https://gitea.kosmos.org/raucao/regent}
REMOTE=${REGENT_REMOTE:-origin}
NOSTR_REMOTE=${REGENT_NOSTR_REMOTE:-nostr}
AUR_REGENT=${REGENT_AUR_REGENT:-ssh://aur@aur.archlinux.org/regent.git}
# One source of truth for the key: the pin in release.sh.
FPR=$(sed -n 's/^RELEASE_KEY_FPR=//p' build-aux/release.sh)
[ -n "$FPR" ] || die "could not read RELEASE_KEY_FPR from build-aux/release.sh"
push=yes aur=yes versions=()
while [ $# -gt 0 ]; do
case "$1" in
--no-push) push=no ;;
--no-aur) aur=no ;;
-h|--help) usage; exit 0 ;;
-*) die "unknown option: $1 (try --help)" ;;
*) versions+=("$1") ;;
esac
shift
done
[ ${#versions[@]} -gt 0 ] || { usage >&2; exit 2; }
for v in "${versions[@]}"; do
[[ $v =~ ^[0-9]+\.[0-9]+\.[0-9]+$ ]] || die "version must look like 1.2.3 (got: $v)"
done
require_tools() { for t in "$@"; do command -v "$t" >/dev/null || die "$t not found"; done; }
require_tools git gpg curl sha256sum sed
[ "$push" = no ] || require_tools gt
[ "$aur" = no ] || [ "$push" = no ] || require_tools makepkg
# The private half must be here before anything is deleted or re-signed.
gpg --batch --list-secret-keys "$FPR" >/dev/null 2>&1 \
|| die "no secret key for $FPR — run this on the machine that holds the release key"
# One work directory for the whole run, cleaned on exit. Per-version subdirs
# keep a partial failure from mixing one release's files into another's.
WORK=$(mktemp -d)
trap 'rm -rf "$WORK"' EXIT
# Fetch a release asset. Asset names are fixed by release.sh's `publish`.
fetch_asset() {
local tag=$1 name=$2 dest=$3
curl -fsSL --retry 3 -o "$dest" "$GITEA/releases/download/$tag/$name" \
|| die "could not download $name from release $tag"
}
resign_one() {
local version=$1 tag="v$1" dir="$WORK/$1"
mkdir -p "$dir"
hdr "$version"
git rev-parse -q --verify "refs/tags/$tag" >/dev/null \
|| die "tag $tag is not in this clone (git fetch --tags $REMOTE first)"
local commit; commit=$(git rev-list -n1 "$tag")
log "tag $tag -> ${commit:0:10}"
hdr "$version: fetching the published artifacts"
fetch_asset "$tag" "regent-$version.tar.xz" "$dir/regent-$version.tar.xz"
fetch_asset "$tag" "regent-$version.tar.xz.sha256sum" "$dir/regent-$version.tar.xz.sha256sum"
( cd "$dir" && sha256sum -c "regent-$version.tar.xz.sha256sum" ) >&2
local sha; sha=$(cut -d' ' -f1 "$dir/regent-$version.tar.xz.sha256sum")
hdr "$version: re-signing the tarball"
gpg --batch --yes --armor --detach-sign --local-user "$FPR" "$dir/regent-$version.tar.xz"
gpg --batch --yes --armor --export "$FPR" > "$dir/regent-signing-key.asc"
gpg --batch --verify "$dir/regent-$version.tar.xz.asc" "$dir/regent-$version.tar.xz" >&2
# Rebuild the release's own PKGBUILD asset. It must verify the (now re-signed)
# tarball, and the published ones are stale besides: 0.9.0's is the initial
# placeholder with `sha256sums=('SKIP' 'SKIP')` (no integrity check at all),
# and 0.9.1's is 0.9.0's recipe. Both predate the AUR update that `publish`
# now does before it uploads. Use the current in-repo recipe — same shape,
# plus the `!lto` fix that 0.9.0/0.9.1 shipped without — and set this
# release's version, sha and signer.
hdr "$version: regenerating the PKGBUILD asset"
sed -e "s/^pkgver=.*/pkgver=$version/" \
-e "s/^_tag=.*/_tag=$version/" \
-e "s/^_fingerprint=.*/_fingerprint=$FPR/" \
-e "s/^sha256sums=.*/sha256sums=('$sha' 'SKIP')/" \
build-aux/aur/regent/PKGBUILD > "$dir/PKGBUILD"
grep -qx "pkgver=$version" "$dir/PKGBUILD" \
&& grep -qx "_tag=$version" "$dir/PKGBUILD" \
&& grep -qx "_fingerprint=$FPR" "$dir/PKGBUILD" \
&& grep -q "sha256sums=('$sha' 'SKIP')" "$dir/PKGBUILD" \
|| die "could not build a valid PKGBUILD asset for $version"
if command -v makepkg >/dev/null; then
( cd "$dir" && makepkg --printsrcinfo >/dev/null ) \
|| die "the regenerated PKGBUILD for $version does not parse"
fi
hdr "$version: re-tagging the same commit"
git tag -d "$tag" >/dev/null
git -c gpg.format=openpgp -c user.signingkey="$FPR" tag -s "$tag" "$commit" -m "Regent $version"
git tag -v "$tag" >&2 || die "could not verify the tag just created"
git verify-tag --raw "$tag" 2>&1 | grep '^\[GNUPG:\] VALIDSIG' | grep -q "$FPR" \
|| die "tag $tag is not signed by $FPR"
if [ "$push" = no ]; then
warn "$version: --no-push; tag re-created locally, assets not uploaded"
return 0
fi
hdr "$version: force-pushing the tag"
if ! git push --force "$REMOTE" "$tag"; then
die "could not force-push $tag — Gitea protects 'v*' tags; relax that rule and re-run"
fi
if git remote get-url "$NOSTR_REMOTE" >/dev/null 2>&1; then
git push --force "$NOSTR_REMOTE" "$tag" \
|| warn "force-push to $NOSTR_REMOTE $tag failed (mirror; continuing)"
fi
hdr "$version: re-uploading the assets"
# Only the signature, the exported key and the PKGBUILD changed; the tarball
# bytes and the checksum are untouched, so `sha256sums` stays valid.
gt release upload "$tag" \
"$dir/regent-$version.tar.xz.asc" \
"$dir/regent-signing-key.asc" \
"$dir/PKGBUILD" --clobber
}
for v in "${versions[@]}"; do
resign_one "$v"
done
# The AUR `regent` package builds whichever version its `_tag` names; its
# `validpgpkeys` must match that release's signer. Update it only if it points
# at one of the versions we just re-signed.
if [ "$aur" = yes ] && [ "$push" = yes ]; then
hdr "updating the AUR recipe"
git clone --quiet "$AUR_REGENT" "$WORK/aur-regent"
aur_tag=$(sed -n 's/^_tag=//p' "$WORK/aur-regent/PKGBUILD" | head -1)
match=no
for v in "${versions[@]}"; do [ "$aur_tag" = "$v" ] && match=yes; done
if [ "$match" = no ]; then
log "AUR regent points at ${aur_tag:-unknown}, which was not re-signed; leaving it"
elif grep -qx "_fingerprint=$FPR" "$WORK/aur-regent/PKGBUILD"; then
log "AUR regent already carries the pinned fingerprint; nothing to do"
else
sed -i "s/^_fingerprint=.*/_fingerprint=$FPR/" "$WORK/aur-regent/PKGBUILD"
( cd "$WORK/aur-regent"
makepkg --printsrcinfo > .SRCINFO
git add PKGBUILD .SRCINFO
git commit -q -m "Re-sign $aur_tag with the pinned release key"
git push --quiet origin master )
log "AUR regent: pushed $aur_tag with the pinned fingerprint"
fi
fi
hdr "done"
log "re-signed: ${versions[*]}"
+33 -2
View File
@@ -56,7 +56,18 @@ Verifies the tarball against `release.env` and `sha256sum`, then:
- exports the public key → `dist/regent-signing-key.asc`,
- `git tag -s` (GPG) and pushes the tag.
The key comes from `REGENT_GPG_KEY`, else the first secret key in the keyring.
The key is the **pinned release key** — `RELEASE_KEY_FPR` in `release.sh`:
```
Râu Cao <raucao@kosmos.org>
5306FC8F1361E469C2E4CF5637036C356E56CC51
```
`sign` refuses any other key (its private half must be in the keyring), and
refuses a key without a secret half. The pin exists because the old fallback —
"the first secret key in the keyring" — silently signed a whole release series
with an unrelated key and put *its* fingerprint in the AUR `validpgpkeys`.
`REGENT_GPG_KEY` overrides the pin for a rotation, and warns that it did.
## `publish` (laptop)
@@ -100,10 +111,30 @@ unwrapped for you.
- `REGENT_MESON_DIST_ARGS=--no-tests` (`prepare`) — skip `meson dist`'s
build-and-test of the tarball.
## Repairing a mis-signed release
A release that went out under the wrong key is fixed with
`build-aux/resign-release.sh <version>…` (on the laptop). It re-signs the same
tarball bytes with the pinned key, re-tags the same commit and refreshes the
assets, so the sha256 and every `sha256sums` are unchanged. It force-pushes the
tags, so relax Gitea's `v*` tag protection first and restore it afterwards; the
Nostr tag force-push is best-effort. `--no-push` previews. `--no-aur` leaves the
AUR alone. This was used once, for 0.9.0–0.9.2, which the old keyring-scan
fallback had signed with an unrelated key.
The script also **regenerates** each release's PKGBUILD asset rather than just
re-pointing its `_fingerprint`, because the published ones were stale: `0.9.0`'s
was the initial placeholder (`sha256sums=('SKIP' 'SKIP')` — no integrity check),
and `0.9.1`'s was `0.9.0`'s recipe. Both predate the AUR update that `publish`
now runs before it uploads the asset. The regenerated recipe is the current
in-repo one with that release's `pkgver`/`_tag`/sha and the pinned signer.
## One-time setup
- A **GPG** key for signing tags and tarballs, on the laptop; publish its
fingerprint.
fingerprint on WKD and a keyserver (makepkg fetches it from there for
`validpgpkeys`). The current one is `RELEASE_KEY_FPR` in `release.sh`
(`5306FC8F1361E469C2E4CF5637036C356E56CC51`).
- An **SSH** key for signing the release commit, on the build host.
- Gitea: protect `v*` tags; `gt auth login` where `publish` runs.
- AUR: the `regent` and `regent-git` packages, with the AUR SSH key where