From 3c6474912508de8c6b32728f880203226b2c9efb Mon Sep 17 00:00:00 2001 From: Manuel de Brito Fontes Date: Fri, 4 Dec 2026 08:15:52 -0300 Subject: [PATCH 1/2] shirudo: pin spinbox at 8c6782fe, with scoped signers and --key-fd spinbox now holds spin-stack/shirudo#17, a .scope file beside a trusted certificate in the config image that limits what its key may sign, and #19, shirudo-build and the gen tools taking the signing key on an inherited descriptor (--key-fd). The rest of the range is #18, #20 and #21, which stack the patch branches by area and change no file but .github/spin/stack.sh. The bump finds the carried kernel patches unchanged; Makefile.target-deps and testing/kernel/patches do not move. Part of spin-stack/spin#2043 Co-Authored-By: Claude Opus 5.5 --- versions.yaml | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/versions.yaml b/versions.yaml index b7064859..98abc8e1 100644 --- a/versions.yaml +++ b/versions.yaml @@ -180,7 +180,7 @@ kind: git source: https://github.com/spin-stack/shirudo.git version: spinbox - pin: 412dc8f3788f893a4e86e949df6dd5449ab3cd2b + pin: 8c6782fe93750f8c36e553e194abc22cc77d5279 track: branch bump: spin-machine-dev bump note: >- From 4737540ca1b8d6ba2601c464a90df55bb43ac71c Mon Sep 17 00:00:00 2001 From: Manuel de Brito Fontes Date: Fri, 4 Dec 2026 08:21:30 -0300 Subject: [PATCH 2/2] boot:shirudo: sign with each key on a descriptor, and scope an import key The control plane will pass each shirudo key to the release's signing subset on a pipe at descriptor 3, with a key directory holding cert.der alone (spin-stack/spin#2047). The operator's control-plane step now signs that way wherever the release's shirudo-build takes --key-fd: keys vouch, shirudo-gen-image, shirudo-gen-runtime and shirudo-build on an object. The test fails a release whose shirudo-build takes none. The config image also gains the import key of spin-stack/spin#2049. The operator's key vouches for it, and import.scope gives it spin's scope (spin-stack/spin#2012): any upatch but spin-seal and spin-guard*. It signs af-alg-block, which loads, and a spin-seal, which the guest refuses for its scope. Part of spin-stack/spin#2043 Co-Authored-By: Claude Opus 5.5 --- boot/Taskfile.yml | 6 ++- boot/shirudo_test.go | 18 ++++++--- boot/testdata/seal-check.sh | 11 +++++- boot/testdata/shirudo-check.sh | 3 ++ docs/shirudo.md | 9 ++++- internal/shirudo/shirudo-operator.sh | 56 ++++++++++++++++++++++------ internal/shirudo/shirudo.go | 5 ++- 7 files changed, 84 insertions(+), 24 deletions(-) diff --git a/boot/Taskfile.yml b/boot/Taskfile.yml index 68050d89..7845cbfd 100644 --- a/boot/Taskfile.yml +++ b/boot/Taskfile.yml @@ -288,11 +288,13 @@ tasks: deploys it with nothing but the release (#759, #800): in a guest of the release, a normal user with RLIMIT_MEMLOCK raised makes this run's key and the signed config and dm-verity runtime images, and signs the shipped spin-seal.o and af-alg-block.o, with the main tarball's signing - subset and no clang or ldd, as an installation's control plane does (#886); its operator half + subset, each key on a descriptor, and no clang or ldd, as an installation's control plane does + (#886, spin-stack/spin#2047); its operator half (shirudo-operator) makes the upatches only this check loads and a systemd initrd around the shipped binary; booted from those with --lockdown shirudo and a TPM, init completes in the initrd and in the root file system's unit the initrd's mark names, status is ok with the keyrings - sealed, a signed upatch blocks an AF_ALG socket and leaves AF_UNIX alone, Docker runs + sealed, a upatch signed by a scoped import key blocks an AF_ALG socket and leaves AF_UNIX + alone while the seal that key signed is refused for its scope (spin-stack/spin#2012), Docker runs containers and a build with no load refused while a unit's DevicePolicy= does not hold, and a signed tcx/egress upatch drops a veth's DSCP 21 while tc's unsigned load of it is refused, and spin's egress seal, signed by its own key, holds against root on eth0 and refuses an diff --git a/boot/shirudo_test.go b/boot/shirudo_test.go index eba24dcd..5500bac7 100644 --- a/boot/shirudo_test.go +++ b/boot/shirudo_test.go @@ -28,12 +28,15 @@ import ( // raised makes a key of this run's, the signed config image and the dm-verity runtime image around // that binary, and signs the shipped seal and af-alg-block objects, with the main tarball's signing // subset and no clang or ldd it can reach, as an installation's control plane does (#886, -// spin-stack/spin#2043); and the release's operator half (shirudo-operator, its second tarball) -// makes the systemd initrd and the upatches only this check loads (internal/shirudo). Then the machine boots with --lockdown shirudo and a TPM from what -// it made. Its init runs to the end in the initrd and again in the root file system, in the one -// unit the initrd's mark names (testdata/shirudo-root.sh), status says ok with the keyrings sealed, -// and one of the upatches, shirudo's own CVE-2026-31431 mitigation, loads and blocks the path it is -// for (an AF_ALG socket) and leaves another (AF_UNIX) alone (testdata/shirudo-check.sh). What +// spin-stack/spin#2043), each key passed on a descriptor (spin-stack/spin#2047); and the release's +// operator half (shirudo-operator, its second tarball) makes the systemd initrd and the upatches +// only this check loads (internal/shirudo). Then the machine boots with --lockdown shirudo and a TPM +// from what it made. Its init runs to the end in the initrd and again in the root file system, in +// the one unit the initrd's mark names (testdata/shirudo-root.sh), status says ok with the keyrings +// sealed, and one of the upatches, shirudo's own CVE-2026-31431 mitigation, signed by an import key +// the config image scopes (spin-stack/spin#2012), loads and blocks the path it is for (an AF_ALG +// socket) and leaves another (AF_UNIX) alone (testdata/shirudo-check.sh), while the seal that key +// signed is refused for its scope (testdata/seal-check.sh). What // docs/shirudo.md says of such a machine holds: Docker runs containers, --privileged and a docker // build's RUN step too, with no load refused, while a unit's DevicePolicy= does not hold; and a // signed tcx/egress upatch drops a veth's DSCP 21 and nothing else, while tc's own load of the same @@ -84,6 +87,9 @@ func TestTheShippedShirudoRunsOnTheRelease(t *testing.T) { t.Fatal(err) } t.Log(said) + if !strings.Contains(said, "signing with each key on descriptor 3") { + t.Fatal("the release's shirudo-build takes no signing key on a descriptor (--key-fd), as the control plane passes each key (spin-stack/spin#2047)") + } r := newRawRoot(t, out, base) must(t, work.Install(r)) sum, err := build.FileSHA256(filepath.Join(out, build.ShirudoBinary)) diff --git a/boot/testdata/seal-check.sh b/boot/testdata/seal-check.sh index 33f1df06..57c74252 100644 --- a/boot/testdata/seal-check.sh +++ b/boot/testdata/seal-check.sh @@ -83,12 +83,21 @@ tc qdisc add dev eth0 clsact && tc qdisc del dev eth0 clsact && echo "tc edits e echo "The seal's key is its own, vouched for by the installation's key; a stranger's is not trusted." $shirudo keys -$shirudo keys | grep -q '^Trusted set (2 members, 0 revoked, 0 unvouched)' +$shirudo keys | grep -q '^Trusted set (3 members, 0 revoked, 0 unvouched)' if said=$($shirudo upatch load /seal-stranger.upatch 2>&1); then echo "a seal signed by a key nobody vouched for was loaded: $said" exit 1 fi echo "refused: the seal signed by a stranger's key ($(echo "$said" | tail -1))" +# The import key is trusted, and its scope in the config image leaves out the seal's name +# (spin-stack/spin#2012): af-alg-block, which it signed, loaded (shirudo-check.sh). +if said=$($shirudo upatch load /seal-import.upatch 2>&1); then + echo "a seal signed by the import key, whose scope leaves it out, was loaded: $said" + exit 1 +fi +echo "$said" | grep -q 'whose scope in the config image leaves out that name' || + { echo "the import key's seal was refused, but not for its scope: $said"; exit 1; } +echo "refused: the seal signed by the import key ($(echo "$said" | tail -1))" $shirudo upatch load /seal.upatch $shirudo upatch list diff --git a/boot/testdata/shirudo-check.sh b/boot/testdata/shirudo-check.sh index cf8d1efc..748f0ac4 100644 --- a/boot/testdata/shirudo-check.sh +++ b/boot/testdata/shirudo-check.sh @@ -66,6 +66,9 @@ before=$(sock 38) echo "AF_ALG before the upatch: $before" test "$before" = "Address family not supported by protocol" +# Signed by the import key, whose scope in the config image allows every name but the handoff's +# (shirudo-operator.sh): this load is what the scope allows, the seal's refusal in seal-check.sh +# what it does not. $shirudo upatch load /af-alg-block.upatch $shirudo upatch list blocked=$(sock 38) diff --git a/docs/shirudo.md b/docs/shirudo.md index 8dcaa3e6..3b33f8a1 100644 --- a/docs/shirudo.md +++ b/docs/shirudo.md @@ -65,7 +65,14 @@ does the same in the operator's guest, after `install`, where the release ships - with `shirudo/libexec`, `shirudo/libexec/gen-image` and `guest/` on its `PATH`, and `/usr/local`, the operator half and `ldd` inaccessible to it, so that it reaches no clang and `shirudo-gen-runtime` needs no `ldd` for the static `guest/shirudo` (spin-stack/shirudo#11); -- signing `shirudo/objects/spin-seal.o` with the seal's key and `af-alg-block.o` with the operator's. +- passing each key as the control plane passes it (spin-stack/spin#2047): on descriptor 3 from a + pipe (`--key-fd 3`), with a key directory that holds `cert.der` alone, where the release's + `shirudo-build` takes one (spin-stack/shirudo#19); +- signing `shirudo/objects/spin-seal.o` with the seal's key and `af-alg-block.o` with the import + key of spin-stack/spin#2049. The operator's key vouches for the import key in the config image's + `keys/trusted/`, and `import.scope` beside it gives it spin's scope (spin-stack/spin#2012, + spin-stack/shirudo#17): every upatch but `spin-seal` and `spin-guard*`. `boot:shirudo` loads its + `af-alg-block` and has its `spin-seal` refused for that scope. The images it makes hold its own files, owned by its uid, not root's. The same user then compiles and signs the upatches only `boot:shirudo` loads with the operator half's clang, and root makes diff --git a/internal/shirudo/shirudo-operator.sh b/internal/shirudo/shirudo-operator.sh index 4706f8f1..237c0b58 100644 --- a/internal/shirudo/shirudo-operator.sh +++ b/internal/shirudo/shirudo-operator.sh @@ -15,21 +15,53 @@ # reach. Called with one argument, the script is one of the signer's steps. set -eu +# signs KEYS COMMAND...: COMMAND signs with the key genkey made in KEYS, given --keys-dir. A +# shirudo-build that takes --key-fd (spin-stack/shirudo#19) gets the key as the control plane passes +# it (spin-stack/spin#2047): on descriptor 3 from a pipe, and a key directory with cert.der alone. +signs() { + from=$1 + shift + if [ -z "$key_fd" ]; then + "$@" --keys-dir "$from" + return + fi + certs=$TMPDIR/certs/${from##*/} + mkdir -p -m 0700 "$certs" + cp "$from/cert.der" "$certs/cert.der" + cat "$from/signing_key.pem" | "$@" --keys-dir "$certs" --key-fd 3 3<&0 &1 | grep -q -- '--key-fd'; then + key_fd=3 + echo "signing with each key on descriptor 3, from a pipe" + fi + mkdir -m 0700 "$keys" "$work/seal-keys" "$TMPDIR/stranger-keys" "$import" shirudo genkey --keys-dir="$keys" shirudo genkey --keys-dir="$work/seal-keys" shirudo genkey --keys-dir="$TMPDIR/stranger-keys" - mkdir -p "$work/config-root/etc/shirudo" "$work/config-root/keys/trusted" "$work/images" - cp "$work/seal-keys/cert.der" "$work/config-root/keys/trusted/spin-seal.der" - shirudo-build keys vouch "$work/seal-keys/cert.der" -o "$work/config-root/keys/trusted/spin-seal.vouch" --keys-dir="$keys" + shirudo genkey --keys-dir="$import" + mkdir -p "$work/config-root/etc/shirudo" "$trusted" "$work/images" + cp "$work/seal-keys/cert.der" "$trusted/spin-seal.der" + signs "$keys" shirudo-build keys vouch "$work/seal-keys/cert.der" -o "$trusted/spin-seal.vouch" + cp "$import/cert.der" "$trusted/import.der" + signs "$keys" shirudo-build keys vouch "$import/cert.der" -o "$trusted/import.vouch" + printf 'upatch *\nupatch !spin-seal\nupatch !spin-guard*\n' >"$trusted/import.scope" echo 'eventlog.max_bytes = 0' >"$work/config-root/etc/shirudo/shirudo.conf" cat >"$work/runtime.conf" <<'EOF' @@ -39,22 +71,22 @@ config.pcr = 14 tpm.tcti = device:/dev/tpmrm0 EOF cd "$work/images" - shirudo-gen-image --source "$work/config-root" --output initial --keys-dir "$keys" --kind config + signs "$keys" shirudo-gen-image --source "$work/config-root" --output initial --kind config shirudo-build image verify initial --cert "$cert" - shirudo-gen-runtime --binary "$release/guest/shirudo" --bootstrap-conf "$work/runtime.conf" \ - --cert "$cert" --config-cert "$cert" --output runtime --keys-dir "$keys" \ - --unit-output "$work/runtime-service.conf" + signs "$keys" shirudo-gen-runtime --binary "$release/guest/shirudo" --bootstrap-conf "$work/runtime.conf" \ + --cert "$cert" --config-cert "$cert" --output runtime --unit-output "$work/runtime-service.conf" printf 'runtime.image = /var/lib/shirudo/images/runtime\nruntime.root_hash = %s\n' \ "$(cat runtime.roothash)" >"$work/uki-bootstrap.conf" - shirudo-build "$af_alg" -o "$work/af-alg-block.upatch" --name af-alg-block --keys-dir "$keys" + signs "$import" shirudo-build "$af_alg" -o "$work/af-alg-block.upatch" --name af-alg-block # A shirudo from before spin-stack/shirudo#7 refuses the seal's tcx sections, and that refusal # alone leaves the machine without it (Install): a later ladder makes an earlier release's # machine with this script. Its standard error is a file here, so shirudo writes the refusal # there too. - if shirudo-build "$seal" -o "$work/seal.upatch" --name spin-seal --keys-dir "$work/seal-keys" \ + if signs "$work/seal-keys" shirudo-build "$seal" -o "$work/seal.upatch" --name spin-seal \ 2>"$TMPDIR/seal.err"; then - shirudo-build "$seal" -o "$work/seal-stranger.upatch" --name spin-seal --keys-dir "$TMPDIR/stranger-keys" + signs "$TMPDIR/stranger-keys" shirudo-build "$seal" -o "$work/seal-stranger.upatch" --name spin-seal + signs "$import" shirudo-build "$seal" -o "$work/seal-import.upatch" --name spin-seal elif grep -q "^unsupported section 'tcx/" "$TMPDIR/seal.err"; then echo "shirudo refuses tcx sections: no seal" else diff --git a/internal/shirudo/shirudo.go b/internal/shirudo/shirudo.go index 659c9846..cef25014 100644 --- a/internal/shirudo/shirudo.go +++ b/internal/shirudo/shirudo.go @@ -136,7 +136,8 @@ func (w Work) Initrd() string { return filepath.Join(w.dir, "initrd.img") } // image's drop-in and enabled; the af-alg-block and tcx-dscp upatches at /af-alg-block.upatch // and /tcx-dscp.upatch, for `shirudo upatch load`; and tcx-dscp's program unsigned at // /tcx-dscp.o, for tc to load itself; and spin's egress seal at /seal.upatch, signed by the seal's -// key, and at /seal-stranger.upatch, signed by a key nothing vouches for. tcx-dscp and the seal are +// key, at /seal-stranger.upatch, signed by a key nothing vouches for, and at /seal-import.upatch, +// signed by the import key, whose scope leaves the seal out. tcx-dscp and the seal are // there only where the shirudo accepts tcx sections (spin-stack/shirudo#7 on): the // operator makes them only then (shirudo-operator.sh). // @@ -197,7 +198,7 @@ func (w Work) Install(root *rawroot.Root) error { } switch _, err := os.Stat(filepath.Join(w.dir, "tcx-dscp.upatch")); { case err == nil: - for _, f := range []string{"tcx-dscp.upatch", "tcx-dscp.o", "seal.upatch", "seal-stranger.upatch"} { + for _, f := range []string{"tcx-dscp.upatch", "tcx-dscp.o", "seal.upatch", "seal-stranger.upatch", "seal-import.upatch"} { if err := put(f, "/"+f); err != nil { return err }