Skip to content

eBPF-based security platform

testing: allow the VMs' build as make vm-enroll enrolls them

John Fastabend5175f89cbe5f
diff --git a/Documentation/contribute/testing/testing.rst b/Documentation/contribute/testing/testing.rst
index b7466434..aa3eb556 100644
--- a/Documentation/contribute/testing/testing.rst
+++ b/Documentation/contribute/testing/testing.rst
@@ -712,11 +712,15 @@ Every ``make vm`` acts as the builder of :doc:`/operate/run/attest`:
before the guest first boots, :src:`testing/vm/tpm-builder.sh` creates
its attestation and endorsement keys in the fresh vTPM, and writes
``enroll.json`` in its state directory, naming the node by the VM's name,
-which is also its host name. ``make vm-enroll`` gathers the
-``enroll.json`` of every VM under ``build/test-vm/vms/`` into
-``build/test-vm/enroll.json`` and loads it into the stack's backend with
-one ``enroll-put``, so that the VMs read ``enrolled``. It prints the file
-and the command before it runs them:
+which is also its host name, and the ``version_id`` of the bundle's
+shirudo, the build the VM boots, in ``shirudo-build`` beside it.
+``make vm-enroll`` gathers the ``enroll.json`` of every VM under
+``build/test-vm/vms/`` into ``build/test-vm/enroll.json`` and loads it
+into the stack's backend with one ``enroll-put``, so that the VMs read
+``enrolled``, then allows their builds with
+:src:`tools/put-shirudo-build`, so that check 3 does not fail them as
+``(not expected)``. It prints the file and each command before it runs
+it:
.. code-block:: console
@@ -730,8 +734,11 @@ and the command before it runs them:
enroll-put: 000b… (ek_name 000b…, node_id interactive-Xa3k9q): already enrolled
enroll-put: 000b… (ek_name 000b…, node_id interactive-pL2m7c): enrolled
enroll-put: loaded bindings: 2
+ $ CLICKHOUSE_CLIENT='docker exec -i shirudo-dev-clickhouse clickhouse-client' tools/put-shirudo-build --note 'test-vm build' 6e52d48e…
+ put-shirudo-build: 6e52d48e…: allowed
-A VM enrolled before is loaded again, which changes nothing, so run it
+A VM enrolled before, and a build allowed before, are loaded again,
+which changes nothing, so run it
after each ``make vm``, before the VM's first keepalive or after. A VM
stopped but not removed with ``make vm-clean`` keeps its state directory
and is enrolled too. ``VM_NAME=<name>`` enrolls that VM alone, from its
diff --git a/testing/vm/run.sh b/testing/vm/run.sh
index 4380ad0e..4774aafa 100755
--- a/testing/vm/run.sh
+++ b/testing/vm/run.sh
@@ -532,16 +532,30 @@ with open(sys.argv[1], "w") as f:
PY
}
+# The builds the VMs of directories $@ boot, each once.
+shirudo_builds()
+{
+ local dir
+
+ for dir; do
+ [[ ! -s "$dir/shirudo-build" ]] || cat "$dir/shirudo-build"
+ done | sort -u
+}
+
run_enroll()
{
+ local builds
+
if [[ -z "$VM_NAME_REQUEST" ]]; then
merge_enroll_files
- exec "$REPO_ROOT/testing/vm/stack.sh" enroll "$VM_ROOT/enroll.json"
+ mapfile -t builds < <(shirudo_builds "$VMS_DIR"/*/)
+ exec "$REPO_ROOT/testing/vm/stack.sh" enroll "$VM_ROOT/enroll.json" "${builds[@]}"
fi
select_named_run_dir
[[ -s "$RUN_DIR/enroll.json" ]] ||
die "VM '$VM_NAME' has no enroll.json: only 'make vm' and end2end nodes have a builder"
- exec "$REPO_ROOT/testing/vm/stack.sh" enroll "$RUN_DIR/enroll.json"
+ mapfile -t builds < <(shirudo_builds "$RUN_DIR")
+ exec "$REPO_ROOT/testing/vm/stack.sh" enroll "$RUN_DIR/enroll.json" "${builds[@]}"
}
start_swtpm()
@@ -557,7 +571,12 @@ start_swtpm()
"$RUN_DIR/ek-ca.pem" "$RUN_DIR/enroll.json" "$VM_NAME" \
>>"$RUN_DIR/swtpm.log" 2>&1 ||
die "could not create the keys of the vTPM; see $RUN_DIR/swtpm.log"
- log "builder's records of the vTPM keys: $RUN_DIR/enroll.json (make vm-enroll loads them)"
+ # The build the VM boots, for the operator to allow as it enrolls
+ # the keys; the binary needs no TPM to say it.
+ "$TEST_VM_HOST_BUNDLE/root/usr/local/bin/shirudo" version --version-id \
+ >"$RUN_DIR/shirudo-build" 2>>"$RUN_DIR/swtpm.log" ||
+ die "cannot read the version_id of the bundle's shirudo; see $RUN_DIR/swtpm.log"
+ log "builder's records of the vTPM keys and the build: $RUN_DIR/enroll.json, $RUN_DIR/shirudo-build (make vm-enroll loads them)"
fi
if user_systemd_available; then
SWTPM_UNIT_FILE="${RUN_DIR}/swtpm.unit"
diff --git a/testing/vm/stack.sh b/testing/vm/stack.sh
index fdfe804d..fef28113 100755
--- a/testing/vm/stack.sh
+++ b/testing/vm/stack.sh
@@ -52,8 +52,10 @@ telemetry)
;;
down) stack_down ;;
enroll)
- # Shown before it runs, so that a demo shows what the step is.
- file=$(realpath --relative-to="$REPO" "${1:?usage: stack.sh enroll <enroll.json>}")
+ # Shown before they run, so that a demo shows what each step is: the
+ # keys the builder made, then the builds the VMs boot.
+ file=$(realpath --relative-to="$REPO" "${1:?usage: stack.sh enroll <enroll.json> [<version_id>...]}")
+ shift
[ "$(docker container inspect -f '{{.State.Running}}' "$STACK_NAME-clickhouse" 2>/dev/null)" = true ] ||
{ echo 'the local stack is not up: run make stack-up' >&2; exit 1; }
cd "$REPO"
@@ -62,6 +64,9 @@ enroll)
cat "$file"
printf "\$ CLICKHOUSE_CLIENT='%s' tools/backend/jobs/enroll-put %s\n" "$client" "$file"
CLICKHOUSE_CLIENT=$client tools/backend/jobs/enroll-put "$file"
+ [ $# -gt 0 ] || exit 0
+ printf "\$ CLICKHOUSE_CLIENT='%s' tools/put-shirudo-build --note 'test-vm build' %s\n" "$client" "$*"
+ CLICKHOUSE_CLIENT=$client tools/put-shirudo-build --note 'test-vm build' "$@"
;;
vm)
prepare