eBPF-based security platform
testing/end2end: take app-sandbox from its sources to a node and back
John Fastabend55a3d06b1e27
diff --git a/.agents/skills/testing/SKILL.md b/.agents/skills/testing/SKILL.mdindex ca6346ea..d2487dd5 100644--- a/.agents/skills/testing/SKILL.md+++ b/.agents/skills/testing/SKILL.md@@ -56,8 +56,14 @@ them. On x86-64 a third fresh edge node then boots alone, as`<name>-3-end2end-edge`, the registry restarts empty again, and `host.sh`runs t9113 against it: the java-base64 shield published, appended to anew tree, pulled and blocking `upatches/test/badDecoder.jar` in a JVM,-then deleted and gone. Their output is `build/test-vm/end2end/t9109.log`-to `t9113.log`.+then deleted and gone. Last, on every architecture, a fourth fresh edge+node boots alone, as `<name>-4-end2end-edge`, the registry restarts+empty once more, and `host.sh` runs t9114 against it: the app-sandbox+upatch built with the sandbox of `testing/fixtures/app-sandbox`,+published, appended to a new tree, pulled and restricting what+`testing/end2end/app_sandbox_probe.py` executes, connects to and+writes, then deleted and gone. Their output is+`build/test-vm/end2end/t9109.log` to `t9114.log`.A test reaches the nodes with `node_sh b` or `node_sh edge` of`testing/end2end/node-lib.sh`, and does to them, the registry and thebackend what `testing/end2end/pipeline-lib.sh` offers. Their boot logsdiff --git a/Documentation/contribute/testing/test-coverage.rst b/Documentation/contribute/testing/test-coverage.rstindex ce45ab42..f5a7044e 100644--- a/Documentation/contribute/testing/test-coverage.rst+++ b/Documentation/contribute/testing/test-coverage.rst@@ -922,7 +922,7 @@ signed config image.``--expect-credential``, and the key moving from ``untrusted`` to``enrolled`` in the backend* - ``t9113-shield-rollout``- - A shield rolled out and taken back, run by ``host.sh`` last, on+ - A shield rolled out and taken back, run by ``host.sh`` onx86-64, on a third fresh edge node and an empty registry:``put-shields`` and ``shields-put`` listing ``java-base64`` in``shield_catalog``, ``bpm tree append`` by reference and@@ -932,6 +932,20 @@ signed config image.agent retired at seq 2 and a JVM started after it without theguard, with ``5 head`` and ``6 set`` of the node's status at eachstep+ * - ``t9114-app-sandbox``+ - The ``app-sandbox`` upatch from its sources to a node and back,+ run by ``host.sh`` last, on a fourth fresh edge node and an empty+ registry: ``bpm build`` generating its rules with the Beefile's+ ``[[upatches.rodata]]`` generator and refusing rules for a+ sandbox without a ``[[upatches.policy]]`` table, ``put-shields``+ and ``shields-put``, ``bpm tree append`` by reference and+ ``--package-digest``, the node loading it at seq 1 and labeling+ the sandbox's files, a labeled program denied the executions,+ connections, datagrams, raw socket and ``.php`` creations,+ renames and writes its sandbox rules out and allowed the rest, an+ unlabeled program denied nothing, then ``--op delete`` and the+ program unrestricted at seq 2, with ``5 head`` and ``6 set`` of+ the node's status at each stepQuickstart and quick guides~~~~~~~~~~~~~~~~~~~~~~~~~~~diff --git a/Documentation/contribute/testing/testing.rst b/Documentation/contribute/testing/testing.rstindex 432771c0..8e883671 100644--- a/Documentation/contribute/testing/testing.rst+++ b/Documentation/contribute/testing/testing.rst@@ -239,10 +239,11 @@ a Python companion with the same stem, such asbefore ``init``. They skip on the build host and run in a separate VMthat the ``tpm`` family boots without the production initrd.-``t9109`` to ``t9113`` carry target numbers but run on the host:+``t9109`` to ``t9114`` carry target numbers but run on the host::src:`testing/end2end/host.sh` runs them after node A's suite, ``t9109``,-``t9110``, ``t9112``, ``t9111`` and then ``t9113``, against other nodes (see-:ref:`testing-two-nodes`), and node A's runner leaves them out.+``t9110``, ``t9112``, ``t9111``, ``t9113`` and then ``t9114``, against+other nodes (see :ref:`testing-two-nodes`), and node A's runner leaves+them out.Run the tests-------------@@ -940,15 +941,17 @@ shows the run in order... figure:: /images/contribute-end2end-run.svg:alt: Ten phases in order, one lane each for the host, thecontainers, the operator VM, node A, node B, the fresh edge node,- the second pair and the third node. 1: t9001 on the host, then the containers+ the second pair and the lone nodes. 1: t9001 on the host, then the containersstart. 2: the operator VM publishes, the host loads the exampletree. 3: node A runs its tests while node B boots. 4: theoperator verifies node A and stops. 5: the edge node boots whilethe host runs check-otlp and checks node B. 6: t9109, t9110 andt9112 on the host. 7: the registry starts again empty and thesecond pair boots. 8: t9111 on the host. 9, on x86-64 only: the- registry starts again empty and a third fresh edge node boots.- 10: t9113 on the host, then teardown.+ registry starts again empty, a third fresh edge node boots and+ t9113 runs on the host. 10: the registry starts again empty, a+ fourth fresh edge node boots and t9114 runs on the host, then+ teardown.Figure 1. The end-to-end run in order, not to scale. Tinted bars runtests.@@ -988,7 +991,10 @@ shows the run in order.stops.#. On x86-64, the registry starts again without a volume and a thirdfresh edge node boots alone; ``t9113`` runs on the host against it- (:ref:`testing-shield`). Then the nodes and the containers stop.+ (:ref:`testing-shield`).+#. The registry starts again without a volume and a fourth fresh edge+ node boots alone; ``t9114`` runs on the host against it+ (:ref:`testing-sandbox`). Then the nodes and the containers stop.The operator VM boots from the runtime image with clang 23 and the builddependencies of the operator package added, which the runner prepares@@ -1003,7 +1009,7 @@ from the files git sees in the checkout and installs it. The operator VMand node A name the registry ``registry.test``, at QEMU's address forthe host, so the tree names it as node A reaches it. The host's ownbuild and the operator key it keeps still play the operator for the-keepalive backend's example tree and for ``t9109`` to ``t9113``, which+keepalive backend's example tree and for ``t9109`` to ``t9114``, whichrun on the host.To check the collector, :src:`testing/end2end/check-otlp.py` relies on@@ -1048,10 +1054,10 @@ operator key and loads it with the backend's tree ingest job, which runs``bpm tree show``. In the guest, ``t9107`` sends the example keepaliveswith their recorded quotes through that collector and queriesClickHouse, both through QEMU's address for the host. After node A,-``host.sh`` runs ``t9109`` to ``t9113`` against the same backend, see+``host.sh`` runs ``t9109`` to ``t9114`` against the same backend, see:ref:`testing-pipeline`, :ref:`testing-history`,-:ref:`testing-activation`, :ref:`testing-walk` and-:ref:`testing-shield`. ``host.sh`` writes+:ref:`testing-activation`, :ref:`testing-walk`, :ref:`testing-shield`+and :ref:`testing-sandbox`. ``host.sh`` writesthe example tree's digest to ``build/test-vm/end2end/backend-tree.digest``when it publishes the tree, and removes it when the backend's treeingest job does not load the tree and when ``host.sh`` stops. Without@@ -1358,7 +1364,7 @@ holds the three segments, ``tree_ops`` the five operations and``node_ops`` each node from seq 1, with no contradiction marked, andboth nodes are ``healthy`` with ``4 chain: pass``, ``5 head: pass, seq 5of 5`` and ``6 set: pass``. :src:`testing/end2end/pipeline-lib.sh` holds-what ``t9109`` to ``t9113`` do to the nodes, the registry and+what ``t9109`` to ``t9114`` do to the nodes, the registry andClickHouse... _testing-shield:@@ -1370,7 +1376,7 @@ A shield rolled out and taken backan operator rolls a fix out for an advisory against a platform and takesit back once the platform is fixed. The shield is ``java-base64`` of:src:`upatches/java-base64/`, a Java agent, whose selector names-``x86_64``, so ``host.sh`` runs the test on x86-64 alone: last, against+``x86_64``, so ``host.sh`` runs the test on x86-64 alone: againsta third fresh edge node, which has followed no tree, a registry thatholds none, and the same backend. Its output is``build/test-vm/end2end/t9113.log``. The host has no JDK to rely on, so@@ -1412,6 +1418,60 @@ It does not check that the node is ``healthy``: a user manager tries``bpf()`` as it starts, which shirudo refuses and counts, and check 3fails a node whose tamper counters rose since its first record.+.. _testing-sandbox:++An application sandboxed and released+~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~++``t9114`` takes the ``app-sandbox`` upatch of :src:`upatches/app-sandbox/`+through the whole pipeline, from its sources to a node that enforces it+and back. ``host.sh`` runs it last, on every architecture, against a+fourth fresh edge node, a registry that holds no tree, and the same+backend. Its output is ``build/test-vm/end2end/t9114.log``. The package+it publishes is the shipped one with ``probe.Beefile`` as its Beefile+and the rules of :src:`testing/fixtures/app-sandbox/`, whose one+sandbox, ``probe``,+labels a file of the test: a copy of the node's ``python3`` at+``/tmp/shirudo-app-sandbox/app``. It may execute the file labeled+``probe-helpers`` beside it, reach the loopback networks, and not+create, rename or write ``*.php``. That copy runs+:src:`testing/end2end/app_sandbox_probe.py`, which tries 26 operations+and prints which of them the kernel denied. The test:++#. checks that the node has no tree state and that the registry holds+ neither the tree nor an index, and empties the keepalive backend;+#. copies the application, a program it may execute and one it may not+ to the node, and runs the probe: nothing is denied;+#. builds the package as it ships and reads the rules of its two+ sandboxes back with ``bpm info data``, and checks that ``bpm build``+ fails for rules that name a sandbox the Beefile has no policy for;+#. publishes the package with :src:`tools/put-shields`, which builds it+ and pushes it to the ``sandboxes`` namespace, and loads the catalog+ with :doc:`/operate/backend/shields-put`;+#. creates ``shirudo/pipeline-tree`` with ``bpm tree append`` of the+ package by the reference and manifest digest ``put-shields`` printed,+ reads it back with ``bpm tree show`` and loads it with the ingest+ job;+#. syncs the node, which reaches seq 1, pins the upatch and labels the+ application with policy bit ``0x1`` and the program it may execute+ with ``0x2``;+#. runs the probe in the application: 16 operations are denied, the+ other program, the connections and datagrams to addresses outside+ the loopback networks, a raw socket and each way to create, rename,+ write or truncate a ``.php`` file, and 10 are allowed, among them the+ helper, the loopback and reading a ``.php`` file;+#. runs the probe with the node's own ``python3``, which no policy+ labels: nothing is denied;+#. sends a keepalive and checks ``5 head: pass, seq 1 of 1`` and ``6+ set: pass, 1 loaded`` in the node's status;+#. appends the package again with ``--op delete``, loads the tree and+ syncs the node, which reaches seq 2 and removes the pins while the+ label stays, and runs the probe in the application a third time:+ nothing is denied;+#. sends a keepalive and checks ``seq 2 of 2`` and ``0 loaded``.++Like ``t9113``, it does not check that the node is ``healthy``.+Select test scripts~~~~~~~~~~~~~~~~~~~diff --git a/Documentation/figures/contribute-end2end-run.tex b/Documentation/figures/contribute-end2end-run.texindex bba8a40a..38f2c013 100644--- a/Documentation/figures/contribute-end2end-run.tex+++ b/Documentation/figures/contribute-end2end-run.tex@@ -27,6 +27,7 @@\draw[bar] (479,37) rectangle (569,73);\draw[run] (575,37) rectangle (663,73);\draw[run] (757,37) rectangle (839,73);+ \draw[run] (845,37) rectangle (927,73);\draw[run] (933,37) rectangle (1011,73);% containers\draw[bar] (172,79) rectangle (663,115);@@ -44,8 +45,9 @@\draw[bar] (479,247) rectangle (663,283);% second pair\draw[bar] (669,289) rectangle (839,325);- % third edge node- \draw[bar] (845,331) rectangle (1011,367);+ % third and fourth edge nodes+ \draw[bar] (845,331) rectangle (927,367);+ \draw[bar] (933,331) rectangle (1011,367);\begin{scope}[every node/.append style={anchor=base}]\foreach \x/\n in {168/1, 266/2, 356/3, 437/4, 524/5, 619/6,@@ -54,7 +56,7 @@\foreach \y/\t in {61/host, 103/containers, 145/operator VM,187/node A, 229/node B, 271/edge node, 313/second pair,- 355/third node}+ 355/lone nodes}\node[anchor=base west] at (0,\y) {\t};\begin{scope}[small]@@ -66,7 +68,8 @@\node at (619,52) {t9109, t9110,};\node at (619,66.5) {t9112};\node at (798,59.5) {t9111};- \node at (972,52) {t9113,};+ \node at (886,59.5) {t9113};+ \node at (972,52) {t9114,};\node at (972,66.5) {teardown};\node at (417.5,101.5) {registry, two collectors, two ClickHouse@@ -75,8 +78,8 @@\node at (710,108.5) {empty again};\node at (886,94) {registry};\node at (886,108.5) {empty again};- \node at (972,94) {stop at};- \node at (972,108.5) {the end};+ \node at (972,94) {registry};+ \node at (972,108.5) {empty again};\node at (266,136) {operator.sh};\node at (266,150.5) {publishes};@@ -96,8 +99,9 @@\node at (752,304) {fresh edge node and};\node at (752,318.5) {node B boot};- \node at (928,346) {fresh edge node boots,};- \node at (928,360.5) {on x86-64 only};+ \node at (886,346) {third,};+ \node at (886,360.5) {on x86-64};+ \node at (972,353.5) {fourth};\end{scope}\end{scope}\end{tikzpicture}diff --git a/Documentation/images/contribute-end2end-run.svg b/Documentation/images/contribute-end2end-run.svgindex 8ca3d7c3..275eecf5 100644--- a/Documentation/images/contribute-end2end-run.svg+++ b/Documentation/images/contribute-end2end-run.svg@@ -1,4 +1,4 @@-<svg xmlns='http://www.w3.org/2000/svg' width='1016.0' height='372.0' viewBox='-72 -72 761.995 278.998' class='fig fig-f-ink' role='img'><!-- Documentation/figures/contribute-end2end-run.tex, sha256 5e3f4df91d89e5a28ae56dff55023c9df90dc8ac4087c94e64986e9d794c87cb --><style>.fig-f-ink{fill:var(--fig-ink,#171b22)}.fig-s-ink{stroke:var(--fig-ink,#171b22)}.fig-f-muted{fill:var(--fig-muted,#5d6675)}.fig-s-muted{stroke:var(--fig-muted,#5d6675)}.fig-f-line{fill:var(--fig-line,#8a93a0)}.fig-s-line{stroke:var(--fig-line,#8a93a0)}.fig-f-grid{fill:var(--fig-grid,#e2e6eb)}.fig-s-grid{stroke:var(--fig-grid,#e2e6eb)}.fig-f-axis{fill:var(--fig-axis,#c3c9d1)}.fig-s-axis{stroke:var(--fig-axis,#c3c9d1)}.fig-f-accent{fill:var(--fig-accent,#8b1e3f)}.fig-s-accent{stroke:var(--fig-accent,#8b1e3f)}.fig-f-s1{fill:var(--fig-s1,#2a78d6)}.fig-s-s1{stroke:var(--fig-s1,#2a78d6)}.fig-f-s2{fill:var(--fig-s2,#eb6834)}.fig-s-s2{stroke:var(--fig-s2,#eb6834)}.fig-f-s3{fill:var(--fig-s3,#1baf7a)}.fig-s-s3{stroke:var(--fig-s3,#1baf7a)}.fig-f-s4{fill:var(--fig-s4,#eda100)}.fig-s-s4{stroke:var(--fig-s4,#eda100)}.fig-f-free{fill:var(--fig-free,#dde2e8)}.fig-s-free{stroke:var(--fig-free,#dde2e8)}.fig-f-on{fill:var(--fig-on,#ffffff)}.fig-s-on{stroke:var(--fig-on,#ffffff)}@media (prefers-color-scheme:dark){.fig-f-ink{fill:var(--fig-ink,#e4e8ee)}.fig-s-ink{stroke:var(--fig-ink,#e4e8ee)}.fig-f-muted{fill:var(--fig-muted,#9ba5b3)}.fig-s-muted{stroke:var(--fig-muted,#9ba5b3)}.fig-f-line{fill:var(--fig-line,#8a93a0)}.fig-s-line{stroke:var(--fig-line,#8a93a0)}.fig-f-grid{fill:var(--fig-grid,#262d37)}.fig-s-grid{stroke:var(--fig-grid,#262d37)}.fig-f-axis{fill:var(--fig-axis,#39414c)}.fig-s-axis{stroke:var(--fig-axis,#39414c)}.fig-f-accent{fill:var(--fig-accent,#e8899f)}.fig-s-accent{stroke:var(--fig-accent,#e8899f)}.fig-f-s1{fill:var(--fig-s1,#3987e5)}.fig-s-s1{stroke:var(--fig-s1,#3987e5)}.fig-f-s2{fill:var(--fig-s2,#d95926)}.fig-s-s2{stroke:var(--fig-s2,#d95926)}.fig-f-s3{fill:var(--fig-s3,#199e70)}.fig-s-s3{stroke:var(--fig-s3,#199e70)}.fig-f-s4{fill:var(--fig-s4,#c98500)}.fig-s-s4{stroke:var(--fig-s4,#c98500)}.fig-f-free{fill:var(--fig-free,#2f3640)}.fig-s-free{stroke:var(--fig-free,#2f3640)}.fig-f-on{fill:var(--fig-on,#ffffff)}.fig-s-on{stroke:var(--fig-on,#ffffff)}}</style>+<svg xmlns='http://www.w3.org/2000/svg' width='1016.0' height='372.0' viewBox='-72 -72 761.995 278.998' class='fig fig-f-ink' role='img'><!-- Documentation/figures/contribute-end2end-run.tex, sha256 63d249c32dbbe0aaf9f46a22140d466300084657d8d9d376ae5e0ed7d18538fc --><style>.fig-f-ink{fill:var(--fig-ink,#171b22)}.fig-s-ink{stroke:var(--fig-ink,#171b22)}.fig-f-muted{fill:var(--fig-muted,#5d6675)}.fig-s-muted{stroke:var(--fig-muted,#5d6675)}.fig-f-line{fill:var(--fig-line,#8a93a0)}.fig-s-line{stroke:var(--fig-line,#8a93a0)}.fig-f-grid{fill:var(--fig-grid,#e2e6eb)}.fig-s-grid{stroke:var(--fig-grid,#e2e6eb)}.fig-f-axis{fill:var(--fig-axis,#c3c9d1)}.fig-s-axis{stroke:var(--fig-axis,#c3c9d1)}.fig-f-accent{fill:var(--fig-accent,#8b1e3f)}.fig-s-accent{stroke:var(--fig-accent,#8b1e3f)}.fig-f-s1{fill:var(--fig-s1,#2a78d6)}.fig-s-s1{stroke:var(--fig-s1,#2a78d6)}.fig-f-s2{fill:var(--fig-s2,#eb6834)}.fig-s-s2{stroke:var(--fig-s2,#eb6834)}.fig-f-s3{fill:var(--fig-s3,#1baf7a)}.fig-s-s3{stroke:var(--fig-s3,#1baf7a)}.fig-f-s4{fill:var(--fig-s4,#eda100)}.fig-s-s4{stroke:var(--fig-s4,#eda100)}.fig-f-free{fill:var(--fig-free,#dde2e8)}.fig-s-free{stroke:var(--fig-free,#dde2e8)}.fig-f-on{fill:var(--fig-on,#ffffff)}.fig-s-on{stroke:var(--fig-on,#ffffff)}@media (prefers-color-scheme:dark){.fig-f-ink{fill:var(--fig-ink,#e4e8ee)}.fig-s-ink{stroke:var(--fig-ink,#e4e8ee)}.fig-f-muted{fill:var(--fig-muted,#9ba5b3)}.fig-s-muted{stroke:var(--fig-muted,#9ba5b3)}.fig-f-line{fill:var(--fig-line,#8a93a0)}.fig-s-line{stroke:var(--fig-line,#8a93a0)}.fig-f-grid{fill:var(--fig-grid,#262d37)}.fig-s-grid{stroke:var(--fig-grid,#262d37)}.fig-f-axis{fill:var(--fig-axis,#39414c)}.fig-s-axis{stroke:var(--fig-axis,#39414c)}.fig-f-accent{fill:var(--fig-accent,#e8899f)}.fig-s-accent{stroke:var(--fig-accent,#e8899f)}.fig-f-s1{fill:var(--fig-s1,#3987e5)}.fig-s-s1{stroke:var(--fig-s1,#3987e5)}.fig-f-s2{fill:var(--fig-s2,#d95926)}.fig-s-s2{stroke:var(--fig-s2,#d95926)}.fig-f-s3{fill:var(--fig-s3,#199e70)}.fig-s-s3{stroke:var(--fig-s3,#199e70)}.fig-f-s4{fill:var(--fig-s4,#c98500)}.fig-s-s4{stroke:var(--fig-s4,#c98500)}.fig-f-free{fill:var(--fig-free,#2f3640)}.fig-s-free{stroke:var(--fig-free,#2f3640)}.fig-f-on{fill:var(--fig-on,#ffffff)}.fig-s-on{stroke:var(--fig-on,#ffffff)}}</style><defs><path id='contribute-end2end-run-g1-28' d='M1.041 0H1.779V-4.11H3.705V0H4.442V-4.755H1.779V-6.174H2.801V-6.819H2.083C1.382-6.819 1.041-6.368 1.041-5.714V-4.755H.267V-4.11H1.041V0ZM4.073-5.87C4.387-5.87 4.525-6.036 4.525-6.285V-6.405C4.525-6.654 4.387-6.819 4.073-6.819S3.622-6.654 3.622-6.405V-6.285C3.622-6.036 3.76-5.87 4.073-5.87Z'/><path id='contribute-end2end-run-g1-44' d='M1.253-1.078C.866-1.078 .691-.857 .691-.534V-.405C.691-.157 .802 .028 1.051 .083C.949 .516 .728 .839 .359 1.226H.977C1.502 .774 1.815 .092 1.815-.405V-.534C1.815-.857 1.64-1.078 1.253-1.078Z'/>@@ -64,6 +64,7 @@<use id='contribute-end2end-run-g5-103' href='#contribute-end2end-run-g1-103' transform='scale(1.081)'/><use id='contribute-end2end-run-g5-104' href='#contribute-end2end-run-g1-104' transform='scale(1.081)'/><use id='contribute-end2end-run-g5-105' href='#contribute-end2end-run-g1-105' transform='scale(1.081)'/>+<use id='contribute-end2end-run-g5-108' href='#contribute-end2end-run-g1-108' transform='scale(1.081)'/><use id='contribute-end2end-run-g5-110' href='#contribute-end2end-run-g1-110' transform='scale(1.081)'/><use id='contribute-end2end-run-g5-111' href='#contribute-end2end-run-g1-111' transform='scale(1.081)'/><use id='contribute-end2end-run-g5-112' href='#contribute-end2end-run-g1-112' transform='scale(1.081)'/>@@ -119,6 +120,9 @@<path d='M569.875-30.865V-51.944C569.875-53.607 571.224-54.955 572.887-54.955H628.594C630.257-54.955 631.606-53.607 631.606-51.944V-30.865C631.606-29.202 630.257-27.854 628.594-27.854H572.887C571.224-27.854 569.875-29.202 569.875-30.865ZM631.606-54.955'/></g><g fill-opacity='0.12' class='fig-s-s1 fig-f-s1'>+<path d='M636.122-30.865V-51.944C636.122-53.607 637.471-54.955 639.134-54.955H694.841C696.505-54.955 697.853-53.607 697.853-51.944V-30.865C697.853-29.202 696.505-27.854 694.841-27.854H639.134C637.471-27.854 636.122-29.202 636.122-30.865ZM697.853-54.955'/>+</g>+<g fill-opacity='0.12' class='fig-s-s1 fig-f-s1'><path d='M702.37-30.865V-51.944C702.37-53.607 703.718-54.955 705.381-54.955H758.077C759.74-54.955 761.089-53.607 761.089-51.944V-30.865C761.089-29.202 759.74-27.854 758.077-27.854H705.381C703.718-27.854 702.37-29.202 702.37-30.865ZM761.089-54.955'/></g><g fill-opacity='0.08' class='fig-s-line fig-f-line'>@@ -152,7 +156,10 @@<path d='M503.628-220.573V-241.651C503.628-243.314 504.976-244.662 506.64-244.662H628.594C630.257-244.662 631.606-243.314 631.606-241.651V-220.573C631.606-218.91 630.257-217.561 628.594-217.561H506.64C504.976-217.561 503.628-218.91 503.628-220.573ZM631.606-244.662'/></g><g fill-opacity='0.08' class='fig-s-line fig-f-line'>-<path d='M636.122-252.191V-273.269C636.122-274.932 637.471-276.28 639.134-276.28H758.077C759.74-276.28 761.089-274.932 761.089-273.269V-252.191C761.089-250.527 759.74-249.179 758.077-249.179H639.134C637.471-249.179 636.122-250.527 636.122-252.191ZM761.089-276.28'/>+<path d='M636.122-252.191V-273.269C636.122-274.932 637.471-276.28 639.134-276.28H694.841C696.505-276.28 697.853-274.932 697.853-273.269V-252.191C697.853-250.527 696.505-249.179 694.841-249.179H639.134C637.471-249.179 636.122-250.527 636.122-252.191ZM697.853-276.28'/>+</g>+<g fill-opacity='0.08' class='fig-s-line fig-f-line'>+<path d='M702.37-252.191V-273.269C702.37-274.932 703.718-276.28 705.381-276.28H758.077C759.74-276.28 761.089-274.932 761.089-273.269V-252.191C761.089-250.527 759.74-249.179 758.077-249.179H705.381C703.718-249.179 702.37-250.527 702.37-252.191ZM761.089-276.28'/></g><g stroke='none' transform='matrix(1.004 0 0 -1.004 195.73 -88.832)' class='fig-f-muted'><use x='-72' y='-72' href='#contribute-end2end-run-g3-49'/>@@ -252,15 +259,15 @@<use x='-23.59' y='-72' href='#contribute-end2end-run-g5-114'/></g><g transform='matrix(1.004 0 0 -1.004 72.27 -339.517)' stroke='none' class='fig-f-ink'>-<use x='-72' y='-72' href='#contribute-end2end-run-g5-116'/>-<use x='-68.49' y='-72' href='#contribute-end2end-run-g5-104'/>-<use x='-62.81' y='-72' href='#contribute-end2end-run-g5-105'/>-<use x='-60.31' y='-72' href='#contribute-end2end-run-g5-114'/>-<use x='-56.7' y='-72' href='#contribute-end2end-run-g5-100'/>-<use x='-48.54' y='-72' href='#contribute-end2end-run-g5-110'/>-<use x='-42.86' y='-72' href='#contribute-end2end-run-g5-111'/>-<use x='-37.26' y='-72' href='#contribute-end2end-run-g5-100'/>-<use x='-31.46' y='-72' href='#contribute-end2end-run-g5-101'/>+<use x='-72' y='-72' href='#contribute-end2end-run-g5-108'/>+<use x='-69.28' y='-72' href='#contribute-end2end-run-g5-111'/>+<use x='-63.68' y='-72' href='#contribute-end2end-run-g5-110'/>+<use x='-58' y='-72' href='#contribute-end2end-run-g5-101'/>+<use x='-50.15' y='-72' href='#contribute-end2end-run-g5-110'/>+<use x='-44.47' y='-72' href='#contribute-end2end-run-g5-111'/>+<use x='-38.87' y='-72' href='#contribute-end2end-run-g5-100'/>+<use x='-33.07' y='-72' href='#contribute-end2end-run-g5-101'/>+<use x='-27.58' y='-72' href='#contribute-end2end-run-g5-115'/></g><g transform='matrix(1.004 0 0 -1.004 167.527 -117.062)' stroke='none' class='fig-f-ink'><use x='-72' y='-72' href='#contribute-end2end-run-g1-116'/>@@ -349,12 +356,19 @@<use x='-57.653' y='-72' href='#contribute-end2end-run-g1-49'/><use x='-52.103' y='-72' href='#contribute-end2end-run-g1-49'/></g>-<g transform='matrix(1.004 0 0 -1.004 789.965 -111.416)' stroke='none' class='fig-f-ink'>+<g transform='matrix(1.004 0 0 -1.004 726.486 -117.062)' stroke='none' class='fig-f-ink'><use x='-72' y='-72' href='#contribute-end2end-run-g1-116'/><use x='-68.753' y='-72' href='#contribute-end2end-run-g1-57'/><use x='-63.203' y='-72' href='#contribute-end2end-run-g1-49'/><use x='-57.653' y='-72' href='#contribute-end2end-run-g1-49'/><use x='-52.103' y='-72' href='#contribute-end2end-run-g1-51'/>+</g>+<g transform='matrix(1.004 0 0 -1.004 789.965 -111.416)' stroke='none' class='fig-f-ink'>+<use x='-72' y='-72' href='#contribute-end2end-run-g1-116'/>+<use x='-68.753' y='-72' href='#contribute-end2end-run-g1-57'/>+<use x='-63.203' y='-72' href='#contribute-end2end-run-g1-49'/>+<use x='-57.653' y='-72' href='#contribute-end2end-run-g1-49'/>+<use x='-52.103' y='-72' href='#contribute-end2end-run-g1-52'/><use x='-46.553' y='-72' href='#contribute-end2end-run-g1-44'/></g><g transform='matrix(1.004 0 0 -1.004 784.213 -122.332)' stroke='none' class='fig-f-ink'>@@ -456,21 +470,27 @@<use x='-28.756' y='-72' href='#contribute-end2end-run-g1-105'/><use x='-26.444' y='-72' href='#contribute-end2end-run-g1-110'/></g>-<g transform='matrix(1.004 0 0 -1.004 789.664 -143.034)' stroke='none' class='fig-f-ink'>-<use x='-72' y='-72' href='#contribute-end2end-run-g1-115'/>-<use x='-67.56' y='-72' href='#contribute-end2end-run-g1-116'/>-<use x='-64.35' y='-72' href='#contribute-end2end-run-g1-111'/>-<use x='-59.17' y='-72' href='#contribute-end2end-run-g1-112'/>-<use x='-51.622' y='-72' href='#contribute-end2end-run-g1-97'/>-<use x='-46.683' y='-72' href='#contribute-end2end-run-g1-116'/>+<g transform='matrix(1.004 0 0 -1.004 788.234 -143.034)' stroke='none' class='fig-f-ink'>+<use x='-72' y='-72' href='#contribute-end2end-run-g1-114'/>+<use x='-68.652' y='-72' href='#contribute-end2end-run-g1-101'/>+<use x='-63.573' y='-72' href='#contribute-end2end-run-g1-103'/>+<use x='-58.689' y='-72' href='#contribute-end2end-run-g1-105'/>+<use x='-56.377' y='-72' href='#contribute-end2end-run-g1-115'/>+<use x='-51.937' y='-72' href='#contribute-end2end-run-g1-116'/>+<use x='-48.69' y='-72' href='#contribute-end2end-run-g1-114'/>+<use x='-45.203' y='-72' href='#contribute-end2end-run-g1-121'/></g>-<g transform='matrix(1.004 0 0 -1.004 788.21 -153.95)' stroke='none' class='fig-f-ink'>-<use x='-72' y='-72' href='#contribute-end2end-run-g1-116'/>-<use x='-68.753' y='-72' href='#contribute-end2end-run-g1-104'/>-<use x='-63.499' y='-72' href='#contribute-end2end-run-g1-101'/>-<use x='-56.238' y='-72' href='#contribute-end2end-run-g1-101'/>-<use x='-51.16' y='-72' href='#contribute-end2end-run-g1-110'/>-<use x='-45.906' y='-72' href='#contribute-end2end-run-g1-100'/>+<g transform='matrix(1.004 0 0 -1.004 778.499 -153.95)' stroke='none' class='fig-f-ink'>+<use x='-72' y='-72' href='#contribute-end2end-run-g1-101'/>+<use x='-66.922' y='-72' href='#contribute-end2end-run-g1-109'/>+<use x='-58.847' y='-72' href='#contribute-end2end-run-g1-112'/>+<use x='-53.537' y='-72' href='#contribute-end2end-run-g1-116'/>+<use x='-50.29' y='-72' href='#contribute-end2end-run-g1-121'/>+<use x='-43.492' y='-72' href='#contribute-end2end-run-g1-97'/>+<use x='-38.552' y='-72' href='#contribute-end2end-run-g1-103'/>+<use x='-33.696' y='-72' href='#contribute-end2end-run-g1-97'/>+<use x='-28.756' y='-72' href='#contribute-end2end-run-g1-105'/>+<use x='-26.444' y='-72' href='#contribute-end2end-run-g1-110'/></g><g transform='matrix(1.004 0 0 -1.004 248.808 -174.652)' stroke='none' class='fig-f-ink'><use x='-72' y='-72' href='#contribute-end2end-run-g1-111'/>@@ -612,28 +632,15 @@<use x='-30.172' y='-72' href='#contribute-end2end-run-g1-111'/><use x='-24.992' y='-72' href='#contribute-end2end-run-g1-116'/></g>-<g transform='matrix(1.004 0 0 -1.004 723.245 -332.741)' stroke='none' class='fig-f-ink'>-<use x='-72' y='-72' href='#contribute-end2end-run-g1-102'/>-<use x='-69.003' y='-72' href='#contribute-end2end-run-g1-114'/>-<use x='-65.655' y='-72' href='#contribute-end2end-run-g1-101'/>-<use x='-60.576' y='-72' href='#contribute-end2end-run-g1-115'/>-<use x='-56.072' y='-72' href='#contribute-end2end-run-g1-104'/>-<use x='-48.635' y='-72' href='#contribute-end2end-run-g1-101'/>-<use x='-43.556' y='-72' href='#contribute-end2end-run-g1-100'/>-<use x='-38.191' y='-72' href='#contribute-end2end-run-g1-103'/>-<use x='-33.363' y='-72' href='#contribute-end2end-run-g1-101'/>-<use x='-26.102' y='-72' href='#contribute-end2end-run-g1-110'/>-<use x='-20.848' y='-72' href='#contribute-end2end-run-g1-111'/>-<use x='-15.668' y='-72' href='#contribute-end2end-run-g1-100'/>-<use x='-10.303' y='-72' href='#contribute-end2end-run-g1-101'/>-<use x='-3.041' y='-72' href='#contribute-end2end-run-g1-98'/>-<use x='2.324' y='-72' href='#contribute-end2end-run-g1-111'/>-<use x='7.504' y='-72' href='#contribute-end2end-run-g1-111'/>-<use x='12.684' y='-72' href='#contribute-end2end-run-g1-116'/>-<use x='15.93' y='-72' href='#contribute-end2end-run-g1-115'/>-<use x='20.389' y='-72' href='#contribute-end2end-run-g1-44'/>-</g>-<g transform='matrix(1.004 0 0 -1.004 739.331 -343.657)' stroke='none' class='fig-f-ink'>+<g transform='matrix(1.004 0 0 -1.004 728.2 -332.741)' stroke='none' class='fig-f-ink'>+<use x='-72' y='-72' href='#contribute-end2end-run-g1-116'/>+<use x='-68.753' y='-72' href='#contribute-end2end-run-g1-104'/>+<use x='-63.499' y='-72' href='#contribute-end2end-run-g1-105'/>+<use x='-61.187' y='-72' href='#contribute-end2end-run-g1-114'/>+<use x='-57.848' y='-72' href='#contribute-end2end-run-g1-100'/>+<use x='-52.483' y='-72' href='#contribute-end2end-run-g1-44'/>+</g>+<g transform='matrix(1.004 0 0 -1.004 717.578 -343.657)' stroke='none' class='fig-f-ink'><use x='-72' y='-72' href='#contribute-end2end-run-g1-111'/><use x='-66.82' y='-72' href='#contribute-end2end-run-g1-110'/><use x='-59.383' y='-72' href='#contribute-end2end-run-g1-120'/>@@ -642,10 +649,14 @@<use x='-43.593' y='-72' href='#contribute-end2end-run-g1-45'/><use x='-39.903' y='-72' href='#contribute-end2end-run-g1-54'/><use x='-34.353' y='-72' href='#contribute-end2end-run-g1-52'/>-<use x='-26.62' y='-72' href='#contribute-end2end-run-g1-111'/>-<use x='-21.44' y='-72' href='#contribute-end2end-run-g1-110'/>-<use x='-16.186' y='-72' href='#contribute-end2end-run-g1-108'/>-<use x='-13.762' y='-72' href='#contribute-end2end-run-g1-121'/>+</g>+<g transform='matrix(1.004 0 0 -1.004 791.288 -338.388)' stroke='none' class='fig-f-ink'>+<use x='-72' y='-72' href='#contribute-end2end-run-g1-102'/>+<use x='-69.04' y='-72' href='#contribute-end2end-run-g1-111'/>+<use x='-63.86' y='-72' href='#contribute-end2end-run-g1-117'/>+<use x='-58.606' y='-72' href='#contribute-end2end-run-g1-114'/>+<use x='-55.174' y='-72' href='#contribute-end2end-run-g1-116'/>+<use x='-51.928' y='-72' href='#contribute-end2end-run-g1-104'/></g></g></g>diff --git a/Documentation/upatches/learn/examples.rst b/Documentation/upatches/learn/examples.rstindex ff0b2174..68dd538c 100644--- a/Documentation/upatches/learn/examples.rst+++ b/Documentation/upatches/learn/examples.rst@@ -180,8 +180,9 @@ bit and the rules of ``sandbox_policy``, and refuse with ``EACCES``:reads the bit from the Beefile and the rules from ``sandbox.toml``, andfails the build for rules without a policy table. The package's``README.md`` describes the rule keys and what the sandboxes do not-cover. :src:`tools/put-shields` publishes it with the shields of-``kernel-cve``.+cover. ``t9114-app-sandbox`` takes the package from its sources to a+node and back (:ref:`testing-sandbox`), and :src:`tools/put-shields`+publishes it with the shields of ``kernel-cve``.Related-------diff --git a/testing/end2end/app_sandbox_probe.py b/testing/end2end/app_sandbox_probe.pynew file mode 100644index 00000000..4610626f--- /dev/null+++ b/testing/end2end/app_sandbox_probe.py@@ -0,0 +1,120 @@+#!/usr/bin/env python3+# SPDX-License-Identifier: BSD-2-Clause+# Copyright (c) 2026 Authors of shirudo+"""What t9114 runs in a node, in and out of the app-sandbox upatch.++ app_sandbox_probe.py setup <dir> make the files the checks work on+ app_sandbox_probe.py run <dir> print "<check> allowed|denied" for+ each operation the sandbox rules on++A check is denied when the kernel refuses it with EACCES, and allowed+with any other outcome: a connection nobody accepts was still let out.+"""++import errno+import os+import shutil+import socket+import subprocess+import sys++# TEST-NET-1 and the IPv6 documentation prefix: routed nowhere.+REMOTE_V4 = "192.0.2.1"+REMOTE_V6 = "2001:db8::1"+PORT = 9+++def setup(work):+ files = os.path.join(work, "files")+ shutil.rmtree(files, ignore_errors=True)+ os.mkdir(files)+ for name in ("existing.php", "moved.php", "cut.php", "note.txt", "plain.txt"):+ with open(os.path.join(files, name), "w") as stream:+ stream.write("data\n")+++def execute(path):+ subprocess.run([path], check=True)+++def connect(family, address):+ with socket.socket(family, socket.SOCK_STREAM) as sock:+ sock.setblocking(False)+ sock.connect((address, PORT))+++def send(family, address):+ with socket.socket(family, socket.SOCK_DGRAM) as sock:+ sock.sendto(b"probe", (address, PORT))+++def raw_socket():+ socket.socket(socket.AF_INET, socket.SOCK_RAW, socket.IPPROTO_ICMP).close()+++def create(path):+ open(path, "x").close()+++def write(path):+ open(path, "r+").close()+++def read(path):+ open(path).close()+++def checks(work):+ def f(name):+ return os.path.join(work, "files", name)++ return [+ ("exec-helper", lambda: execute(os.path.join(work, "helper"))),+ ("exec-other", lambda: execute(os.path.join(work, "other"))),+ ("connect-loopback", lambda: connect(socket.AF_INET, "127.0.0.1")),+ ("connect-loopback-v6", lambda: connect(socket.AF_INET6, "::1")),+ ("connect-loopback-mapped",+ lambda: connect(socket.AF_INET6, "::ffff:127.0.0.1")),+ ("connect-remote", lambda: connect(socket.AF_INET, REMOTE_V4)),+ ("connect-remote-v6", lambda: connect(socket.AF_INET6, REMOTE_V6)),+ ("connect-remote-mapped",+ lambda: connect(socket.AF_INET6, "::ffff:" + REMOTE_V4)),+ ("send-loopback", lambda: send(socket.AF_INET, "127.0.0.1")),+ ("send-remote", lambda: send(socket.AF_INET, REMOTE_V4)),+ ("send-remote-v6", lambda: send(socket.AF_INET6, REMOTE_V6)),+ ("raw-socket", raw_socket),+ ("create-txt", lambda: create(f("new.txt"))),+ ("create-php", lambda: create(f("new.php"))),+ ("create-exact", lambda: create(f("core"))),+ ("create-longer", lambda: create(f("cores"))),+ ("mkdir-php", lambda: os.mkdir(f("dir.php"))),+ ("symlink-php", lambda: os.symlink("note.txt", f("symlink.php"))),+ ("link-php", lambda: os.link(f("note.txt"), f("link.php"))),+ ("rename-txt", lambda: os.rename(f("plain.txt"), f("renamed.txt"))),+ ("rename-to-php", lambda: os.rename(f("note.txt"), f("note.php"))),+ ("rename-from-php", lambda: os.rename(f("moved.php"), f("moved.txt"))),+ ("read-php", lambda: read(f("existing.php"))),+ ("write-php", lambda: write(f("existing.php"))),+ ("truncate-php", lambda: os.truncate(f("cut.php"), 0)),+ ("write-txt", lambda: write(f("new.txt"))),+ ]+++def run(work):+ for name, check in checks(work):+ try:+ check()+ verdict = "allowed"+ except OSError as error:+ verdict = "denied" if error.errno == errno.EACCES else "allowed"+ print(name, verdict)+++def main():+ if len(sys.argv) != 3 or sys.argv[1] not in ("setup", "run"):+ sys.exit(__doc__)+ {"setup": setup, "run": run}[sys.argv[1]](sys.argv[2])+++if __name__ == "__main__":+ main()diff --git a/testing/end2end/host.sh b/testing/end2end/host.shindex c32bf3ac..db0db10e 100755--- a/testing/end2end/host.sh+++ b/testing/end2end/host.sh@@ -12,7 +12,8 @@# and node B then take their place, on a registry that holds no tree, and# t9111 runs against them. On x86-64, which the java-base64 shield# selects, a third fresh edge node takes theirs, the registry empty again,-# and t9113 runs against it.+# and t9113 runs against it. A last fresh edge node and an empty registry+# are for t9114.set -eu@@ -193,19 +194,20 @@ second_pair() {die "the second pair is not labelled role=edge and role=core"}-# Boot a third fresh edge node for t9113, alone, once the second pair has-# stopped. It follows the same tree as the others, so the registry starts-# again and holds neither that tree nor a shield.-third_node() {- NODE_ROUND=-3+# Boot a fresh edge node alone, in round $1 and called the $2 one, once+# the nodes before it have stopped. It follows the same tree as the+# others, so the registry starts again and holds neither that tree nor a+# package.+lone_node() {+ NODE_ROUND=$1rm -rf -- "$NODES_DIR/node-edge" "$NODES_DIR/node-b"docker rm -fv "$STACK_NAME-registry" >/dev/null 2>&1 || :- stack_oci || die "the registry did not come up a third time"- say "a third fresh edge node, in $E2E_VM$NODE_ROUND-end2end-edge"+ stack_oci || die "the registry did not come up for the $2 edge node"+ say "a $2 fresh edge node, in $E2E_VM$NODE_ROUND-end2end-edge"node_boot edgenode_wait edge 0 || {tail -n 40 "$W/node-edge$NODE_ROUND.log" >&2- die "the third edge node did not boot; see $W/node-edge$NODE_ROUND.log"+ die "the $2 edge node did not boot; see $W/node-edge$NODE_ROUND.log"}}@@ -409,10 +411,15 @@ node_down b ""node_clean bif [ "$(uname -m)" = x86_64 ]; then- third_node+ lone_node -3 thirdhost_test t9113-shield-rolloutnode_down edge ""node_clean edgefi+lone_node -4 fourth+host_test t9114-app-sandbox+node_down edge ""+node_clean edge+say "ok"diff --git a/testing/end2end/t9114-app-sandbox.sh b/testing/end2end/t9114-app-sandbox.shnew file mode 100755index 00000000..9faf5480--- /dev/null+++ b/testing/end2end/t9114-app-sandbox.sh@@ -0,0 +1,237 @@+#!/bin/sh+# SPDX-License-Identifier: BSD-2-Clause+# Copyright (c) 2026 Authors of shirudo+#+# t9114 -- the app-sandbox upatch through the whole pipeline. The+# operator builds the package of upatches/app-sandbox, with probe.Beefile+# and the rules of fixtures/app-sandbox, which sandbox a program of this+# test, publishes it to a namespace, where the backend lists it as+# available, and appends it to a new tree by its reference and digest.+# The node pulls it, and the program then executes, connects and writes+# only what its sandbox allows, while a program outside it is left+# alone. The operator deletes it from the tree, the node unloads it, and+# the program is unrestricted again.+#+# end2end/host.sh runs it on the host last, as root, against a fresh edge+# node of its own and a registry that holds no tree.++cd "$(dirname "$0")/.."+. ./test-lib.sh++REPO=$(cd .. && pwd)+E2E=${E2E:-$REPO/build/test-vm/end2end}+S=$REPO/shirudo+CHECKS=$PWD/end2end/pipeline_checks.py+REGISTRY=${REGISTRY:-127.0.0.1:15443}+STACK_NAME=${STACK_NAME:-shirudo-end2end}+NAMESPACE=oci://$REGISTRY/sandboxes+REPOSITORY=shirudo/pipeline-tree+TREE=oci://$REGISTRY/$REPOSITORY+TREE_ID=pipeline-tree+UPATCH=app-sandbox+VERSION=1.0.0+RUNTIME=/usr/local/bin/shirudo-runtime+STATE=/var/lib/shirudo/bpm/upatch-tree+PINS=/run/shirudo/bpffs/upatches/$UPATCH+# The paths probe.Beefile of fixtures/app-sandbox labels are under it.+APP_DIR=/tmp/shirudo-app-sandbox+PROBE=/workspace/shirudo/testing/end2end/app_sandbox_probe.py+CLICKHOUSE_CLIENT="docker exec -i $STACK_NAME-backend-clickhouse clickhouse-client"+export CLICKHOUSE_CLIENT++[ -n "${END2END_BACKEND-}" ] && [ -n "${END2END_KEYS-}" ] ||+ test_skip_all "end2end/host.sh runs it last, with a keepalive backend"+BACKEND=$END2END_BACKEND+KEYS=$END2END_KEYS+command -v docker >/dev/null 2>&1 || test_skip_all "no docker"+command -v python3 >/dev/null 2>&1 || test_skip_all "no python3"+[ -s "$E2E/ca.pem" ] || test_skip_all "no registry and collector CA in $E2E"+. ./vm/stack-lib.sh+. ./end2end/node-lib.sh+. ./end2end/pipeline-lib.sh+node_wait edge 0 || test_skip_all "the fresh edge node is not up"+W=$(mktemp -d)+trap 'rm -rf "$W"' EXIT++# Copy the package directory of upatches/app-sandbox to $W/$1, with the+# headers bpm build looks for beside the Beefile.+stage() {+ mkdir -p "$W/$1" &&+ cp "$REPO/upatches/$UPATCH/Beefile" "$REPO/upatches/$UPATCH/sandbox.toml" \+ "$REPO/upatches/$UPATCH/gen_policy.py" \+ "$REPO/upatches/$UPATCH/$UPATCH.bpf.c" "$W/$1/" &&+ ln -s "$REPO/vendor" "$REPO/bpf" "$W/$1/"+}++# Run the probe in the node with the interpreter $1 and write the checks+# the kernel denied it to $W/denied, one name per line. The probe makes+# 26 checks.+probe() {+ on edge "python3 $PROBE setup $APP_DIR && $1 $PROBE run $APP_DIR" \+ >"$W/probe" &&+ test "$(wc -l <"$W/probe")" = 26 &&+ sed -n "s/ denied\$//p" "$W/probe" >"$W/denied"+}++# The policy bits the node's file $1 is labeled with, in hexadecimal, or+# none for a file without the label.+policy_bits() {+ on edge "python3 -c 'import errno, os, sys+try:+ value = os.getxattr(sys.argv[1], \"security.bpf.shirudo.policy\")+except OSError as error:+ assert error.errno == errno.ENODATA, error+ print(\"none\")+else:+ print(hex(int.from_bytes(value, sys.byteorder)))' $1"+}++test_expect_success 'the node has followed no tree, and the registry holds no tree and no package' '+ on edge "[ ! -e $STATE/state.json ] && [ ! -e $STATE/outcomes ]" &&+ on edge "[ ! -e $PINS ]" &&+ test "$(manifest_status "$REPOSITORY/manifests/stable")" = 404 &&+ test "$(manifest_status sandboxes/bpm-index/manifests/stable)" = 404+'++test_expect_success 'the backend starts empty' '+ ch "DROP DATABASE IF EXISTS shirudo SYNC" &&+ ch "DROP DATABASE IF EXISTS otel SYNC" &&+ stack_backend_schema "$BACKEND" &&+ ch "INSERT INTO shirudo.settings (stale_seconds, stuck_seconds, window)+ VALUES (600, 3600, 7)" &&+ version=$(on edge "$RUNTIME version --version-id") &&+ ch "INSERT INTO shirudo.expected_builds (version_id, note)+ VALUES ('\''$version'\'', '\''t9114'\'')" &&+ test "$(ch "SELECT count() FROM shirudo.shield_catalog")" = 0+'++test_expect_success 'the node trusts the CA and reaches the registry' '+ node_reach edge+'++# The application is a copy of the interpreter, so that the label goes on+# a file of this test and python3 itself stays outside the sandbox.+test_expect_success 'the node has the application and the programs it may and may not execute' '+ on edge "rm -rf $APP_DIR && mkdir $APP_DIR &&+ cp -L /usr/bin/python3 $APP_DIR/app &&+ cp -L /usr/bin/true $APP_DIR/helper &&+ cp -L /usr/bin/true $APP_DIR/other"+'++test_expect_success 'without the sandbox, the application is denied nothing' '+ probe "$APP_DIR/app" &&+ test ! -s "$W/denied"+'++test_expect_success 'the package of upatches/app-sandbox builds with the rules it ships' '+ stage shipped &&+ (cd "$W" && "$S" bpm build shipped --version "$VERSION" \+ --keys-dir "$KEYS") >&2 &&+ "$S" bpm info data "$W/$UPATCH-$VERSION.bee" "upatches/$UPATCH.upatch" \+ >"$W/shipped.data" &&+ grep -qF ".sandboxes = (__u64)3," "$W/shipped.data" &&+ grep -qF ".net_enforced = (__u64)3," "$W/shipped.data"+'++test_expect_success 'a sandbox the Beefile declares no policy for fails the build' '+ stage unknown &&+ printf "[sandbox.nobody]\nexec = []\n" >"$W/unknown/sandbox.toml" &&+ ! (cd "$W" && "$S" bpm build unknown --version "$VERSION" \+ --keys-dir "$KEYS") 2>"$W/unknown.err" &&+ grep -qF "the Beefile has no policy nobody" "$W/unknown.err"+'++test_expect_success 'the operator publishes the package, and the backend lists it as available' '+ stage "pkg/$UPATCH" &&+ cp "$PWD/fixtures/$UPATCH/probe.Beefile" "$W/pkg/$UPATCH/Beefile" &&+ cp "$PWD/fixtures/$UPATCH/sandbox.toml" "$W/pkg/$UPATCH/" &&+ SHIRUDO=$S "$REPO/tools/put-shields" --version "$VERSION" --keys-dir "$KEYS" \+ --catalog "$W/shields.json" --new-index "$NAMESPACE" "$W/pkg/$UPATCH" \+ >"$W/append" &&+ read -r _shirudo _bpm _tree _append reference _option digest _rest \+ <"$W/append" &&+ test "$reference" = "$NAMESPACE/$UPATCH:$VERSION" &&+ "$BACKEND/jobs/shields-put" "$W/shields.json" >&2 &&+ printf "%s\t%s\t%s\n" "$reference" "$UPATCH" "${digest#sha256:}" \+ >"$W/catalog" &&+ ch_cmp "SELECT reference, id, manifest_digest+ FROM shirudo.shield_catalog FINAL" "$W/catalog" &&+ test "$(ch "SELECT count() FROM shirudo.tree_ops")" = 0+'++test_expect_success 'the operator creates the tree with the package' '+ tree_append_pushed &&+ test "$(manifest_status "$REPOSITORY/manifests/stable")" = 200 &&+ "$S" bpm tree show "$TREE" --cert "$KEYS/cert.der" >"$W/show.json" &&+ tree_ingest &&+ printf "%s\t1\tadd\t%s\n" "$TREE_ID" "$UPATCH" >"$W/ops" &&+ ch_cmp "SELECT tree_id, seq, op, id FROM shirudo.tree_ops FINAL+ ORDER BY seq" "$W/ops"+'++test_expect_success 'the node pulls the tree, loads the upatch and labels the files of the sandbox' '+ sync_to 1 1 &&+ on edge "[ -d $PINS ]" &&+ test "$(policy_bits "$APP_DIR/app")" = 0x1 &&+ test "$(policy_bits "$APP_DIR/helper")" = 0x2 &&+ test "$(policy_bits "$APP_DIR/other")" = none+'++test_expect_success 'the application executes, connects and writes only what its sandbox allows' '+ probe "$APP_DIR/app" &&+ cat >"$W/expected" <<-\EOT &&+ exec-other+ connect-remote+ connect-remote-v6+ connect-remote-mapped+ send-remote+ send-remote-v6+ raw-socket+ create-php+ create-exact+ mkdir-php+ symlink-php+ link-php+ rename-to-php+ rename-from-php+ write-php+ truncate-php+ EOT+ diff -u "$W/expected" "$W/denied" >&2+'++test_expect_success 'a program outside the sandbox is denied nothing' '+ probe python3 &&+ test ! -s "$W/denied"+'++test_expect_success 'the backend sees the node at the head of the tree, the upatch loaded' '+ head_report 1 1+'++test_expect_success 'the operator deletes the package from the tree' '+ tree_append_pushed delete &&+ tree_ingest &&+ printf "%s\t1\tadd\t%s\n%s\t2\tdelete\t%s\n" "$TREE_ID" "$UPATCH" \+ "$TREE_ID" "$UPATCH" >"$W/ops" &&+ ch_cmp "SELECT tree_id, seq, op, id FROM shirudo.tree_ops FINAL+ ORDER BY seq" "$W/ops"+'++# An unload leaves the labels, which restrict nothing without the upatch.+test_expect_success 'the node pulls the delete and unloads the upatch' '+ sync_to 2 "1 2" &&+ on edge "[ ! -e $PINS ]" &&+ test "$(policy_bits "$APP_DIR/app")" = 0x1+'++test_expect_success 'the application is denied nothing again' '+ probe "$APP_DIR/app" &&+ test ! -s "$W/denied"+'++test_expect_success 'the backend sees the node at the delete, nothing loaded' '+ head_report 2 0+'++test_donediff --git a/testing/fixtures/app-sandbox/probe.Beefile b/testing/fixtures/app-sandbox/probe.Beefilenew file mode 100644index 00000000..f380e991--- /dev/null+++ b/testing/fixtures/app-sandbox/probe.Beefile@@ -0,0 +1,27 @@+[package]+name = "app-sandbox"+description = "The app-sandbox upatch with the sandbox of the end-to-end test"+license = "GPL-2.0 OR BSD-2-Clause"+authors = ["Authors of shirudo"]++[[upatches]]+source = "app-sandbox.bpf.c"++[[upatches.rodata]]+symbol = "sandbox_policy"+input = "sandbox.toml"+generator = ["python3", "gen_policy.py"]+update = ["python3", "gen_policy.py"]++[[upatches.policy]]+id = "probe"+bit = 0x1+paths = ["/tmp/shirudo-app-sandbox/app"]++[[upatches.policy]]+id = "probe-helpers"+bit = 0x2+paths = ["/tmp/shirudo-app-sandbox/helper"]++[upatches.tree]+id = "app-sandbox"diff --git a/testing/fixtures/app-sandbox/sandbox.toml b/testing/fixtures/app-sandbox/sandbox.tomlnew file mode 100644index 00000000..0afc12b9--- /dev/null+++ b/testing/fixtures/app-sandbox/sandbox.toml@@ -0,0 +1,16 @@+# SPDX-License-Identifier: BSD-2-Clause+# Copyright (c) 2026 Authors of shirudo+#+# The sandbox t9114 puts end2end/app_sandbox_probe.py in.++[networks]+loopback = ["127.0.0.0/8", "::1/128"]++[sandbox.probe]+exec = ["probe-helpers"]+network = ["@loopback"]++[sandbox.probe.deny]+create = ["*.php", "core"]+rename = ["*.php"]+write = ["*.php"]diff --git a/testing/functional/build/t1007-test-vm-cli.sh b/testing/functional/build/t1007-test-vm-cli.shindex 080e13ce..c82b7611 100755--- a/testing/functional/build/t1007-test-vm-cli.sh+++ b/testing/functional/build/t1007-test-vm-cli.sh@@ -964,17 +964,19 @@ test_expect_success 'the runners split the tests by number' 'test -e end2end/t9111-pipeline-segments.sh &&test -e end2end/t9112-activation.sh &&test -e end2end/t9113-shield-rollout.sh &&+ test -e end2end/t9114-app-sandbox.sh &&grep -Fqx " end2end/t9109-pipeline.sh | end2end/t9110-keepalive-history.sh) continue ;;" \run-target-tests.sh &&grep -Fqx " end2end/t9111-pipeline-segments.sh | end2end/t9112-activation.sh) continue ;;" \run-target-tests.sh &&grep -Fqx "host_test t9109-pipeline" end2end/host.sh &&grep -Fqx "host_test t9110-keepalive-history" end2end/host.sh &&- grep -Fqx " end2end/t9113-shield-rollout.sh) continue ;;" \+ grep -Fqx " end2end/t9113-shield-rollout.sh | end2end/t9114-app-sandbox.sh) continue ;;" \run-target-tests.sh &&grep -Fqx "host_test t9111-pipeline-segments" end2end/host.sh &&grep -Fqx "host_test t9112-activation" end2end/host.sh &&- grep -Fqx " host_test t9113-shield-rollout" end2end/host.sh+ grep -Fqx " host_test t9113-shield-rollout" end2end/host.sh &&+ grep -Fqx "host_test t9114-app-sandbox" end2end/host.sh'test_expect_success 'test-vm rejects unknown policy modes before boot' 'diff --git a/testing/run-target-tests.sh b/testing/run-target-tests.shindex ef1ac8a2..1475eae7 100755--- a/testing/run-target-tests.sh+++ b/testing/run-target-tests.sh@@ -72,12 +72,12 @@ for t in "$dir"/t[0-9]1[0-9][0-9]-*.sh; do[ -e "$t" ] || continuefound=1test_matches "$t" || continue- # end2end/host.sh runs t9109 to t9113 itself, on the host after node+ # end2end/host.sh runs t9109 to t9114 itself, on the host after node# A's suite, against fresh edge nodes and nodes B.case "$t" inend2end/t9109-pipeline.sh | end2end/t9110-keepalive-history.sh) continue ;;end2end/t9111-pipeline-segments.sh | end2end/t9112-activation.sh) continue ;;- end2end/t9113-shield-rollout.sh) continue ;;+ end2end/t9113-shield-rollout.sh | end2end/t9114-app-sandbox.sh) continue ;;end2end/t9107-keepalive-backend.sh)# host.sh records the example tree when it publishes it to# its backend and removes the record when it stops, so a run