Skip to content

eBPF-based security platform

bpm: take --cert in register add and refuse any other option

Daniel Borkmann3876291d969f
diff --git a/Documentation/reference/cli/bpm.rst b/Documentation/reference/cli/bpm.rst
index 47317cbc..da5c6261 100644
--- a/Documentation/reference/cli/bpm.rst
+++ b/Documentation/reference/cli/bpm.rst
@@ -21,7 +21,7 @@ Usage
.. code-block:: none
- shirudo bpm config register add <source> oci://<registry> [--index-repository <repository>] (--key-file <certificate> | --key-file=<certificate>)
+ shirudo bpm config register add <source> oci://<registry> [--index-repository <repository>] (--cert <certificate> | --cert=<certificate>)
shirudo bpm config register list
shirudo bpm config register (remove | rm) <source>
shirudo bpm config update --base-package <package> --version <version>
@@ -133,8 +133,8 @@ image, the image's ``etc/shirudo/bpm/registries.d/`` is used instead, and
image mode: change repository definitions and keys in a signed config image, then run `shirudo image update`
- ``add`` checks that the endpoint is ``oci://<host>[:<port>]`` without a
- path, checks ``--index-repository`` and that ``--key-file`` is a
- certificate. It copies the certificate to
+ path, checks ``--index-repository`` and that ``--cert`` is a
+ certificate, and refuses any other option. It copies the certificate to
``/etc/shirudo/bpm/keys/<source>.der`` and writes the source file.
- ``list`` prints the registered source names, one per line.
- ``remove`` and ``rm`` delete the source file and its certificate.
diff --git a/builtin-bpm.c b/builtin-bpm.c
index d3021e4a..57be9c5c 100644
--- a/builtin-bpm.c
+++ b/builtin-bpm.c
@@ -1562,8 +1562,8 @@ static int cmd_bpm_config(int argc, const char **argv)
if (!op || is_help(op)) {
fprintf(stderr,
"usage: shirudo bpm config register add <source> "
- "oci://<registry> --index-repository <repository> "
- "--key-file <certificate>\n"
+ "oci://<registry> [--index-repository <repository>] "
+ "--cert <certificate>\n"
" shirudo bpm config register {list|remove} ...\n"
" shirudo bpm config update --base-package "
"<package.bee|oci://host/repo:tag> --version <version> "
@@ -1670,6 +1670,10 @@ static int cmd_bpm_config(int argc, const char **argv)
return 2;
} else if (!strcmp(argv[i], "--index-repository")) {
return 2;
+ } else {
+ pr_err("bpm: register add: unknown option '%s'",
+ argv[i]);
+ return 2;
}
}
if (!s.index_repository[0] &&
@@ -1683,8 +1687,7 @@ static int cmd_bpm_config(int argc, const char **argv)
source_index_repository_valid(s.endpoint,
s.index_repository)) {
cert_free(&cert);
- pr_err("bpm: register add requires a valid endpoint, index "
- "repository and --key-file certificate");
+ pr_err("bpm: register add requires a valid endpoint, index repository and --cert certificate");
return 2;
}
cert_free(&cert);
diff --git a/testing/functional/bpm/t7001-bpm-cli.sh b/testing/functional/bpm/t7001-bpm-cli.sh
index 1b2a9275..c0d8dff4 100644
--- a/testing/functional/bpm/t7001-bpm-cli.sh
+++ b/testing/functional/bpm/t7001-bpm-cli.sh
@@ -60,6 +60,15 @@ test_expect_success 'bpm tree help covers sync and append' '
! $SHIRUDO bpm tree not-a-command >/dev/null 2>&1
'
+test_expect_success 'bpm config register add takes --cert and refuses other options' '
+ rc=0 &&
+ out=$($SHIRUDO bpm config register add src oci://registry.example \
+ --key-file x.der 2>&1) || rc=$? &&
+ [ "$rc" -eq 2 ] &&
+ echo "$out" | grep -q "unknown option .--key-file." &&
+ $SHIRUDO bpm config --help 2>&1 | grep -q -- "--cert <certificate>"
+'
+
test_expect_success 'bpm uninstall and list validate their arguments' '
! $SHIRUDO bpm uninstall >/dev/null 2>&1 &&
! $SHIRUDO bpm uninstall ../etc >/dev/null 2>&1 &&