eBPF-based security platform
bpm: extend a tree only when the operator names it
Daniel Borkmann96ff4dbc3499
diff --git a/Documentation/contribute/testing/test-coverage.rst b/Documentation/contribute/testing/test-coverage.rstindex 350511bd..c1800a9a 100644--- a/Documentation/contribute/testing/test-coverage.rst+++ b/Documentation/contribute/testing/test-coverage.rst@@ -520,8 +520,9 @@ signed config image.could not unpack together, ``bpm push`` with a signed index,``bpm tree append`` and its refusal of an XDP device class twoupatches of a tree select and of an entry no target would take,- each before anything is uploaded, A-to-B tree signing-key rotation- with explicit predecessor verification+ each before anything is uploaded, its refusal to extend a tree+ without ``--tree-id`` or with another tree's id, A-to-B tree+ signing-key rotation with explicit predecessor verification* - ``t7006-policy-labels``- Beefile policy declarations are serialized into the signedupatch section@@ -538,7 +539,9 @@ signed config image.writes nothing to the registry; with ``--walk`` prints a treenever sealed as without it and every segment of a tree sealedby ``--segment-ops 1`` oldest first, stops at ``seq`` 0 from a- sealed segment, and refuses a tree whose sealed segment is gone+ sealed segment, and refuses a tree whose sealed segment is gone;+ ``bpm tree append`` refuses the ``beta`` tree served in place of+ ``stable``* - ``t7009-bpm-tree-seal``- ``bpm tree append`` seals a segment at ``--segment-ops``, a valuethat may change between appends, or before one append would passdiff --git a/Documentation/operate/maintain/keys.rst b/Documentation/operate/maintain/keys.rstindex c17f1129..2303225b 100644--- a/Documentation/operate/maintain/keys.rst+++ b/Documentation/operate/maintain/keys.rst@@ -296,7 +296,8 @@ publication with the old certificate:.. code-block:: consoleoperator$ shirudo bpm tree append <package> oci://<registry>/<tree> \- --keys-dir <standby-keys-dir> --previous-cert <primary-keys-dir>/cert.der+ --tree-id <tree-id> --keys-dir <standby-keys-dir> \+ --previous-cert <primary-keys-dir>/cert.derThe new publication is signed by the standby key. Later appends use thatkey for both checks and can omit ``--previous-cert``. Targets acceptdiff --git a/Documentation/reference/cheat-sheet.rst b/Documentation/reference/cheat-sheet.rstindex e94abcda..e4687a96 100644--- a/Documentation/reference/cheat-sheet.rst+++ b/Documentation/reference/cheat-sheet.rst@@ -221,14 +221,14 @@ append <cli/bpm>`. ``<package>`` is a built package whose Beefile has.. code-block:: console- operator$ shirudo bpm tree append <package> oci://quay.io/example/tree --keys-dir ~/shirudo-keys+ operator$ shirudo bpm tree append <package> oci://quay.io/example/tree --tree-id <tree-id> --keys-dir ~/shirudo-keysRetract them on another tree reference with :doc:`bpm tree append<cli/bpm>`:.. code-block:: console- operator$ shirudo bpm tree append <package> oci://quay.io/example/tree --keys-dir ~/shirudo-keys --reference canary --op delete+ operator$ shirudo bpm tree append <package> oci://quay.io/example/tree --tree-id <canary-tree-id> --keys-dir ~/shirudo-keys --reference canary --op deleteRefresh the indexes and upgrade, as ``shirudo-bpm-repo-update.timer``does, with :doc:`cli/bpm`:diff --git a/Documentation/reference/cli/bpm.rst b/Documentation/reference/cli/bpm.rstindex 0d3f8abf..1500972a 100644--- a/Documentation/reference/cli/bpm.rst+++ b/Documentation/reference/cli/bpm.rst@@ -243,8 +243,11 @@ package as the next operations of the signed tree atcertificate when the next publication will be signed by a new key.It does not change the certificate used to sign the new publication.* - ``--tree-id``- - the existing tree's, else the package name- - Tree ID. It must match the existing tree.+ - for a new tree, the package name at ``stable`` and+ ``<package>-<reference>`` at another reference+ - Tree ID. Required to extend an existing tree, and it must be that+ tree's: the registry chooses what the reference holds, so only the+ operator can say which tree the new generation belongs to.* - ``--reference``- ``stable``- Tag of the tree publication.diff --git a/Documentation/security/threat-model.rst b/Documentation/security/threat-model.rstindex 01ce59ec..e9b7e728 100644--- a/Documentation/security/threat-model.rst+++ b/Documentation/security/threat-model.rst@@ -1500,7 +1500,10 @@ R8 Registry withholding and replaypackages added since; a registry that claims to have none is refusedunless ``--new-index`` is given. ``bpm tree append`` builds the nextpublication on the one the registry serves the same way, so an older- one makes the operator sign a second branch of the tree. A target+ one makes the operator sign a second branch of the tree. It extends+ only the tree ``--tree-id`` names, which an existing tree requires,+ so a registry that serves another tree the key signs in its place, a+ canary tree at ``stable``, is refused (``t7005``, ``t7008``). A targetthat processed an operation the second branch does not have refusesit, as its operations up to the target's cursor do not fold to the``history_root`` the target holds, in a segment and at a segment'sdiff --git a/Documentation/upatches/learn/kernel-fix-tutorial.rst b/Documentation/upatches/learn/kernel-fix-tutorial.rstindex 08e5e3bc..cf2a58fb 100644--- a/Documentation/upatches/learn/kernel-fix-tutorial.rst+++ b/Documentation/upatches/learn/kernel-fix-tutorial.rst@@ -416,10 +416,12 @@ Append its tree entry to a tree that targets follow:.. code-block:: consoleoperator$ shirudo bpm tree append rpl-shield-1.0.0.bee \- oci://<registry>/<namespace>/<tree> --keys-dir <keys-dir>+ oci://<registry>/<namespace>/<tree> --tree-id <tree-id> \+ --keys-dir <keys-dir>``<registry>`` and ``<namespace>`` name your registry and repository path,-and ``<tree>`` the repository of the tree. ``bpm push`` prints the pushed+``<tree>`` the repository of the tree and ``<tree-id>`` its id, which an+append to an existing tree must name. ``bpm push`` prints the pushedreference, ``bpm tree append`` the tree's reference and manifest digest.A package signed with the test bundle's key is for test targets only.Sign what a fleet runs with your own key.diff --git a/Documentation/upatches/publish/publishing.rst b/Documentation/upatches/publish/publishing.rstindex 5bd18c26..259d1897 100644--- a/Documentation/upatches/publish/publishing.rst+++ b/Documentation/upatches/publish/publishing.rst@@ -110,7 +110,8 @@ Append it to the tree.. code-block:: consoleoperator$ shirudo bpm tree append <name>-<version>.bee \- oci://<registry>/<namespace>/<tree> --keys-dir <keys-dir>+ oci://<registry>/<namespace>/<tree> --tree-id <tree-id> \+ --keys-dir <keys-dir>``<tree>`` is the tree's repository. The command fetches the currentpublication at ``<tree>:stable`` and verifies its signature against@@ -124,8 +125,11 @@ Append it to the treeas it was, its ``fixes`` included.A repository without a publication starts a new tree at generation 1,- with the package name as tree id or the id ``--tree-id`` gives. For an- existing tree, ``--tree-id`` must name the id it has. ``--reference+ with the id ``--tree-id`` gives, else the package name at ``stable``+ and ``<package>-<reference>`` at another reference, so that a canary+ tree has an id of its own. To extend an existing tree, ``--tree-id``+ must name the id it has, from your own records: a registry that serves+ another tree your key signs at that reference is refused. ``--reference<ref>`` publishes to another tag than ``stable``, such as a canarytree.@@ -134,7 +138,8 @@ Append it to the tree.. code-block:: consoleoperator$ shirudo bpm tree append <name>-<version>.bee \- oci://<registry>/<namespace>/<tree> --keys-dir <keys-dir> --op delete+ oci://<registry>/<namespace>/<tree> --tree-id <tree-id> \+ --keys-dir <keys-dir> --op deleteNothing is ever removed from the tree: a ``delete`` is a new operationafter the ``add``, and carries no ``fixes``. To replace a loadeddiff --git a/testing/functional/bpm/t7005-bpm-publish.sh b/testing/functional/bpm/t7005-bpm-publish.shindex 0c2933c6..97837e53 100644--- a/testing/functional/bpm/t7005-bpm-publish.sh+++ b/testing/functional/bpm/t7005-bpm-publish.sh@@ -436,7 +436,7 @@ PYtest_expect_success 'a delete append chains on the previous publication' '"$S" bpm tree append "$WORK/t7005-1.0.0.bee" "oci://$REGISTRY/ns/tree" \- --keys-dir "$WORK/keys" --op delete >/dev/null 2>&1 &&+ --tree-id t7005 --keys-dir "$WORK/keys" --op delete >/dev/null 2>&1 &&split_layers "$REG/ns/tree/manifests/stable" "$REG/ns/tree" "$WORK/tree2" &&cms_verify "$WORK/tree2.sig" "$WORK/tree2.payload" &&python3 - "$WORK/tree2.payload" "$WORK/tree1.manifest" "$WORK/tree1.payload" "$WORK/unload.json" <<'"'"'PY'"'"'@@ -455,9 +455,15 @@ assert op["artifact"]["payload_sha256"] == "sha256:" + unload["payload_sha256"],PY'-test_expect_success 'tree append refuses a different tree id and a package without tree entries' '+test_expect_success 'tree append refuses another tree id, none, and a package without tree entries' '! "$S" bpm tree append "$WORK/t7005-1.0.0.bee" "oci://$REGISTRY/ns/tree" \- --keys-dir "$WORK/keys" --tree-id other >/dev/null 2>&1 &&+ --keys-dir "$WORK/keys" --tree-id other >/dev/null 2>"$WORK/other.err" &&+ grep -q "holds tree t7005, not other; refusing to extend another tree" \+ "$WORK/other.err" &&+ ! "$S" bpm tree append "$WORK/t7005-1.0.0.bee" "oci://$REGISTRY/ns/tree" \+ --keys-dir "$WORK/keys" >/dev/null 2>"$WORK/noid.err" &&+ grep -q "holds tree t7005; name the tree to extend with --tree-id" \+ "$WORK/noid.err" &&python3 - "$WORK" <<'"'"'PY'"'"'import io, pathlib, sys, tarfilework = pathlib.Path(sys.argv[1])@@ -473,7 +479,7 @@ with tarfile.open(fileobj=body, mode="w:gz", format=tarfile.USTAR_FORMAT) as tar(work / "plain.bee").write_bytes(body.getvalue())PY! "$S" bpm tree append "$WORK/plain.bee" "oci://$REGISTRY/ns/tree" \- --keys-dir "$WORK/keys" >/dev/null 2>"$WORK/plain.err" &&+ --tree-id t7005 --keys-dir "$WORK/keys" >/dev/null 2>"$WORK/plain.err" &&grep -q "no \[upatches.tree\] entries" "$WORK/plain.err"'@@ -568,7 +574,8 @@ test_expect_success 'the operator commands are reachable directly in shirudo-buitest_expect_success 'tree append needs readable signing material' '! "$S" bpm tree append "$WORK/t7005-1.0.0.bee" "oci://$REGISTRY/ns/tree" \- --key "$WORK/missing.pem" --cert "$WORK/keys/cert.der" >/dev/null 2>&1+ --tree-id t7005 --key "$WORK/missing.pem" \+ --cert "$WORK/keys/cert.der" >/dev/null 2>&1'test_expect_success 'a new signing key does not silently replace the previous tree signer' '@@ -576,13 +583,13 @@ test_expect_success 'a new signing key does not silently replace the previous tropenssl x509 -inform DER -in "$WORK/next-key/cert.der" -out "$WORK/next-key.pem" &&cp "$REG/ns/tree/manifests/stable" "$WORK/before-rotation.manifest" &&! "$S" bpm tree append "$WORK/t7005-1.0.0.bee" "oci://$REGISTRY/ns/tree" \- --keys-dir "$WORK/next-key" >/dev/null 2>&1 &&+ --tree-id t7005 --keys-dir "$WORK/next-key" >/dev/null 2>&1 &&cmp "$REG/ns/tree/manifests/stable" "$WORK/before-rotation.manifest"'test_expect_success 'previous-cert verifies A while B signs the next publication' '"$S" bpm tree append "$WORK/t7005-1.0.0.bee" "oci://$REGISTRY/ns/tree" \- --keys-dir "$WORK/next-key" --previous-cert "$WORK/keys/cert.der" >/dev/null &&+ --tree-id t7005 --keys-dir "$WORK/next-key" --previous-cert "$WORK/keys/cert.der" >/dev/null &&split_layers "$REG/ns/tree/manifests/stable" "$REG/ns/tree" "$WORK/rotated" &&cms_verify "$WORK/rotated.sig" "$WORK/rotated.payload" "$WORK/next-key.pem" &&! cms_verify "$WORK/rotated.sig" "$WORK/rotated.payload" &&@@ -597,7 +604,7 @@ PYTESTtest_expect_success 'later B publications use B to verify the predecessor by default' '"$S" bpm tree append "$WORK/t7005-1.0.0.bee" "oci://$REGISTRY/ns/tree" \- --keys-dir "$WORK/next-key" >/dev/null &&+ --tree-id t7005 --keys-dir "$WORK/next-key" >/dev/null &&split_layers "$REG/ns/tree/manifests/stable" "$REG/ns/tree" "$WORK/after-rotation" &&cms_verify "$WORK/after-rotation.sig" "$WORK/after-rotation.payload" "$WORK/next-key.pem" &&python3 -c "import json, sys; p=json.load(open(sys.argv[1])); assert p[\"generation\"] == 4" \@@ -607,7 +614,7 @@ test_expect_success 'later B publications use B to verify the predecessor by deftest_expect_success 'a wrong explicit predecessor certificate leaves the tree unchanged' 'cp "$REG/ns/tree/manifests/stable" "$WORK/rotated.manifest" &&! "$S" bpm tree append "$WORK/t7005-1.0.0.bee" "oci://$REGISTRY/ns/tree" \- --keys-dir "$WORK/next-key" --previous-cert="$WORK/keys/cert.der" >/dev/null 2>&1 &&+ --tree-id t7005 --keys-dir "$WORK/next-key" --previous-cert="$WORK/keys/cert.der" >/dev/null 2>&1 &&cmp "$REG/ns/tree/manifests/stable" "$WORK/rotated.manifest"'diff --git a/testing/functional/bpm/t7007-bpm-tree-fixes.sh b/testing/functional/bpm/t7007-bpm-tree-fixes.shindex f1bffe81..d95e4ef0 100644--- a/testing/functional/bpm/t7007-bpm-tree-fixes.sh+++ b/testing/functional/bpm/t7007-bpm-tree-fixes.sh@@ -87,7 +87,7 @@ TREE="oci://127.0.0.1:$PORT/ns/tree"append() {pkg=$1shift- "$S" bpm tree append "$WORK/$pkg-1.0.0.bee" "$TREE" \+ "$S" bpm tree append "$WORK/$pkg-1.0.0.bee" "$TREE" --tree-id t7007a \--keys-dir "$WORK/keys" "$@" >/dev/null 2>"$WORK/append.err" &&python3 - "$REG/ns/tree" "$WORK" <<'PY'import json, pathlib, sys@@ -223,7 +223,7 @@ PYrefused() {malformed "$1" "$2" &&cp "$REG/ns/tree/manifests/stable" "$WORK/bad.manifest" &&- ! "$S" bpm tree append "$WORK/t7007b-1.0.0.bee" "$TREE" \+ ! "$S" bpm tree append "$WORK/t7007b-1.0.0.bee" "$TREE" --tree-id t7007a \--keys-dir "$WORK/keys" >/dev/null 2>"$WORK/bad.err" &&grep -q "has a fixes list bpm tree append would not write" \"$WORK/bad.err" &&diff --git a/testing/functional/bpm/t7008-bpm-tree-show.sh b/testing/functional/bpm/t7008-bpm-tree-show.shindex 5600b7e6..148a0c61 100755--- a/testing/functional/bpm/t7008-bpm-tree-show.sh+++ b/testing/functional/bpm/t7008-bpm-tree-show.sh@@ -149,6 +149,18 @@ test_expect_success 'show refuses a reference that does not exist' '--reference absent'+test_expect_success 'append refuses the tree of another reference served in place' '+ cp "$REG/ns/tree/manifests/stable" "$WORK/stable" &&+ cp "$REG/ns/tree/manifests/beta" "$REG/ns/tree/manifests/stable" &&+ registry_sum >"$WORK/before" &&+ ! "$S" bpm tree append "$WORK/t7008-1.0.0.bee" "$TREE" \+ --tree-id t7008 --keys-dir "$WORK/keys" >"$WORK/out" 2>"$WORK/err" &&+ grep -q "holds tree t7008-beta, not t7008;" "$WORK/err" &&+ registry_sum >"$WORK/after" &&+ cmp -s "$WORK/before" "$WORK/after" &&+ cp "$WORK/stable" "$REG/ns/tree/manifests/stable"+'+test_expect_success 'show refuses a wrong certificate' 'refused "Key was rejected by service" "$TREE" \--cert "$WORK/other/cert.der"@@ -272,8 +284,8 @@ test_expect_success 'tree append with --segment-ops 1 seals a segment per appendn=0 &&for op in add delete add; do"$S" bpm tree append "$WORK/t7008-1.0.0.bee" "$SEGS" \- --keys-dir "$WORK/keys" --segment-ops 1 --op "$op" \- >/dev/null || return 1+ --tree-id t7008 --keys-dir "$WORK/keys" --segment-ops 1 \+ --op "$op" >/dev/null || return 1n=$((n + 1)) &&cp "$REG/ns/segs/manifests/stable" "$WORK/g$n" || return 1donediff --git a/testing/functional/bpm/t7009-bpm-tree-seal.sh b/testing/functional/bpm/t7009-bpm-tree-seal.shindex 2fbde739..bfa5ac41 100755--- a/testing/functional/bpm/t7009-bpm-tree-seal.sh+++ b/testing/functional/bpm/t7009-bpm-tree-seal.sh@@ -105,8 +105,8 @@ append() {pkg=$1 tree=$2shift 2"$S" bpm tree append "$WORK/$pkg-1.0.0.bee" \- "oci://127.0.0.1:$PORT/ns/$tree" --keys-dir "$WORK/keys" "$@" \- >"$WORK/out" 2>"$WORK/err"+ "oci://127.0.0.1:$PORT/ns/$tree" --tree-id "$tree" \+ --keys-dir "$WORK/keys" "$@" >"$WORK/out" 2>"$WORK/err"}# The checks of the segments of a tree, read from the registry files.@@ -314,7 +314,7 @@ synthetic() {ops.append(o)if bad:ops[-1]["operation_digest"] = ops[0]["operation_digest"]- doc = {"schema": 1, "tree_id": "t7009a", "generation": 1,+ doc = {"schema": 1, "tree_id": sys.argv[3], "generation": 1,"base": {"seq": 0}, "operations": ops, "head": {"seq": n}}(work / "synthetic.json").write_bytes(json.dumps(doc, separators=(",", ":")).encode())diff --git a/tools/shirudo-build/bpm-publish.c b/tools/shirudo-build/bpm-publish.cindex 8f4fd6a9..7daf0554 100644--- a/tools/shirudo-build/bpm-publish.c+++ b/tools/shirudo-build/bpm-publish.c@@ -55,6 +55,7 @@ static void tree_append_usage(void)" [--segment-ops <n>]\n\n""Publishes the [upatches.tree] entries of a built package as the next\n""operations of the signed tree at <repository>:<ref> (default stable).\n"+ "Extending an existing tree needs --tree-id naming it.\n""A segment that holds --segment-ops operations (default %d, 1 to %d)\n""is sealed and the entries start the next one.\n""The key defaults to --keys-dir, SHIRUDO_KEYS_DIR or %s.\n",@@ -1142,6 +1143,28 @@ static int tree_start_segment(const struct tree_publication *sealed,return ret;}+/*+ * A new tree's id: the one --tree-id gives, else the package's at stable+ * and the package's with the reference elsewhere, so that a canary tree+ * one key publishes beside stable does not take stable's id, which an+ * append checks to tell the two apart.+ */+static int tree_new_id(const char *tree_id, const char *package,+ const char *reference, char *out, size_t cap)+{+ if (tree_id)+ return strscpy(out, tree_id, cap) < 0 ? -E2BIG : 0;+ if (!strcmp(reference, "stable"))+ return strscpy(out, package, cap) < 0 ? -E2BIG : 0;+ if (strsprintf(out, cap, "%s-%s", package, reference) < 0 ||+ !bpm_package_name_ok(out)) {+ pr_err("bpm tree append: %s-%s is no tree id; name the tree with --tree-id",+ package, reference);+ return -EINVAL;+ }+ return 0;+}+static int cmd_bpm_tree_append(int argc, char **argv){const char *package = NULL, *raw_repository = NULL, *keys_dir_arg = NULL;@@ -1305,16 +1328,29 @@ static int cmd_bpm_tree_append(int argc, char **argv)pub = (struct tree_publication){ .schema = 1,.generation = 1 };parent[0] = '\0';- if (tree_id)- bpm_copy_string(pub.tree_id, sizeof(pub.tree_id), tree_id);+ ret = tree_new_id(tree_id, info.name, reference, pub.tree_id,+ sizeof(pub.tree_id));+ if (ret)+ goto out;} else if (ret) {pr_err("bpm tree append: cannot read the publication at %s:%s",repo_ref, reference);goto out;} else {- if (tree_id && strcmp(pub.tree_id, tree_id)) {- pr_err("bpm tree append: tree id mismatch: existing %s, requested %s",- pub.tree_id, tree_id);+ /*+ * The registry chooses what the reference holds, another tree+ * the key signs among it: only the operator can say which tree+ * the signature it is about to make belongs to.+ */+ if (!tree_id) {+ pr_err("bpm tree append: %s:%s holds tree %s; name the tree to extend with --tree-id",+ repo_ref, reference, pub.tree_id);+ ret = -EINVAL;+ goto out;+ }+ if (strcmp(pub.tree_id, tree_id)) {+ pr_err("bpm tree append: %s:%s holds tree %s, not %s; refusing to extend another tree",+ repo_ref, reference, pub.tree_id, tree_id);ret = -EINVAL;goto out;}@@ -1344,8 +1380,6 @@ static int cmd_bpm_tree_append(int argc, char **argv)}}pub.schema = 1;- if (!pub.tree_id[0])- bpm_copy_string(pub.tree_id, sizeof(pub.tree_id), info.name);bpm_copy_string(pub.parent_manifest_digest,sizeof(pub.parent_manifest_digest), parent);