Skip to content

eBPF-based security platform

testing/vm: write the stack's settings to a file a shell sources

John Fastabend61ec1d5d946f
diff --git a/Documentation/contribute/testing/testing.rst b/Documentation/contribute/testing/testing.rst
index 0862f43a..3f04b23b 100644
--- a/Documentation/contribute/testing/testing.rst
+++ b/Documentation/contribute/testing/testing.rst
@@ -762,6 +762,15 @@ storage.
``make stack-up`` is shorthand for ``make oci telemetry``. Start the VM
with ``make vm``.
+Each of the three writes ``build/test-vm/stack/env``, and ``make
+stack-up`` ends with a ``Shell:`` line that names it. A shell that reads
+the file, ``. build/test-vm/stack/env``, has the checkout's ``shirudo``
+and ``shirudo-build`` on ``PATH``, the bundle's operator key directory
+in ``KEYS``, the stack's CA in ``BPM_OCI_CA_FILE``, the tree the VM
+follows in ``TREE`` and the stack's ClickHouse client in
+``CLICKHOUSE_CLIENT``, as the commands of :doc:`/start/guides/index`
+use them.
+
``make telemetry`` and ``make stack-up`` first build
``tools/quote-check/shirudo-quote-check``, as ``make quote-check`` does,
and turn that ClickHouse into a keepalive backend with it: they install
diff --git a/testing/Makefile b/testing/Makefile
index ecfa272a..db15d398 100644
--- a/testing/Makefile
+++ b/testing/Makefile
@@ -458,6 +458,7 @@ clean:
.PHONY: oci telemetry stack-up stack-down xtop shields
stack-up: oci telemetry
+ $(Q)TEST_VM_HOST_PRIVATE_DIR="$(TEST_VM_HOST_PRIVATE_DIR)" $(ROOT)/testing/vm/stack.sh env
oci telemetry:
$(Q)TEST_VM_HOST_PRIVATE_DIR="$(TEST_VM_HOST_PRIVATE_DIR)" $(ROOT)/testing/vm/stack.sh $@
diff --git a/testing/vm/stack.sh b/testing/vm/stack.sh
index 6e37a4b1..d3899fbb 100755
--- a/testing/vm/stack.sh
+++ b/testing/vm/stack.sh
@@ -22,7 +22,7 @@ fi
exec 9>"$W/.lock"
flock 9
case "$TLS_DIR/" in "$REPO/"*) echo 'stack private keys must be outside the checkout' >&2; exit 1 ;; esac
-command=${1:?usage: stack.sh prepare|oci|telemetry|down|enroll|sbom|shields|xtop|vm}
+command=${1:?usage: stack.sh prepare|oci|telemetry|env|down|enroll|sbom|shields|xtop|vm}
shift
prepare()
{
@@ -33,11 +33,33 @@ prepare()
fi
}
+quoted()
+{
+ printf "'%s'" "$(printf '%s' "$1" | sed "s/'/'\\\\''/g")"
+}
+
+# What a shell needs to run the guides' commands against the stack, in a
+# file it sources: make cannot set a variable in the shell that ran it.
+write_env()
+{
+ cat >"$W/env.tmp" <<-EOF
+ export PATH=$(quoted "$REPO:$REPO/tools/shirudo-build"):"\$PATH"
+ KEYS=$(quoted "${TEST_VM_HOST_PRIVATE_DIR:?}/operator-keys/keys")
+ export BPM_OCI_CA_FILE=$(quoted "$W/ca.pem")
+ TREE=oci://$REGISTRY/shirudo/local-tree
+ export CLICKHOUSE_CLIENT='docker exec -i $STACK_NAME-clickhouse clickhouse-client'
+ EOF
+ [ "$(id -u)" != 0 ] || chown "$owner" "$W/env.tmp"
+ mv -- "$W/env.tmp" "$W/env"
+}
+
case "$command" in
prepare) prepare ;;
-oci) prepare; stack_oci; printf 'OCI: oci://%s (CA: %s/ca.pem)\n' "$REGISTRY" "$W" ;;
+env) prepare; write_env; printf 'Shell: . %s/env\n' "$W" ;;
+oci) prepare; write_env; stack_oci; printf 'OCI: oci://%s (CA: %s/ca.pem)\n' "$REGISTRY" "$W" ;;
telemetry)
prepare
+ write_env
checker=$REPO/tools/quote-check/shirudo-quote-check
if [ -x "$checker" ]; then
stack_telemetry "$REPO/testing/vm/otelcol-stack.yaml" \