Skip to content

eBPF-based security platform

testing: deliver a Java agent end to end and run it in a JVM

John Fastabendcac7dfc2dfb3
diff --git a/Documentation/contribute/testing/test-coverage.rst b/Documentation/contribute/testing/test-coverage.rst
index d5b9538b..e8b4cacd 100644
--- a/Documentation/contribute/testing/test-coverage.rst
+++ b/Documentation/contribute/testing/test-coverage.rst
@@ -777,9 +777,12 @@ signed config image.
- DNS over loopback in maps, OTLP and ClickHouse
* - ``t9105-delivery``
- The operator package built and installed in an operator VM
- without a TPM, which publishes ``kernel-obs`` and verifies the
- evidence; registry, tree sync, load, export and attestation on
- the target
+ without a TPM, which publishes ``kernel-obs`` and the Java agent
+ ``e2e-java`` it compiles, and verifies the evidence, its
+ ``java_load`` included; registry, tree sync, load, export and
+ attestation on the target, and a JVM a user manager starts
+ picking up ``JAVA_TOOL_OPTIONS`` and running the agent from its
+ sealed jar
* - ``t9106-policy-exec-graph``
- A signed SHPL section labels five executables; its BPF policy
allows unlabeled tasks to exec unlabeled files and 0x1, allows
diff --git a/Documentation/contribute/testing/testing.rst b/Documentation/contribute/testing/testing.rst
index 8e929717..f2c09154 100644
--- a/Documentation/contribute/testing/testing.rst
+++ b/Documentation/contribute/testing/testing.rst
@@ -49,7 +49,8 @@ Before you begin
``libtpms-dev``.
- For the end-to-end tests: Docker on the host, and network access the
first time, when the runner adds clang 23 from apt.llvm.org and the
- operator's build dependencies to the image of the operator VM.
+ operator's build dependencies, a JDK among them, to the image of the
+ operator VM.
The ``CI suite`` workflow uses the x86-64 CI kernel package from
``shirudo-dev/kernel`` for every trigger: the
@@ -786,17 +787,22 @@ shows the run in order.
:src:`testing/end2end/operator.sh` over SSH: it builds ``kernel-obs``
into a package with ``bpm build``, against the headers and
``vmlinux.h`` of the package, pushes it with ``bpm push``, appends it
- to a signed upatch tree with ``bpm tree append`` and picks the nonce
- the targets attest with. The host publishes the keepalive backend's
+ to a signed upatch tree with ``bpm tree append``, does the same with
+ ``e2e-java``, a Java agent it compiles from
+ :src:`testing/end2end/java-agent/Agent.java` with ``javac``, and
+ picks the nonce the targets attest with. The host publishes the keepalive backend's
example tree and loads it with the tree ingest job.
#. Node A boots, activates a signed config that points at the tree and
- the collector, and its units pull, verify, load and export. Its
+ the collector, and its units pull, verify, load and export. A JVM
+ that a user manager of node A starts after the sync picks up
+ ``JAVA_TOOL_OPTIONS`` from ``environment.d`` and runs the agent from
+ its sealed jar; the runtime image carries a JRE for it. Its
tests, ``t91??``, run over SSH from the host, which writes what they
print to ``result/guest.log`` as a family's VM does. Node B boots
beside it.
#. The host hands node A's TPM evidence to the operator, which verifies
- it with ``attest verify`` and checks that its records name the
- package and the tree operation it published. The operator VM then
+ it with ``attest verify`` and checks that its records name both
+ packages and the last tree operation it published. The operator VM then
stops.
#. The fresh edge node boots in node A's place. Meanwhile the host
checks that the collector holds the package's records, and checks
@@ -915,8 +921,8 @@ config image, as ``t9105`` configures node A:
* - ``config-end2end``
- ``role=edge``
- The tree ``shirudo/end2end-tree`` and the test's collector. Node
- A activates it in ``t9105``, and the ``kernel-obs`` operation
- selects ``role=edge``.
+ A activates it in ``t9105``, and the ``kernel-obs`` and
+ ``e2e-java`` operations select ``role=edge``.
* - ``config-edge``
- ``role=edge``
- The tree ``shirudo/pipeline-tree`` on the test's registry and the
diff --git a/testing/end2end/java-agent/Agent.java b/testing/end2end/java-agent/Agent.java
new file mode 100644
index 00000000..16d86ff0
--- /dev/null
+++ b/testing/end2end/java-agent/Agent.java
@@ -0,0 +1,19 @@
+// SPDX-License-Identifier: BSD-2-Clause
+// Copyright (c) 2026 Authors of shirudo
+
+package shirudo.e2e;
+
+/*
+ * The Java agent of the end-to-end test: its premain names the jar the
+ * JVM loaded it from, which t9105 compares against the sealed one.
+ */
+public final class Agent {
+ private Agent() {
+ }
+
+ public static void premain(String args) {
+ System.err.println("shirudo-e2e-agent: premain from "
+ + Agent.class.getProtectionDomain()
+ .getCodeSource().getLocation().getPath());
+ }
+}
diff --git a/testing/end2end/operator.sh b/testing/end2end/operator.sh
index 37df4a56..b46136e2 100755
--- a/testing/end2end/operator.sh
+++ b/testing/end2end/operator.sh
@@ -24,6 +24,43 @@ payload() {
python3 -c 'import json, sys; print(json.load(sys.stdin)["payload_sha256"])'
}
+# The Java agent e2e-java, compiled here as an operator would, packaged,
+# pushed and appended to the tree after kernel-obs, for the same nodes.
+publish_java() {
+ java=$W/java
+ mkdir -p "$java/classes" "$W/pkg/e2e-java"
+ say "compile the Java agent e2e-java and sign it into a package"
+ javac --release 11 -d "$java/classes" \
+ "$REPO/testing/end2end/java-agent/Agent.java"
+ printf 'Premain-Class: shirudo.e2e.Agent\n' >"$java/manifest"
+ jar --create --file "$W/pkg/e2e-java/e2e-java.jar" \
+ --manifest "$java/manifest" -C "$java/classes" .
+ cat >"$W/pkg/e2e-java/Beefile" <<-'EOF'
+ [package]
+ name = "e2e-java"
+ description = "The Java agent of the end-to-end test"
+
+ [[upatches]]
+ source = "e2e-java.jar"
+ type = "java"
+
+ [upatches.tree]
+ id = "e2e-java"
+
+ [upatches.tree.selector.labels]
+ role = ["edge"]
+ EOF
+ (cd "$W/pkg" && shirudo bpm build e2e-java --version 1.0.0 --keys-dir "$KEYS")
+ bee=$W/pkg/e2e-java-1.0.0.bee
+ say "push it to oci://$REGISTRY and append it to the upatch tree"
+ shirudo bpm push "$bee" "oci://$REGISTRY/shirudo/e2e-java" \
+ --keys-dir "$KEYS"
+ shirudo bpm tree append "$bee" "oci://$REGISTRY/shirudo/end2end-tree" \
+ --keys-dir "$KEYS" --tree-id kernel-obs
+ tar --no-same-owner -xzf "$bee" -C "$W/pkg"
+ payload "$W/pkg/e2e-java-1.0.0/upatches/e2e-java.upatch" >"$W/java-payload"
+}
+
publish() {
[ -s "$BPM_OCI_CA_FILE" ] || die "no CA of the registry: $BPM_OCI_CA_FILE"
[ -s "$POLICY_FIXTURE" ] || die "no policy exec graph fixture: $POLICY_FIXTURE"
@@ -47,6 +84,7 @@ role = ["edge"]' "$W/pkg/kernel-obs/Beefile"
--keys-dir "$KEYS"
tar --no-same-owner -xzf "$bee" -C "$W/pkg"
payload "$W/pkg/kernel-obs-1.0.0/upatches/kernel-obs.upatch" >"$W/payload"
+ publish_java
payload "$POLICY_FIXTURE" >"$W/policy-payload"
openssl rand -hex 16 >"$W/nonce"
}
@@ -67,10 +105,11 @@ verify() {
# The records replay to the register the TPM certified, so the last load
# and tree operation they name are the target's.
python3 - "$W/evidence.json" "$(cat "$W/payload")" \
- "$(cat "$W/policy-payload")" "$BPM_OCI_CA_FILE" "$REGISTRY" <<'PY' ||
+ "$(cat "$W/policy-payload")" "$BPM_OCI_CA_FILE" "$REGISTRY" \
+ "$(cat "$W/java-payload")" <<'PY' ||
import json, ssl, sys, urllib.request
-evidence, payload, policy_payload, ca, registry = sys.argv[1:6]
+evidence, payload, policy_payload, ca, registry, java_payload = sys.argv[1:7]
ctx = ssl.create_default_context(cafile=ca)
@@ -98,6 +137,9 @@ loads = [r["upatch"] for r in records if r["type"] == "upatch_load"]
assert {"name": "kernel-obs", "payload_sha256": payload} in loads, loads
assert loads[-1] == {"name": "policy-exec-graph",
"payload_sha256": policy_payload}, loads[-1]
+java_loads = [r["upatch"] for r in records if r["type"] == "java_load"]
+assert java_loads == [{"name": "e2e-java",
+ "payload_sha256": java_payload}], java_loads
ops = [r["tree"] for r in records if r["type"] == "tree_op"]
assert ops[-1] == {key: published[key] for key in
("seq", "op", "id", "operation_digest")}, (ops[-1], published)
diff --git a/testing/end2end/t9105-delivery.sh b/testing/end2end/t9105-delivery.sh
index e6665bcf..6d1283e5 100755
--- a/testing/end2end/t9105-delivery.sh
+++ b/testing/end2end/t9105-delivery.sh
@@ -4,11 +4,13 @@
#
# t9105 -- the delivery path end to end. The operator VM built kernel-obs
# into a package, pushed it to an OCI registry and appended it to a signed
-# upatch tree, and an OpenTelemetry Collector listens (end2end/host.sh).
-# The target activates the signed config that points at both, and the
-# units it ships pull the tree, verify and load the package, and export
-# what it observes; the TPM-signed evidence goes back to the operator,
-# which checks it against what it published.
+# upatch tree, then did the same with the Java agent e2e-java it compiled,
+# and an OpenTelemetry Collector listens (end2end/host.sh). The target
+# activates the signed config that points at both, and the units it ships
+# pull the tree, verify and load both packages, and export what it
+# observes; a JVM a user manager starts picks up the agent from the sealed
+# jar; the TPM-signed evidence goes back to the operator, which checks it
+# against what it published.
cd "$(dirname "$0")/.."
. ./integration-lib.sh
@@ -19,6 +21,8 @@ E2E=$PWD/../build/test-vm/end2end
CONFIG=/var/lib/shirudo/images/config-end2end
PIN=/run/shirudo/bpffs/upatches/kernel-obs/link_0
OUT=/mnt/shirudo-out/end2end
+JAR=/run/shirudo-java/e2e-java.jar
+JAVA_USER=shirudo-e2e-java
[ -s "$E2E/ca.pem" ] && [ -s "$E2E/nonce" ] ||
test_skip_all "no registry and collector: run make -C testing end2end"
[ -s "$CONFIG.img" ] || test_skip_all "missing config-end2end image"
@@ -29,6 +33,39 @@ mkdir -p "$OUT"
sed -E -i '/^[^#]*[[:space:]]registry\.test([[:space:]]|$)/d' /etc/hosts
printf '10.0.2.2 registry.test\n' >>/etc/hosts
+# The JVM's user and its manager, which lingering keeps up, go with the
+# test; the agent stays loaded for the evidence.
+cleanup() {
+ uid=$(id -u "$JAVA_USER" 2>/dev/null) || return 0
+ loginctl disable-linger "$JAVA_USER" 2>/dev/null || true
+ systemctl stop "user@$uid.service" 2>/dev/null || true
+ userdel -r "$JAVA_USER" 2>/dev/null || true
+}
+trap cleanup EXIT
+
+# A command of the JVM's user against its manager, over the manager's
+# private socket, which needs no session bus.
+as_java_user() {
+ runuser -u "$JAVA_USER" -- \
+ env XDG_RUNTIME_DIR="/run/user/$(id -u "$JAVA_USER")" "$@"
+}
+
+# The JVM, as a service of the user's manager, which gives it the
+# manager's environment.
+java_unit() {
+ dir=/home/$JAVA_USER/.config/systemd/user
+ install -d -o "$JAVA_USER" -g "$JAVA_USER" \
+ "/home/$JAVA_USER/.config" "/home/$JAVA_USER/.config/systemd" "$dir" &&
+ cat >"$dir/shirudo-e2e-java.service" <<-'EOF' &&
+ [Service]
+ Type=oneshot
+ ExecStart=java -version
+ StandardOutput=truncate:%h/java-version.out
+ StandardError=inherit
+ EOF
+ chown "$JAVA_USER:" "$dir/shirudo-e2e-java.service"
+}
+
# Start a unit and wait for it; its journal is what a failure needs.
unit_ok() {
systemctl start "$1" && return 0
@@ -60,6 +97,30 @@ test_expect_success 'the tree sync unit pulls, verifies and loads the package' '
"$SHIRUDO_BIN" status --json >"$OUT/status.json"
'
+test_expect_success 'the sync installs the Java agent and names it in JAVA_TOOL_OPTIONS' '
+ [ "$(stat -c %a "$JAR")" = 644 ] &&
+ grep -qxF "JAVA_TOOL_OPTIONS=\"\${JAVA_TOOL_OPTIONS:+\$JAVA_TOOL_OPTIONS }-javaagent:$JAR\"" \
+ /run/environment.d/shirudo.conf
+'
+
+# environment.d reaches JVMs through a user manager, which reads it when
+# it starts: this one starts after the sync.
+test_expect_success 'a JVM a user manager starts loads the agent from the sealed jar' '
+ useradd --create-home --user-group "$JAVA_USER" &&
+ loginctl enable-linger "$JAVA_USER" &&
+ systemctl start "user@$(id -u "$JAVA_USER").service" &&
+ as_java_user systemctl --user show-environment \
+ >"$OUT/java-user-environment" &&
+ grep -qx "JAVA_TOOL_OPTIONS=-javaagent:$JAR" "$OUT/java-user-environment" &&
+ java_unit &&
+ as_java_user systemctl --user daemon-reload &&
+ as_java_user systemctl --user start shirudo-e2e-java.service &&
+ cp "/home/$JAVA_USER/java-version.out" "$OUT/java-version.out" &&
+ grep -qx "Picked up JAVA_TOOL_OPTIONS: -javaagent:$JAR" \
+ "$OUT/java-version.out" &&
+ grep -qx "shirudo-e2e-agent: premain from $JAR" "$OUT/java-version.out"
+'
+
test_expect_success 'the map export unit ships what the package observed' '
python3 end2end/kernel_obs_events.py exec &&
unit_ok shirudo-map-export.service
diff --git a/testing/functional/build/t1007-test-vm-cli.sh b/testing/functional/build/t1007-test-vm-cli.sh
index c2c2972b..bd4e0807 100755
--- a/testing/functional/build/t1007-test-vm-cli.sh
+++ b/testing/functional/build/t1007-test-vm-cli.sh
@@ -326,7 +326,7 @@ test_expect_success 'the runtime image gives the appliance the host resolvers in
! grep -qx -- "--install" "$WORK/dns-args" &&
grep -q "cat /root/shirudo-nameservers >>/etc/resolv.conf" "$WORK/dns-args" &&
grep -q "apt-get \$apt_opts update" "$WORK/dns-args" &&
- grep -q "apt-get \$apt_opts install ca-certificates e2fsprogs keyutils" "$WORK/dns-args" &&
+ grep -q "apt-get \$apt_opts install ca-certificates default-jre-headless e2fsprogs keyutils" "$WORK/dns-args" &&
grep -q "ripgrep rsync" "$WORK/dns-args" &&
run_dns "$WORK/no-such-resolv.conf" &&
! test -s "$WORK/dns-ns" &&
diff --git a/testing/vm/operator-packages b/testing/vm/operator-packages
index e45b49fe..02a4fdef 100644
--- a/testing/vm/operator-packages
+++ b/testing/vm/operator-packages
@@ -1,6 +1,7 @@
build-essential
cryptsetup-bin
curl
+default-jdk-headless
dpkg-dev
e2fsprogs
git
diff --git a/testing/vm/runtime-packages b/testing/vm/runtime-packages
index c95c1746..92ccbf72 100644
--- a/testing/vm/runtime-packages
+++ b/testing/vm/runtime-packages
@@ -1,4 +1,5 @@
ca-certificates
+default-jre-headless
e2fsprogs
keyutils
libelf1t64