Skip to content

Secure, Fast, and Extensible Sandbox runtime for AI agents.

test(egress): gate Fast Sandbox IP-rebind kernel regression

leo peina230aa8db864
diff --git a/.github/workflows/egress-test.yml b/.github/workflows/egress-test.yml
index bb71eca1d..1256dc072 100644
--- a/.github/workflows/egress-test.yml
+++ b/.github/workflows/egress-test.yml
@@ -97,7 +97,8 @@ jobs:
TestNftStartFailurePreservesKernelAndRetry \
TestNftRealMissingTableFallback
bash scripts/ci-nft-go-test.sh . \
- TestRevisionNftEffectsRealFileAndKernel
+ TestRevisionNftEffectsRealFileAndKernel \
+ TestTransitionRealNftChangedIPKernelRules
- name: Run privileged quarantine packet regressions
working-directory: components/egress
diff --git a/components/egress/scripts/test_ci_privileged_go_test.py b/components/egress/scripts/test_ci_privileged_go_test.py
index 61d670d14..beab0bccb 100644
--- a/components/egress/scripts/test_ci_privileged_go_test.py
+++ b/components/egress/scripts/test_ci_privileged_go_test.py
@@ -16,6 +16,7 @@
import json
import os
+import re
from pathlib import Path
import shutil
import subprocess
@@ -38,6 +39,66 @@ NFT_TESTS = [
"TestNftStartFailurePreservesKernelAndRetry",
"TestNftRealMissingTableFallback",
]
+NFT_OWNER_TESTS = [
+ "TestRevisionNftEffectsRealFileAndKernel",
+ "TestTransitionRealNftChangedIPKernelRules",
+]
+WORKFLOW = (
+ Path(__file__).resolve().parents[3] / ".github" / "workflows" / "egress-test.yml"
+)
+
+
+def nft_owner_tests_in_workflow(workflow):
+ """Return nft owner argv only from the privileged nft step's run block."""
+ lines = workflow.splitlines()
+ heading = " - name: Run privileged nft regressions"
+ starts = [index for index, line in enumerate(lines) if line == heading]
+ if len(starts) != 1:
+ return None
+
+ start = starts[0]
+ end = next(
+ (index for index in range(start + 1, len(lines)) if lines[index].startswith(" - ")),
+ len(lines),
+ )
+ step = lines[start:end]
+ if step.count(" working-directory: components/egress") != 1:
+ return None
+ run_headers = [index for index, line in enumerate(step) if line == " run: |"]
+ if len(run_headers) != 1:
+ return None
+
+ run = []
+ for line in step[run_headers[0] + 1 :]:
+ if line.strip() and len(line) - len(line.lstrip()) < 10:
+ break
+ run.append(line)
+
+ command = " bash scripts/ci-nft-go-test.sh . " + chr(92)
+ calls = [index for index, line in enumerate(run) if line == command]
+ if len(calls) != 1:
+ return None
+
+ tests = []
+ cursor = calls[0] + 1
+ completed = False
+ while cursor < len(run) and run[cursor].startswith(" "):
+ arg = run[cursor][12:].strip()
+ continued = arg.endswith(chr(92))
+ if continued:
+ arg = arg[:-1].rstrip()
+ if re.fullmatch(r"Test[A-Za-z0-9_]+", arg) is None:
+ return None
+ tests.append(arg)
+ cursor += 1
+ if not continued:
+ completed = True
+ break
+ if not completed or not tests:
+ return None
+ return tests
+
+
OWNER_TESTS = [
"TestRevisionAtomicPolicyDirectoryBindMount",
"TestRevisionAtomicPolicySingleFileBindMountRejected",
@@ -239,7 +300,7 @@ class NftGoTestRunnerTests(PrivilegedGoTestRunnerTests):
kind = "nft"
def test_success_for_nft_and_owner_groups(self):
- for package, tests in (("./pkg/nftables", NFT_TESTS), (".", ["TestRevisionNftEffectsRealFileAndKernel"])):
+ for package, tests in (("./pkg/nftables", NFT_TESTS), (".", NFT_OWNER_TESTS)):
with self.subTest(package=package):
result, events = self.run_script(package=package, tests=tests)
self.assertEqual(result.returncode, 0, result.stdout + result.stderr)
@@ -248,6 +309,58 @@ class NftGoTestRunnerTests(PrivilegedGoTestRunnerTests):
self.assertEqual([event["command"] for event in events].count("sudo"), 1)
self.assertNotIn("unshare", [event["command"] for event in events])
+ def test_workflow_wires_nft_owner_tests_in_privileged_step(self):
+ workflow = WORKFLOW.read_text(encoding="utf-8")
+ self.assertEqual(nft_owner_tests_in_workflow(workflow), NFT_OWNER_TESTS)
+
+ slash = chr(92)
+ newline = chr(10)
+ owner_call = (
+ f" bash scripts/ci-nft-go-test.sh . {slash}{newline}"
+ f" TestRevisionNftEffectsRealFileAndKernel {slash}{newline}"
+ " TestTransitionRealNftChangedIPKernelRules" + newline
+ )
+ quarantine_command = f" bash scripts/ci-nft-go-test.sh ./pkg/quarantine {slash}{newline}"
+ quarantine_step = " - name: Run privileged quarantine packet regressions"
+ moved = workflow.replace(owner_call, "", 1).replace(
+ quarantine_command,
+ owner_call + quarantine_command,
+ 1,
+ )
+ moved_to_anonymous_step = workflow.replace(owner_call, "", 1).replace(
+ quarantine_step,
+ " - run: |" + newline + owner_call + quarantine_step,
+ 1,
+ )
+ commented = workflow.replace(
+ " TestTransitionRealNftChangedIPKernelRules" + newline,
+ " # TestTransitionRealNftChangedIPKernelRules" + newline,
+ 1,
+ )
+ wrong_package = workflow.replace(
+ f" bash scripts/ci-nft-go-test.sh . {slash}",
+ f" bash scripts/ci-nft-go-test.sh ./pkg/nftables {slash}",
+ 1,
+ )
+ correct_step = (
+ " - name: Run privileged nft regressions" + newline
+ + " working-directory: components/egress" + newline
+ )
+ wrong_step = (
+ " - name: Run privileged nft regressions" + newline
+ + " working-directory: components/egress/scripts" + newline
+ )
+ wrong_working_directory = workflow.replace(correct_step, wrong_step, 1)
+ for name, mutant in (
+ ("moved to another named step", moved),
+ ("moved to an anonymous step", moved_to_anonymous_step),
+ ("commented out", commented),
+ ("wrong package", wrong_package),
+ ("wrong working directory", wrong_working_directory),
+ ):
+ with self.subTest(name=name):
+ self.assertNotEqual(nft_owner_tests_in_workflow(mutant), NFT_OWNER_TESTS)
+
def test_missing_nft_fails_before_compilation(self):
(self.bin / "nft").unlink()
result, events = self.run_script()