Skip to content

eBPF-based security platform

testing: load the backend into the local stack's ClickHouse

John Fastabend50030369114b
diff --git a/Documentation/contribute/testing/testing.rst b/Documentation/contribute/testing/testing.rst
index e4f88994..3622f026 100644
--- a/Documentation/contribute/testing/testing.rst
+++ b/Documentation/contribute/testing/testing.rst
@@ -688,6 +688,26 @@ storage.
``make stack-up`` is shorthand for ``make oci telemetry``. Start the VM
with ``make vm``.
+When ``make quote-check`` has built
+``tools/quote-check/shirudo-quote-check``, ``make telemetry`` also turns
+that ClickHouse into a keepalive backend: it installs the checker as
+``tpm_quote_check`` and loads the schema of :src:`tools/backend/`, and
+its collector runs :src:`testing/vm/otelcol-stack.yaml`, which writes
+every log record into ``otel.otel_logs`` as well, where the backend reads
+the keepalives. The VM then shows in ``shirudo.node_status``, and
+:doc:`/operate/backend/xtop` reads them:
+
+.. code-block:: console
+
+ $ make quote-check
+ $ make stack-up
+ $ make vm
+ $ CLICKHOUSE_URL=http://127.0.0.1:18124/ tools/xtop/dist/xtop
+
+Without the checker it starts the telemetry stack alone and says so. A
+stack started before the checker was built keeps its collector: run
+``make stack-down`` before ``make telemetry`` to add the backend.
+
``make vm`` prepares a stable CA even when neither service is running.
After initialization, it activates the signed ``config-local-stack``
image. That image points telemetry at ``https://10.0.2.2:14319`` and the
diff --git a/Documentation/operate/backend/xtop.rst b/Documentation/operate/backend/xtop.rst
index a44b69f3..ee8c0e72 100644
--- a/Documentation/operate/backend/xtop.rst
+++ b/Documentation/operate/backend/xtop.rst
@@ -39,7 +39,9 @@ Build and run
CLICKHOUSE_PASSWORD=... tools/xtop/dist/xtop
``bun run src/index.tsx`` in :src:`tools/xtop/` runs it without
-building. A user that can only ``SELECT`` from the ``shirudo`` database
+building. Against the local development stack, whose ClickHouse holds
+the backend once ``make quote-check`` has built the checker, the URL is
+``http://127.0.0.1:18124/`` (:ref:`local-dev-stack`). A user that can only ``SELECT`` from the ``shirudo`` database
is enough.
.. list-table::
diff --git a/testing/vm/otelcol-stack.yaml b/testing/vm/otelcol-stack.yaml
new file mode 100644
index 00000000..5f239d0e
--- /dev/null
+++ b/testing/vm/otelcol-stack.yaml
@@ -0,0 +1,34 @@
+# SPDX-License-Identifier: BSD-2-Clause
+# Copyright (c) 2026 Authors of shirudo
+#
+# The collector of the local development stack: what the end-to-end
+# collector writes, and every log record also into otel.otel_logs, where
+# the backend's schema in the same ClickHouse reads the keepalives.
+receivers:
+ otlp:
+ protocols:
+ http:
+ endpoint: 0.0.0.0:4318
+ tls:
+ cert_file: /certs/server.pem
+ key_file: /certs/server.key
+exporters:
+ file:
+ path: /out/otlp.json
+ clickhouse:
+ endpoint: tcp://clickhouse:9000
+ database: shirudo
+ create_schema: true
+ clickhouse/backend:
+ endpoint: tcp://clickhouse:9000
+ database: otel
+ logs_table_name: otel_logs
+ create_schema: false
+service:
+ pipelines:
+ logs:
+ receivers: [otlp]
+ exporters: [file, clickhouse, clickhouse/backend]
+ metrics:
+ receivers: [otlp]
+ exporters: [file, clickhouse]
diff --git a/testing/vm/stack-lib.sh b/testing/vm/stack-lib.sh
index 39559d21..8e3629f4 100644
--- a/testing/vm/stack-lib.sh
+++ b/testing/vm/stack-lib.sh
@@ -79,8 +79,15 @@ stack_oci_log()
docker logs "$STACK_NAME-registry" 2>/dev/null
}
+# The telemetry stack: ClickHouse on $CLICKHOUSE and a collector on
+# $COLLECTOR that runs configuration $1, by default the end-to-end one.
+# With a backend directory $2 and a quote checker $3, ClickHouse also
+# gets the backend's schema, before the collector starts writing to it.
stack_telemetry()
{
+ config=${1:-$REPO/testing/end2end/otelcol.yaml}
+ backend=${2:-}
+ checker=${3:-}
docker network inspect "$STACK_NAME" >/dev/null 2>&1 ||
docker network create "$STACK_NAME" >/dev/null
set --
@@ -95,18 +102,62 @@ stack_telemetry()
[ "$attempt" -lt 150 ] || return 1
sleep 0.2
done
+ if [ -n "$backend" ]; then
+ stack_backend_install "$STACK_NAME-clickhouse" "$backend" \
+ "$checker" || return 1
+ fi
stack_run "$STACK_NAME-collector" --network "$STACK_NAME" \
-p "$COLLECTOR:4318" -v "$TLS_DIR:/certs:ro" \
-v "$W/out:/out" \
- -v "$REPO/testing/end2end/otelcol.yaml:/etc/otelcol-contrib/config.yaml:ro" \
+ -v "$config:/etc/otelcol-contrib/config.yaml:ro" \
"$COLLECTOR_IMAGE"
stack_wait_https -X POST -H 'Content-Type: application/json' -d '{}' \
"https://$COLLECTOR/v1/logs"
}
+stack_clickhouse_client()
+{
+ name=$1
+ shift
+ docker exec -i "$name" clickhouse-client "$@"
+}
+
stack_backend_client()
{
- docker exec -i "$STACK_NAME-backend-clickhouse" clickhouse-client "$@"
+ stack_clickhouse_client "$STACK_NAME-backend-clickhouse" "$@"
+}
+
+# Into the ClickHouse of container $1, install the quote checker $3 as
+# tpm_quote_check, as the backend's README installs it, and load the
+# schema of the backend in directory $2.
+stack_backend_install()
+{
+ into=$1
+ attempt=0
+ until stack_clickhouse_client "$into" --query 'SELECT 1' \
+ </dev/null >/dev/null 2>&1; do
+ attempt=$((attempt + 1))
+ [ "$attempt" -lt 150 ] || return 1
+ sleep 0.2
+ done
+ docker exec "$into" mkdir -p /var/lib/clickhouse/user_scripts &&
+ docker cp "$3" \
+ "$into:/var/lib/clickhouse/user_scripts/shirudo-quote-check" &&
+ docker exec "$into" \
+ chmod 0755 /var/lib/clickhouse/user_scripts/shirudo-quote-check &&
+ docker cp "$2/clickhouse/tpm_quote_check_function.xml" \
+ "$into:/etc/clickhouse-server/tpm_quote_check_function.xml" &&
+ stack_clickhouse_client "$into" --query 'SYSTEM RELOAD FUNCTIONS' \
+ </dev/null || return 1
+ attempt=0
+ until stack_clickhouse_client "$into" --query "SELECT name
+ FROM system.functions WHERE name = 'tpm_quote_check'" \
+ </dev/null 2>/dev/null | grep -q .; do
+ attempt=$((attempt + 1))
+ [ "$attempt" -lt 150 ] || return 1
+ sleep 0.2
+ done
+ stack_backend_schema "$2" "$into"
}
# The keepalive backend of directory $1 beside the telemetry stack: a
@@ -123,28 +174,7 @@ stack_backend()
stack_run "$container" --network "$STACK_NAME" \
--network-alias backend-clickhouse -p "$BACKEND_CLICKHOUSE:8123" \
-e CLICKHOUSE_SKIP_USER_SETUP=1 "$CLICKHOUSE_IMAGE"
- attempt=0
- until stack_backend_client --query 'SELECT 1' >/dev/null 2>&1; do
- attempt=$((attempt + 1))
- [ "$attempt" -lt 150 ] || return 1
- sleep 0.2
- done
- docker exec "$container" mkdir -p /var/lib/clickhouse/user_scripts &&
- docker cp "$checker" \
- "$container:/var/lib/clickhouse/user_scripts/shirudo-quote-check" &&
- docker exec "$container" \
- chmod 0755 /var/lib/clickhouse/user_scripts/shirudo-quote-check &&
- docker cp "$backend/clickhouse/tpm_quote_check_function.xml" \
- "$container:/etc/clickhouse-server/tpm_quote_check_function.xml" &&
- stack_backend_client --query 'SYSTEM RELOAD FUNCTIONS' || return 1
- attempt=0
- until stack_backend_client --query "SELECT name FROM system.functions
- WHERE name = 'tpm_quote_check'" 2>/dev/null | grep -q .; do
- attempt=$((attempt + 1))
- [ "$attempt" -lt 150 ] || return 1
- sleep 0.2
- done
- stack_backend_schema "$backend" || return 1
+ stack_backend_install "$container" "$backend" "$checker" || return 1
stack_run "$STACK_NAME-backend-collector" --network "$STACK_NAME" \
-p "$BACKEND_COLLECTOR:4318" -v "$TLS_DIR:/certs:ro" \
-e CLICKHOUSE_ENDPOINT=tcp://backend-clickhouse:9000 \
@@ -155,14 +185,16 @@ stack_backend()
}
# Load the schema of the backend in directory $1, with the retention its
-# settings name, into the backend's ClickHouse.
+# settings name, into the ClickHouse of container $2, by default the
+# backend's.
stack_backend_schema()
{
+ into=${2:-$STACK_NAME-backend-clickhouse}
for file in "$1"/sql/*.sql; do
- stack_backend_client <"$file" || return 1
+ stack_clickhouse_client "$into" <"$file" || return 1
done
- "$1/sql/apply-retention.sh" docker exec -i \
- "$STACK_NAME-backend-clickhouse" clickhouse-client >/dev/null
+ "$1/sql/apply-retention.sh" docker exec -i "$into" \
+ clickhouse-client >/dev/null
}
stack_down()
diff --git a/testing/vm/stack.sh b/testing/vm/stack.sh
index ff56deb1..e85aaf92 100755
--- a/testing/vm/stack.sh
+++ b/testing/vm/stack.sh
@@ -38,8 +38,17 @@ prepare) prepare ;;
oci) prepare; stack_oci; printf 'OCI: oci://%s (CA: %s/ca.pem)\n' "$REGISTRY" "$W" ;;
telemetry)
prepare
- stack_telemetry
- printf 'OTLP: https://%s; ClickHouse: http://%s\n' "$COLLECTOR" "$CLICKHOUSE"
+ checker=$REPO/tools/quote-check/shirudo-quote-check
+ if [ -x "$checker" ]; then
+ stack_telemetry "$REPO/testing/vm/otelcol-stack.yaml" \
+ "$REPO/tools/backend" "$checker"
+ printf 'OTLP: https://%s; ClickHouse with the backend: http://%s\n' \
+ "$COLLECTOR" "$CLICKHOUSE"
+ else
+ stack_telemetry
+ printf 'OTLP: https://%s; ClickHouse: http://%s\n' "$COLLECTOR" "$CLICKHOUSE"
+ printf '%s\n' 'no backend: make quote-check, make stack-down, then make telemetry' >&2
+ fi
;;
down) stack_down ;;
vm)