Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
6 changes: 4 additions & 2 deletions boot/Taskfile.yml
Original file line number Diff line number Diff line change
Expand Up @@ -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
Expand Down
18 changes: 12 additions & 6 deletions boot/shirudo_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -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
Expand Down Expand Up @@ -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))
Expand Down
11 changes: 10 additions & 1 deletion boot/testdata/seal-check.sh
Original file line number Diff line number Diff line change
Expand Up @@ -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

Expand Down
3 changes: 3 additions & 0 deletions boot/testdata/shirudo-check.sh
Original file line number Diff line number Diff line change
Expand Up @@ -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)
Expand Down
9 changes: 8 additions & 1 deletion docs/shirudo.md
Original file line number Diff line number Diff line change
Expand Up @@ -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
Expand Down
56 changes: 44 additions & 12 deletions internal/shirudo/shirudo-operator.sh
Original file line number Diff line number Diff line change
Expand Up @@ -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 </dev/null
}

# sign makes the keys, the images, and the af-alg-block and seal upatches from $af_alg and $seal in
# $work. spin's egress seal is signed by a key of its own, not by the operator's
# (spin-stack/spin#1876). The operator's key vouches for it in the config image, which is what puts
# it in the .bpf keyring at init. A stranger's key, which nothing vouches for, signs the same seal
# for the check that it is refused.
# for the check that it is refused. The import key of spin-stack/spin#2049 is vouched for too, with
# the scope spin gives it beside its certificate (spin-stack/spin#2012, spin-stack/shirudo#17): any
# upatch but those the handoff loads. It signs af-alg-block, which its scope allows, and the seal,
# which it does not.
sign() {
keys=$work/keys
cert=$keys/cert.der
mkdir -m 0700 "$keys" "$work/seal-keys" "$TMPDIR/stranger-keys"
import=$TMPDIR/import-keys
trusted=$work/config-root/keys/trusted
# A shirudo-build from before spin-stack/shirudo#19 takes no key on a descriptor, and a later
# ladder makes an earlier release's machine with this script.
key_fd=
if shirudo-build --help 2>&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'
Expand All @@ -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
Expand Down
5 changes: 3 additions & 2 deletions internal/shirudo/shirudo.go
Original file line number Diff line number Diff line change
Expand Up @@ -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).
//
Expand Down Expand Up @@ -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
}
Expand Down
2 changes: 1 addition & 1 deletion versions.yaml
Original file line number Diff line number Diff line change
Expand Up @@ -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: >-
Expand Down