eBPF-based security platform
testing: verify policy label removal after unload
John Fastabend3acbf11dd01d
diff --git a/testing/end2end/t9106-policy-exec-graph.sh b/testing/end2end/t9106-policy-exec-graph.shindex 457fb5d6..c0227e52 100644--- a/testing/end2end/t9106-policy-exec-graph.sh+++ b/testing/end2end/t9106-policy-exec-graph.sh@@ -2,8 +2,7 @@# SPDX-License-Identifier: BSD-2-Clause# Copyright (c) 2026 Authors of shirudo#-# t9106 -- signed policy labels enforce exec and socket policy graphs.-# This is the last end-to-end test and leaves the policy loaded for evidence.+# t9106 -- signed policy labels enforce policy graphs and are removable.cd "$(dirname "$0")/..". ./integration-lib.sh@@ -11,13 +10,17 @@ target_guardFIXTURES=${SHIRUDO_TEST_FIXTURES_DIR:?target fixture directory is not set}LOAD="$FIXTURES/shirudo-test-policy-exec-graph.upatch"+UNLOAD="$FIXTURES/shirudo-test-policy-exec-graph.unload.upatch"WORK=/tmp/shirudo-policy-exec-graphHELPER=./end2end/policy-exec+POLICY_PROBE=/run/shirudo/runtime/usr/bin/shirudo-policy-probeE2E=$PWD/../build/test-vm/end2endOUT=/mnt/shirudo-out/end2end-[ -s "$LOAD" ] || test_skip_all "missing policy exec graph fixture"+[ -s "$LOAD" ] && [ -s "$UNLOAD" ] ||+ test_skip_all "missing policy exec graph fixture"[ -x "$HELPER" ] || test_skip_all "policy exec graph helper is missing"+[ -x "$POLICY_PROBE" ] || test_skip_all "runtime policy probe is missing"[ -s "$E2E/nonce" ] && [ -d "$OUT" ] ||test_skip_all "end-to-end evidence destination is missing"NONCE=$(cat "$E2E/nonce")@@ -40,4 +43,8 @@ elseUNLABELED_RESULT=failedfi"$WORK/exec-1" run "$UNLABELED_RESULT" || exit 1-"$SHIRUDO_BIN" attest --nonce="$NONCE" --out="$OUT/evidence.json"+"$SHIRUDO_BIN" attest --nonce="$NONCE" --out="$OUT/evidence.json" ||+ exit 1+"$SHIRUDO_BIN" upatch unload "$UNLOAD" --no-precheck >/dev/null 2>&1 ||+ exit 1+"$POLICY_PROBE" remove-policy "$WORK/exec-1" || exit 1diff --git a/testing/helper/policy-probe.c b/testing/helper/policy-probe.cindex 4e6f4942..82d19312 100644--- a/testing/helper/policy-probe.c+++ b/testing/helper/policy-probe.c@@ -250,6 +250,18 @@ static int set_policy(const char *path, const char *text)sizeof(value), 0) ? 1 : 0;}+static int remove_policy(const char *path)+{+ __u64 value;+ ssize_t n;++ if (removexattr(path, "security.bpf.shirudo.policy"))+ return 1;+ n = getxattr(path, "security.bpf.shirudo.policy", &value,+ sizeof(value));+ return n < 0 && errno == ENODATA ? 0 : 1;+}+static int check_policy(const char *text){__u64 expected, active = 0;@@ -404,6 +416,8 @@ int main(int argc, char **argv)}if (argc == 4 && !strcmp(argv[1], "set-policy"))return set_policy(argv[2], argv[3]);+ if (argc == 3 && !strcmp(argv[1], "remove-policy"))+ return remove_policy(argv[2]);if (argc >= 2 && !strcmp(argv[1], "check-policy"))return check_policy_env();if (argc >= 2 && !strcmp(argv[1], "fork-exec-policy"))diff --git a/testing/vm/build-bundle.sh b/testing/vm/build-bundle.shindex e83adef8..e565b69f 100755--- a/testing/vm/build-bundle.sh+++ b/testing/vm/build-bundle.sh@@ -638,6 +638,9 @@ build_policy_exec_graph_fixture()tar -xOf "$package" \policy-exec-graph-1.0.0/upatches/policy-exec-graph.upatch \>"$TMP_DIR/fixtures/shirudo-test-policy-exec-graph.upatch"+ tar -xOf "$package" \+ policy-exec-graph-1.0.0/upatches/policy-exec-graph.unload.upatch \+ >"$TMP_DIR/fixtures/shirudo-test-policy-exec-graph.unload.upatch"}log "building target-test fixtures on the operator host"