eBPF-based security platform
bpm: build a config update only on the base package the operator pins
Daniel Borkmannc65b45053441
diff --git a/.agents/skills/security-audit/SKILL.md b/.agents/skills/security-audit/SKILL.mdindex 500fef8a..38994505 100644--- a/.agents/skills/security-audit/SKILL.md+++ b/.agents/skills/security-audit/SKILL.md@@ -86,7 +86,7 @@ code, then take it through "Refute it".| Files, pins, xattrs, mounts, `/proc`, environment | ADV-B, ADV-C | `util/seal.c`, `util/paths.c`, `util/io.c`, `builtin-init.c` | act on the object checked; lock spans || `bpf()`, LSM hooks | ADV-A, ADV-B | `bpf/bpf2.c`, `bpf/seal.c` | every syscall path to the same effect || Collector replies | ADV-E | `util/upatch_maps_otel.c` | changes no state; text sanitized |-| Operator inputs, key | ADV-D (U14) | `tools/shirudo-build/`, `util/sign.c` | key stays on the operator; stateless |+| Operator inputs, key | ADV-D | `tools/shirudo-build/`, `util/sign.c` | key stays on the operator; stateless; what a registry serves is pinned |The fuzz targets in `testing/fuzz/` list the parsers of outside input,and `Documentation/contribute/testing/proof-coverage.rst` says whichdiff --git a/Documentation/contribute/testing/test-coverage.rst b/Documentation/contribute/testing/test-coverage.rstindex 1508d623..46e5f591 100644--- a/Documentation/contribute/testing/test-coverage.rst+++ b/Documentation/contribute/testing/test-coverage.rst@@ -569,6 +569,10 @@ signed config image.* - ``t7010-bpm-slow-registry``- A registry that trickles a package fast enough for the low-speedlimit is cut off at the transfer's total deadline+ * - ``t7011-bpm-config-base``+ - ``bpm config update`` refuses an ``oci://`` base package without+ ``--base-digest``, the option with a local base, a malformed+ digest and a registry that serves another manifest* - ``t7101-bpm-tree``- Tree sync with a selector* - ``t7102-bpm-tree-sequential``diff --git a/Documentation/reference/cli/bpm.rst b/Documentation/reference/cli/bpm.rstindex d8cdde15..b1049afa 100644--- a/Documentation/reference/cli/bpm.rst+++ b/Documentation/reference/cli/bpm.rst@@ -25,6 +25,7 @@ Usageshirudo bpm config register listshirudo bpm config register (remove | rm) <source>shirudo bpm config update --base-package <package> --version <version>+ [--base-digest sha256:<manifest>][--file <beefile>][--rodata-input <name>=<path>]... [--keys-dir <dir>]shirudo bpm repo update [<source>]@@ -156,7 +157,12 @@ again and signs a new unload directive for it. The base package must besigned by the same key and declare ``.rodata`` inputs, and ``--version``must be a SemVer 2.0.0 version greater than its version. Without ``--file``, the Beefile and thecommands it names come from the base package and run on the operator-host: take base packages only from sources you trust. The output is+host: take base packages only from sources you trust. An ``oci://``+base package needs ``--base-digest``, the manifest digest ``bpm push``+printed when you published it, and the command refuses another+manifest: a tag is the registry's to point at any package your key+signed, an older one included, whose loaders and Beefile the command+would take. ``--base-digest`` with a local base package is refused. The output is``<name>-<version>.bee`` in the current directory. Options take theirvalue as the next argument only.@@ -452,7 +458,8 @@ push----``push`` publishes a ``.bee`` file to ``oci://<registry>/<repository>``-(no tag) and prints ``oci://<registry>/<repository>:<version>``. With+(no tag) and prints ``oci://<registry>/<repository>:<version>+sha256:<digest>``, the digest of the manifest it pushed. With``--keys-dir``, or ``--index-cert`` and ``--index-key`` together, it alsoadds the package to the registry's signed index``<namespace>/bpm-index:stable``, signed with that key. The namespace isdiff --git a/Documentation/security/threat-model.rst b/Documentation/security/threat-model.rstindex 3772eb5a..c7f2235a 100644--- a/Documentation/security/threat-model.rst+++ b/Documentation/security/threat-model.rst@@ -468,9 +468,9 @@ ADV-C, root with mount-namespace and device controlADV-D, network and registryTowards the target: observes, drops, delays and replays traffic, andserves any content a registry holds, old signed content included- (T7, R8). Towards the operator: a registry from which ``shirudo bpm- config update --base-package oci://`` takes a package runs commands- on the operator host (U14), and so can become ADV-F.+ (T7, R8). Towards the operator: it serves what ``bpm tree append``+ and ``bpm config update`` build on, which the operator pins by+ ``--tree-id`` and ``--base-digest``.ADV-E, malicious collectorReceives keepalives and map snapshots. It can refuse or delay them@@ -1890,18 +1890,6 @@ U13 A revoked signer's historical vouches remain validdependent key whose authority should no longer be trusted. Aplanned overlap is not sufficient compromise recovery by itself.-U14 The operator runs commands from a registry package- :Affects: ``shirudo bpm config update --base-package oci://...``- without ``--file`` on the operator host.- :Consequence: The command takes the Beefile from a package checked- only against the registry's manifest digest and runs its updater- commands on the host that holds the signing key. A hostile- registry becomes ADV-F.- :Status: Confirmed in code; the usage text says the commands are- trusted as operator-side code.- :Meanwhile: Always pass ``--file`` with a local Beefile, or a local- ``.bee`` file as the base package.-U15 Certificates are fetched without a pin:Affects: ``tools/gen-initrd/install.sh --cert <url>`` and``shirudo bpm key add oci://...``, which image mode refuses on a@@ -2010,8 +1998,7 @@ D9 Perf events across execOut of scope-------------- Compromise of the operator host or of the signing key itself. U14 is- in scope, because it turns a registry into that compromise.+- Compromise of the operator host or of the signing key itself.- A malicious or faulty kernel, verifier, TPM or hardware, and physicalattacks (ADV-G).- Denial of service: removing the binary, cutting the network, filling@@ -2050,9 +2037,7 @@ The deployer:- Uses only ML-DSA-87 certificates from ``shirudo genkey``, repositorycertificates included (U4)- Treats the TPM owner password as known to root (R20)-- Never runs ``shirudo bpm config update --base-package oci://...``- without ``--file`` (U14), and checks the fingerprint of every- certificate it installs (U15)+- Checks the fingerprint of every certificate it installs (U15)- Watches the size of the eventlog (U6) and the keepalives, and treats a``tampered`` status as an incident to understand, not a condition toretry (:doc:`/operate/troubleshoot/incident-tampered`)diff --git a/Documentation/upatches/publish/publishing.rst b/Documentation/upatches/publish/publishing.rstindex 259d1897..7625b5c4 100644--- a/Documentation/upatches/publish/publishing.rst+++ b/Documentation/upatches/publish/publishing.rst@@ -80,8 +80,9 @@ Push it to a repository``<namespace>/bpm-index:stable`` in the same registry, signs the indexwith your key, and tags the package with its version. The indexnamespace is the package repository path without its final name. It- prints the pushed reference,- ``oci://<registry>/<namespace>/<name>:<version>``.+ prints the pushed reference and the manifest's digest,+ ``oci://<registry>/<namespace>/<name>:<version> sha256:<digest>``;+ ``bpm config update`` takes that digest to build on the package.The first package of a namespace needs ``--new-index``: ``bpm push``refuses a namespace without an index otherwise, so that a registry thatdiff --git a/testing/functional/bpm/t7005-bpm-publish.sh b/testing/functional/bpm/t7005-bpm-publish.shindex 97837e53..7a883682 100644--- a/testing/functional/bpm/t7005-bpm-publish.sh+++ b/testing/functional/bpm/t7005-bpm-publish.sh@@ -305,7 +305,8 @@ test_expect_success 'bpm push refuses a namespace without an index unless told ttest_expect_success 'bpm push publishes the package and a signed repository index' '"$S" bpm push "$WORK/t7005-1.0.0.bee" "oci://$REGISTRY/ns/t7005" \--keys-dir "$WORK/keys" --new-index >"$WORK/push.out" 2>"$WORK/push.err" &&- grep -qx "oci://$REGISTRY/ns/t7005:1.0.0" "$WORK/push.out" &&+ grep -qx "oci://$REGISTRY/ns/t7005:1.0.0 sha256:$(sha256sum \+ <"$REG/ns/t7005/manifests/1.0.0" | cut -d" " -f1)" "$WORK/push.out" &&test -s "$REG/ns/t7005/manifests/1.0.0" &&test -s "$REG/ns/bpm-index/manifests/stable" &&split_layers "$REG/ns/bpm-index/manifests/stable" "$REG/ns/bpm-index" "$WORK/index1" &&diff --git a/testing/functional/bpm/t7011-bpm-config-base.sh b/testing/functional/bpm/t7011-bpm-config-base.shnew file mode 100755index 00000000..8619fa83--- /dev/null+++ b/testing/functional/bpm/t7011-bpm-config-base.sh@@ -0,0 +1,93 @@+#!/bin/sh+# SPDX-License-Identifier: BSD-2-Clause+# Copyright (c) 2026 Authors of shirudo+#+# t7011 -- bpm config update takes an oci:// base package only under the+# manifest digest the operator names: without --base-digest, and with a+# registry that serves another manifest under the tag, it refuses before+# it reads the package.++cd "$(dirname "$0")/../.."+. ./test-lib.sh++REPO=$(cd .. && pwd)+S=$REPO/shirudo+SHB=$REPO/tools/shirudo-build/shirudo-build+command -v python3 >/dev/null 2>&1 || test_skip_all "no python3"+[ -x "$S" ] || test_skip_all "shirudo not built"+[ -x "$SHB" ] || test_skip_all "shirudo-build not built (make shirudo-build)"+W=$(mktemp -d)+SERVER=+cleanup() {+ [ -z "$SERVER" ] || kill "$SERVER" 2>/dev/null || :+ rm -rf "$W"+}+trap cleanup EXIT++cat >"$W/registry.py" <<'PY'+import http.server, json, sys++MANIFEST = json.dumps({+ "schemaVersion": 2,+ "mediaType": "application/vnd.oci.image.manifest.v1+json",+ "layers": [{"mediaType": "application/vnd.shirudo.bpm.package.v1+gzip",+ "digest": "sha256:" + "0" * 64, "size": 1}],+}).encode()+++class Handler(http.server.BaseHTTPRequestHandler):+ def log_message(self, *args):+ pass++ def do_GET(self):+ if "/manifests/" not in self.path:+ self.send_error(404)+ return+ self.send_response(200)+ self.send_header("Content-Type",+ "application/vnd.oci.image.manifest.v1+json")+ self.send_header("Content-Length", str(len(MANIFEST)))+ self.end_headers()+ self.wfile.write(MANIFEST)+++server = http.server.ThreadingHTTPServer(("127.0.0.1", 0), Handler)+with open(sys.argv[1], "w") as f:+ f.write(str(server.server_address[1]))+server.serve_forever()+PY+python3 "$W/registry.py" "$W/port" &+SERVER=$!+for _ in 1 2 3 4 5 6 7 8 9 10; do+ [ -s "$W/port" ] && break+ sleep 0.5+done+[ -s "$W/port" ] || test_skip_all "the registry did not start"+BASE="oci://127.0.0.1:$(cat "$W/port")/ns/base:1.0.0"+OTHER=sha256:$(printf '%064d' 1)+update() {+ (cd "$W" && BPM_OCI_SCHEME=http SHIRUDO_BUILD="$SHB" \+ "$S" bpm config update "$@" \+ --version 1.0.1 >"$W/out" 2>"$W/err")+}++test_expect_success 'an oci:// base needs the manifest digest' '+ ! update --base-package "$BASE" &&+ grep -q "base-digest names the manifest of an oci:// base package" \+ "$W/err"+'+test_expect_success 'a local base takes none' '+ : >"$W/base.bee" &&+ ! update --base-package "$W/base.bee" --base-digest "$OTHER" &&+ grep -q "base-digest names the manifest of an oci:// base package" \+ "$W/err"+'+test_expect_success 'a digest that is not sha256 hex is refused' '+ ! update --base-package "$BASE" --base-digest sha256:ABC &&+ grep -q "is not sha256:<64 lowercase hex>" "$W/err"+'+test_expect_success 'another manifest under the tag is refused' '+ ! update --base-package "$BASE" --base-digest "$OTHER" &&+ grep -q "serves manifest sha256:[0-9a-f]*, not $OTHER" "$W/err"+'+test_donediff --git a/tools/shirudo-build/bpm-build.c b/tools/shirudo-build/bpm-build.cindex 08bda115..cb9913f2 100644--- a/tools/shirudo-build/bpm-build.c+++ b/tools/shirudo-build/bpm-build.c@@ -1969,7 +1969,13 @@ out:return ret;}-static int build_download_package(const char *reference, char *path)+/*+ * The package of the manifest whose digest the operator named: a tag is+ * the registry's to point at any package the key ever signed, an older+ * one included, whose loaders config update would sign as a new version.+ */+static int build_download_package(const char *reference, const char *want,+ char *path){struct bpm_oci_client client __cleanup(bpm_oci_client_clear) = {};struct bpm_descriptor layers[8] = {};@@ -1991,6 +1997,16 @@ static int build_download_package(const char *reference, char *path)ret = bpm_oci_get_memory(&client, url, BPM_MANIFEST_MEDIA, &manifest);if (ret)goto out;+ ret = bpm_sha256_hex(manifest.data, manifest.len, digest,+ sizeof(digest));+ if (ret)+ goto out;+ if (!bpm_digest_matches(want, digest)) {+ pr_err("bpm config update: %s serves manifest sha256:%s, not %s",+ reference, digest, want);+ ret = -EKEYREJECTED;+ goto out;+ }ret = bpm_oci_parse_manifest(manifest.data, manifest.len, layers,ARRAY_SIZE(layers), &n_layers, NULL, 0);if (ret)@@ -2037,7 +2053,7 @@ out:static int __build_bpm_config_update(int argc, char **argv,struct bpm_build_input_override *overrides){- const char *file_arg = NULL, *base_arg = NULL;+ const char *file_arg = NULL, *base_arg = NULL, *base_digest = NULL;const char *version = NULL, *keys_arg = NULL;size_t n_overrides = 0;char build_file[PATH_MAX], resolved_file[PATH_MAX], source_dir[PATH_MAX];@@ -2060,11 +2076,14 @@ static int __build_bpm_config_update(int argc, char **argv,fprintf(stdout,"usage: shirudo bpm config update ""--base-package <package.bee|oci://host/repo:tag> "+ "[--base-digest sha256:<manifest>] ""--version <version> ""[--file <name>.bee] [--keys-dir <dir>] ""[--rodata-input <name>=<path>]...\n""Without --file, the Beefile and updater inputs come from "- "--base-package and are trusted as operator-side code.\n");+ "--base-package and are trusted as operator-side code.\n"+ "An oci:// base package needs --base-digest, the manifest "+ "digest bpm push printed for it.\n");return 0;} else if (!strcmp(argv[i], "--file")) {if (++i >= argc)@@ -2074,6 +2093,10 @@ static int __build_bpm_config_update(int argc, char **argv,if (++i >= argc)goto usage;base_arg = argv[i];+ } else if (!strcmp(argv[i], "--base-digest")) {+ if (++i >= argc)+ goto usage;+ base_digest = argv[i];} else if (!strcmp(argv[i], "--version")) {if (++i >= argc)goto usage;@@ -2103,8 +2126,20 @@ static int __build_bpm_config_update(int argc, char **argv,version);return -EINVAL;}- if (!strncmp(base_arg, "oci://", 6)) {- ret = build_download_package(base_arg, base_package_tmp);+ if (!strncmp(base_arg, "oci://", 6) != !!base_digest) {+ pr_err("bpm config update: --base-digest names the manifest of an oci:// base package, and one needs it");+ return -EINVAL;+ }+ if (base_digest && (strncmp(base_digest, "sha256:", 7) ||+ strlen(base_digest + 7) != 64 ||+ !hex_is_lower(base_digest + 7, 64))) {+ pr_err("bpm config update: --base-digest %s is not sha256:<64 lowercase hex>",+ base_digest);+ return -EINVAL;+ }+ if (base_digest) {+ ret = build_download_package(base_arg, base_digest,+ base_package_tmp);if (ret)return ret;if (strscpy(base_package, base_package_tmp,@@ -2346,7 +2381,8 @@ out_base:usage:fprintf(stderr,"usage: shirudo bpm config update --base-package "- "<package.bee|oci://host/repo:tag> --version <version> "+ "<package.bee|oci://host/repo:tag> "+ "[--base-digest sha256:<manifest>] --version <version> ""[--file <name>.bee] ""[--rodata-input <name>=<path>]... [--keys-dir <dir>]\n");return -EINVAL;@@ -2373,6 +2409,7 @@ static void bpm_usage(FILE *fp)" [--keys-dir <dir>] [--vmlinux <vmlinux.h>]\n"" [--rodata-input <name>=<path>]...\n"" shirudo bpm config update --base-package <package.bee|oci://...>\n"+ " [--base-digest sha256:<manifest>]\n"" --version <version> [--file <name>.bee]\n"" [--rodata-input <name>=<path>]...\n"" shirudo bpm push <package-file> <repository> [--keys-dir <dir> |\n"diff --git a/tools/shirudo-build/bpm-publish.c b/tools/shirudo-build/bpm-publish.cindex 7daf0554..5c356ae4 100644--- a/tools/shirudo-build/bpm-publish.c+++ b/tools/shirudo-build/bpm-publish.c@@ -521,8 +521,9 @@ static int push_package(const char *package_path, const char *raw_repository,sizeof(package_digest));if (ret)goto out;- if (strsprintf(reference, sizeof(reference), "oci://%s/%s:%s",- c.registry, repository, info.version) < 0) {+ if (strsprintf(reference, sizeof(reference), "oci://%s/%s:%s %s",+ c.registry, repository, info.version,+ package_digest) < 0) {ret = -ENAMETOOLONG;goto out;}