Skip to content

eBPF-based security platform

bpm: start a repository index only when asked to

Daniel Borkmann6624819d5234
diff --git a/Documentation/contribute/code/develop-locally.rst b/Documentation/contribute/code/develop-locally.rst
index 663e0ea4..179341a4 100644
--- a/Documentation/contribute/code/develop-locally.rst
+++ b/Documentation/contribute/code/develop-locally.rst
@@ -324,9 +324,12 @@ Build and publish it
.. code-block:: console
- operator$ BPM_OCI_SCHEME=http shirudo bpm push "$DEV/exec-count-1.0.0.bee" oci://127.0.0.1:5000/dev/exec-count --keys-dir "$KEYS"
+ operator$ BPM_OCI_SCHEME=http shirudo bpm push "$DEV/exec-count-1.0.0.bee" oci://127.0.0.1:5000/dev/exec-count --keys-dir "$KEYS" --new-index
oci://127.0.0.1:5000/dev/exec-count:1.0.0
+ ``--new-index`` starts the registry's index with this first package;
+ later pushes to the namespace leave it out.
+
The index holds one package per version. A package built again under
a version the index lists already is refused with ``bpm push: the
repository index already lists exec-count 1.0.0 with different
diff --git a/Documentation/reference/cheat-sheet.rst b/Documentation/reference/cheat-sheet.rst
index 76184954..7e8200e7 100644
--- a/Documentation/reference/cheat-sheet.rst
+++ b/Documentation/reference/cheat-sheet.rst
@@ -205,6 +205,9 @@ Publish a package and add it to the registry's signed index with
operator$ shirudo bpm push ./kernel-obs-1.0.0.bee oci://quay.io/example/kernel-obs --keys-dir ~/shirudo-keys
+Add ``--new-index`` for the first package of a namespace, which has no
+index yet.
+
Build the next version with a new ``.rodata`` input with :doc:`bpm config
update <cli/bpm>`. ``watch`` names the Beefile input ``watch.list``:
diff --git a/Documentation/reference/cli/bpm.rst b/Documentation/reference/cli/bpm.rst
index e5854a75..0a67ac65 100644
--- a/Documentation/reference/cli/bpm.rst
+++ b/Documentation/reference/cli/bpm.rst
@@ -38,6 +38,7 @@ Usage
shirudo bpm info data <package> <member> [--json]
shirudo bpm push <package> oci://<registry>/<repository>
[--keys-dir <dir> | --index-cert <certificate> --index-key <signing-key>]
+ [--new-index]
shirudo bpm build [<context>] --version <version> [--file <beefile>]
[--keys-dir <dir>] [--vmlinux <vmlinux-h>]
[--rodata-input <name>=<path>]...
@@ -270,6 +271,13 @@ derived from the package repository path. Without signing options only the
package is published. ``push`` does not read ``SHIRUDO_KEYS_DIR``. Its
options take the value as the next argument or after ``=``.
+``push`` refuses a namespace without an index unless ``--new-index`` is
+given, and refuses ``--new-index`` where an index exists. The operator
+keeps no state, so a registry that answers that it has no index cannot
+be told from one that never had any, and the index signed then would
+leave out every package listed before. Pass ``--new-index`` for the first
+package of a namespace alone.
+
build
-----
diff --git a/Documentation/security/threat-model.rst b/Documentation/security/threat-model.rst
index 18aea7be..af417597 100644
--- a/Documentation/security/threat-model.rst
+++ b/Documentation/security/threat-model.rst
@@ -1373,8 +1373,12 @@ R8 Registry withholding and replay
the last index that verifies, and nothing orders one index before
another or binds it to the registry it came from. ``shirudo bpm
list`` shows the target's own state, and a repository update is not
- measured. Detection: compare the upatch payloads and tree operations
- that ``attest verify`` certifies with what you published.
+ measured. ``bpm push`` builds the next index from the one the registry
+ serves, so an older one makes the operator sign an index without the
+ packages added since; a registry that claims to have none is refused
+ unless ``--new-index`` is given. Detection: compare the upatch payloads
+ and tree operations that ``attest verify`` certifies with what you
+ published, and the pushed index with the versions you released.
R9 Classical pieces
The WebPKI certificates of registries and collectors authenticate
diff --git a/Documentation/start/guides/publish-package.rst b/Documentation/start/guides/publish-package.rst
index ad06df0b..be0a5e67 100644
--- a/Documentation/start/guides/publish-package.rst
+++ b/Documentation/start/guides/publish-package.rst
@@ -117,13 +117,14 @@ Publish it
.. code-block:: console
- operator$ BPM_OCI_SCHEME=http shirudo bpm push hello-1.0.0.bee oci://127.0.0.1:5000/example/hello --keys-dir "$KEYS"
+ operator$ BPM_OCI_SCHEME=http shirudo bpm push hello-1.0.0.bee oci://127.0.0.1:5000/example/hello --keys-dir "$KEYS" --new-index
oci://127.0.0.1:5000/example/hello:1.0.0
The push tags the package with its version. With ``--keys-dir``, it
also adds the package to the registry's signed index,
``<namespace>/bpm-index:stable``, which targets read when they install from
- a registered repository. ``BPM_OCI_SCHEME=http`` drops TLS, which suits
+ a registered repository. ``--new-index`` starts that index, as this is
+ the namespace's first package; later pushes leave it out. ``BPM_OCI_SCHEME=http`` drops TLS, which suits
only a registry on your own host. Without it, shirudo speaks HTTPS with
TLS 1.3 and a hybrid ML-KEM key exchange.
diff --git a/Documentation/upatches/publish/publishing.rst b/Documentation/upatches/publish/publishing.rst
index 20dfb395..cb511d6d 100644
--- a/Documentation/upatches/publish/publishing.rst
+++ b/Documentation/upatches/publish/publishing.rst
@@ -83,6 +83,11 @@ Push it to a repository
prints the pushed reference,
``oci://<registry>/<namespace>/<name>:<version>``.
+ The first package of a namespace needs ``--new-index``: ``bpm push``
+ refuses a namespace without an index otherwise, so that a registry that
+ hides the index cannot have you sign one without the packages it
+ listed. ``--new-index`` is refused where an index exists.
+
Without ``--keys-dir``, or ``--index-cert`` and ``--index-key``, the
command pushes the package and moves the version tag, but leaves the
index unchanged and does not check that the version is new. Targets
diff --git a/completion/shirudo.bash b/completion/shirudo.bash
index e987f8a0..fc340dd6 100644
--- a/completion/shirudo.bash
+++ b/completion/shirudo.bash
@@ -163,7 +163,7 @@ _shirudo()
$(compgen -d -- "$cur") )
elif [[ $sub == push && $cur == -* ]]; then
COMPREPLY=( $(compgen -W "--keys-dir --index-cert \
- --index-key" -- "$cur") )
+ --index-key --new-index" -- "$cur") )
elif [[ $sub == push ]]; then
COMPREPLY=( $(compgen -f -X '!*.bee' -- "$cur") \
$(compgen -d -- "$cur") )
diff --git a/testing/end2end/host.sh b/testing/end2end/host.sh
index 84c86e9e..f7661ac9 100755
--- a/testing/end2end/host.sh
+++ b/testing/end2end/host.sh
@@ -123,7 +123,8 @@ id = "kernel-obs"\
role = ["end2end"]' "$W/pkg/kernel-obs/Beefile"
(cd "$W/pkg" && "$S" bpm build kernel-obs --version 1.0.0 --keys-dir "$KEYS")
BEE=$W/pkg/kernel-obs-1.0.0.bee
-"$S" bpm push "$BEE" "oci://$REGISTRY/shirudo/kernel-obs" --keys-dir "$KEYS"
+"$S" bpm push "$BEE" "oci://$REGISTRY/shirudo/kernel-obs" --keys-dir "$KEYS" \
+ --new-index
"$S" bpm tree append "$BEE" "oci://$REGISTRY/shirudo/end2end-tree" \
--keys-dir "$KEYS"
tar -xzf "$BEE" -C "$W/pkg"
diff --git a/testing/functional/bpm/t7005-bpm-publish.sh b/testing/functional/bpm/t7005-bpm-publish.sh
index ad8355ab..76a0a30e 100644
--- a/testing/functional/bpm/t7005-bpm-publish.sh
+++ b/testing/functional/bpm/t7005-bpm-publish.sh
@@ -181,9 +181,22 @@ pathlib.Path(f"{out}.artifact_type").write_text(manifest["artifactType"])
PY
}
+# A registry that answers 404 for the index cannot be told from a namespace
+# that never had one, and the operator would sign an index without every
+# package it held: starting one takes --new-index.
+test_expect_success 'bpm push refuses a namespace without an index unless told to start one' '
+ ! "$S" bpm push "$WORK/t7005-1.0.0.bee" "oci://$REGISTRY/ns/t7005" \
+ --keys-dir "$WORK/keys" >/dev/null 2>"$WORK/noindex.err" &&
+ grep -q "has no repository index; pass --new-index" "$WORK/noindex.err" &&
+ ! test -e "$REG/ns/bpm-index/manifests/stable" &&
+ ! "$S" bpm push "$WORK/t7005-1.0.0.bee" "oci://$REGISTRY/ns/t7005" \
+ --new-index >/dev/null 2>"$WORK/noindex2.err" &&
+ grep -q "new-index needs --keys-dir" "$WORK/noindex2.err"
+'
+
test_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" >"$WORK/push.out" 2>"$WORK/push.err" &&
+ --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" &&
test -s "$REG/ns/t7005/manifests/1.0.0" &&
test -s "$REG/ns/bpm-index/manifests/stable" &&
@@ -250,6 +263,14 @@ test_expect_success 'push without signing material leaves the index untouched' '
cmp -s "$WORK/index3.payload" "$WORK/index4.payload"
'
+test_expect_success 'push refuses to start an index where one exists' '
+ ! "$S" bpm push "$WORK/t7005-2.0.0.bee" "oci://$REGISTRY/ns/t7005" \
+ --keys-dir "$WORK/keys" --new-index >/dev/null 2>"$WORK/newindex.err" &&
+ grep -q "has a repository index already" "$WORK/newindex.err" &&
+ split_layers "$REG/ns/bpm-index/manifests/stable" "$REG/ns/bpm-index" "$WORK/index5" &&
+ cmp -s "$WORK/index3.payload" "$WORK/index5.payload"
+'
+
test_expect_success 'push refuses half of the index signing pair' '
! "$S" bpm push "$WORK/t7005-2.0.0.bee" "oci://$REGISTRY/ns/t7005" \
--index-cert "$WORK/keys/cert.der" >/dev/null 2>&1
diff --git a/tools/shirudo-build/bpm-publish.c b/tools/shirudo-build/bpm-publish.c
index 7933d72c..e8cb294d 100644
--- a/tools/shirudo-build/bpm-publish.c
+++ b/tools/shirudo-build/bpm-publish.c
@@ -114,7 +114,7 @@ static int index_repository_for_package(const char *repository, char *out, size_
return 0;
}
-/* A registry without an index yields an empty one. */
+/* -ENOENT when the registry has no index there. */
static int fetch_index(struct bpm_oci_client *c, const char *repository,
const char *cert,
struct bpm_index_entry *entries, int *n)
@@ -130,8 +130,6 @@ static int fetch_index(struct bpm_oci_client *c, const char *repository,
if (ret)
return ret;
ret = bpm_oci_get_memory(c, url, BPM_MANIFEST_MEDIA, &manifest);
- if (ret == -ENOENT)
- return 0;
if (ret)
return ret;
layers = xcalloc(BPM_MAX_ENTRIES, sizeof(*layers));
@@ -192,14 +190,17 @@ out:
/*
* Add or refresh the package's entry in the signed index beside its
* repository namespace. A version already listed with different content
- * is refused: published versions are immutable.
+ * is refused: published versions are immutable. The operator keeps no
+ * state, so only new_index tells a namespace without an index from a
+ * registry that hides one: the index pushed then would be signed without
+ * every package listed before.
*/
static int push_index(struct bpm_oci_client *c, const char *index_repository,
const char *repository,
const struct bpm_package_info *info,
const char *manifest_digest,
const struct bpm_descriptor *layer,
- const char *key, const char *cert)
+ const char *key, const char *cert, bool new_index)
{
struct bpm_descriptor config, payload_layer, sig_layer;
struct bpm_index_entry *entries, *entry = NULL;
@@ -216,6 +217,16 @@ static int push_index(struct bpm_oci_client *c, const char *index_repository,
if (!entries)
return -ENOMEM;
ret = fetch_index(c, index_repository, cert, entries, &n);
+ if (ret == -ENOENT && new_index) {
+ ret = 0;
+ } else if (ret == -ENOENT) {
+ pr_err("bpm push: %s has no repository index; pass --new-index to start one, and only for a namespace that never had one",
+ index_repository);
+ } else if (!ret && new_index) {
+ pr_err("bpm push: %s has a repository index already; --new-index starts one only where there is none",
+ index_repository);
+ ret = -EEXIST;
+ }
if (ret)
goto out;
for (int i = 0; i < n; i++) {
@@ -330,7 +341,7 @@ out:
static int push_package(const char *package_path, const char *raw_repository,
const char *index_key, const char *index_cert,
- const char **reference_out)
+ bool new_index, const char **reference_out)
{
struct bpm_oci_client c __cleanup(bpm_oci_client_clear) = {};
struct bpm_package_info info = {};
@@ -490,7 +501,8 @@ static int push_package(const char *package_path, const char *raw_repository,
goto out;
if (index_key && index_cert) {
ret = push_index(&c, index_repository, repository, &info,
- package_digest, &layer, index_key, index_cert);
+ package_digest, &layer, index_key, index_cert,
+ new_index);
if (ret)
goto out;
}
@@ -892,11 +904,13 @@ static void bpm_push_usage(void)
fprintf(stderr,
"usage: shirudo bpm push <package-file> <repository>\n"
" [--keys-dir <dir> | --index-cert <cert.der>\n"
- " --index-key <signing_key.pem>]\n\n"
+ " --index-key <signing_key.pem>] [--new-index]\n\n"
"The repository must start with oci:// and must not include a tag.\n"
"With signing material the registry's signed index at\n"
"<namespace>/bpm-index:stable gains the package entry, signed with the\n"
- "operator key; without it only the package is published.\n"
+ "operator key; without it only the package is published. A namespace\n"
+ "without an index is refused unless --new-index starts one, which in\n"
+ "turn is refused where an index exists.\n"
"Examples:\n"
" shirudo bpm push ./package.bee oci://quay.io/namespace/package\n"
" shirudo bpm push ./package.bee oci://quay.io/namespace/package \\\n"
@@ -908,6 +922,7 @@ int build_bpm_push(int argc, char **argv)
const char *package = NULL, *repository = NULL, *reference = NULL;
const char *keys_dir_arg = NULL, *index_cert = NULL, *index_key = NULL;
char cert_path[PATH_MAX], key_path[PATH_MAX];
+ bool new_index = false;
int ret;
if (argc == 2 && build_is_help(argv[1])) {
@@ -929,6 +944,8 @@ int build_bpm_push(int argc, char **argv)
index_key = argv[++i];
} else if (!strncmp(a, "--index-key=", 12)) {
index_key = a + 12;
+ } else if (!strcmp(a, "--new-index")) {
+ new_index = true;
} else if (a[0] == '-' || (package && repository)) {
bpm_push_usage();
return 2;
@@ -959,11 +976,16 @@ int build_bpm_push(int argc, char **argv)
pr_err("bpm push: --index-cert and --index-key must be supplied together");
return 2;
}
+ if (new_index && !index_key) {
+ pr_err("bpm push: --new-index needs --keys-dir, or --index-cert and --index-key");
+ return 2;
+ }
if (index_key && build_check_keys(index_key, index_cert))
return 1;
if (curl_global_init(CURL_GLOBAL_DEFAULT) != CURLE_OK)
return publish_fail("initialize curl", -EIO);
- ret = push_package(package, repository, index_key, index_cert, &reference);
+ ret = push_package(package, repository, index_key, index_cert,
+ new_index, &reference);
curl_global_cleanup();
if (ret)
return publish_fail("push", ret);