eBPF-based security platform
Documentation/start: add quick guides for the use cases, with a backend
John Fastabend871666074069
diff --git a/Documentation/start/guides/backend.rst b/Documentation/start/guides/backend.rstnew file mode 100644index 00000000..27d37fc5--- /dev/null+++ b/Documentation/start/guides/backend.rst@@ -0,0 +1,215 @@+..+ SPDX-License-Identifier: BSD-2-Clause+ Copyright (c) 2026 Authors of shirudo++:page-type: Tutorial+:audience: Operators, upatch authors++Set up the backend+==================++In this tutorial you start what a target pulls from and reports to, on+your own host: an OCI registry, an OpenTelemetry Collector and the+example backend of :src:`tools/backend/`, a ClickHouse that checks every+keepalive a target sends. You enroll the test target in the backend and+read its status there. The use-case guides,+:doc:`live-patching`, :doc:`system-hardening` and+:doc:`runtime-observability`, start from the state this page leaves.++The test VM is configured for these services from its first boot. Its+signed config names ``oci://10.0.2.2:15444/shirudo/local-tree`` as the+upatch tree to follow and ``https://10.0.2.2:14319`` as the collector,+and its timers look for a tree operation and send a keepalive every 10+seconds, where a target's wait a minute. Until the services run, the+timers retry.++Before you begin+----------------++- A shell that may lock memory, which ``shirudo`` does as it starts:++ .. code-block:: console++ operator$ sudo prlimit --pid $$ --memlock=unlimited:unlimited++ ``ulimit -l`` then prints ``unlimited``. Under a lower limit+ ``shirudo`` stops with ``hardening: cannot lock process memory``, and+ ``make vm`` with ``cannot fingerprint the bundle's own certificate``+ or ``cannot read the version_id of the bundle's shirudo``. The limit+ belongs to the shell: set it in each terminal you run the commands of+ this guide in.+- A host that meets the requirements of the :doc:`/start/quickstart`,+ with the test kernel staged and shirudo built as its first three+ sections do: in the root of your checkout, with ``shirudo`` and+ ``shirudo-build`` on ``PATH``+- Docker on the operator host++Start the services and the target+---------------------------------++1. Start the registry, the collector, the backend and the test VM, and+ load the settings of the stack into your operator shell:++ .. code-block:: console++ operator$ make stack-up && make vm VM_NAME=quickstart+ operator$ . build/test-vm/stack/env++ The first line prints:++ .. code-block:: console++ ...+ OCI: oci://127.0.0.1:15444 (CA: /home/user/shirudo/build/test-vm/stack/ca.pem)+ OTLP: https://127.0.0.1:14319; ClickHouse with the backend: http://127.0.0.1:18124+ Shell: . /home/user/shirudo/build/test-vm/stack/env+ ...+ [test-vm] booting bzImage with 4 CPUs and 4G memory+ [test-vm] VM ready: name=quickstart state=.../build/test-vm/vms/quickstart qemu_pid=... swtpm_pid=...+ ...+ [test-vm] console: make -C testing vm-console VM_NAME=quickstart+ [test-vm] ssh: make -C testing vm-ssh++ ``make stack-up`` builds ``tools/quote-check/shirudo-quote-check``,+ the checker the backend verifies keepalives with, which+ :doc:`/reference/cli/quote-check` describes. It then runs three+ containers on the host's loopback interface: the registry, the+ collector and a ClickHouse with the schema of+ :src:`tools/backend/sql/` and the checker installed as its+ ``tpm_quote_check`` function. ``make vm`` boots the test VM of the+ quickstart, which reaches the services at ``10.0.2.2`` and trusts the+ CA the ``OCI:`` line names. A VM that the quickstart booted before works+ as well: run ``make stack-up`` alone. :ref:`local-dev-stack`+ describes each ``make`` target of this stack, and+ :doc:`/operate/backend/set-up` sets the backend up on a host of your+ own.++2. Open a root shell on the target, in which ``shirudo`` runs the+ runtime binary:++ .. code-block:: console++ operator$ make -C testing vm-ssh VM_NAME=quickstart++ Commands with the ``target#`` prompt run in this shell.++3. Look at the settings the ``Shell:`` line names, which your shell+ read in the first step:++ .. code-block:: console++ operator$ cat build/test-vm/stack/env+ export PATH='/home/user/shirudo:/home/user/shirudo/tools/shirudo-build':"$PATH"+ KEYS='/tmp/shirudo-test-vm-private-1000/operator-keys/keys'+ export BPM_OCI_CA_FILE='/home/user/shirudo/build/test-vm/stack/ca.pem'+ TREE=oci://127.0.0.1:15444/shirudo/local-tree+ export CLICKHOUSE_CLIENT='docker exec -i shirudo-dev-clickhouse clickhouse-client'++ ``make stack-up`` writes the file, as a ``make`` target cannot set a+ variable in the shell that ran it. It puts ``shirudo`` and+ ``shirudo-build`` of your checkout on ``PATH`` and names the key+ directory, the registry's CA and the tree for the commands of the+ guides. ``shirudo bpm`` reads ``BPM_OCI_CA_FILE`` to verify the+ registry, and the jobs of :src:`tools/backend/jobs/` run the+ ClickHouse client ``CLICKHOUSE_CLIENT`` names. A shell you open later+ has none of them until it reads the file too. The tree does not+ exist yet: the first operation you append creates it.++Enroll the target+-----------------++1. Load the names of the target's TPM keys into the backend:++ .. code-block:: console++ operator$ make vm-enroll VM_NAME=quickstart+ $ cat build/test-vm/vms/quickstart/enroll.json+ {"source": "test-vm", "nodes": [{"ak_name": "000b384a13035ce74a05397c2df1837c26832060a048f199cebf270b40c6d1a29b35", "ek_name": "000b2bcc6ad1b9d260ae30ffb0a3f75dd65bf20d0870c7346aeab39abd295ddda2d0", "node_id": "quickstart"}]}+ $ CLICKHOUSE_CLIENT='docker exec -i shirudo-dev-clickhouse clickhouse-client' tools/backend/jobs/enroll-put build/test-vm/vms/quickstart/enroll.json+ enroll-put: 000b384a13035ce74a05397c2df1837c26832060a048f199cebf270b40c6d1a29b35 (ek_name 000b2bcc6ad1b9d260ae30ffb0a3f75dd65bf20d0870c7346aeab39abd295ddda2d0, node_id quickstart): enrolled+ enroll-put: loaded bindings: 1+ $ CLICKHOUSE_CLIENT='docker exec -i shirudo-dev-clickhouse clickhouse-client' tools/put-shirudo-build --note 'test-vm build' 59400f7e494aaa7d25dd4e6205689571ceda217bb77d07ceba6708ed0a372441+ put-shirudo-build: 59400f7e494aaa7d25dd4e6205689571ceda217bb77d07ceba6708ed0a372441: allowed++ The backend trusts a keepalive only when the attestation key that+ signed its quote is enrolled. ``make vm`` recorded the names of the+ attestation and endorsement keys when it created the VM's TPM, as the+ builder of a real target does, and ``make vm-enroll`` loads that+ record with :doc:`/operate/backend/enroll-put`. It also tells the+ backend which build of shirudo to expect. Your names and build+ differ. :doc:`attest-target` enrolls a key from the target itself,+ through credential activation.++2. Read the target's status in the backend:++ .. code-block:: console++ operator$ docker exec -i shirudo-dev-clickhouse clickhouse-client --query "SYSTEM REFRESH VIEW shirudo.node_status_mv; SYSTEM WAIT VIEW shirudo.node_status_mv"+ operator$ docker exec -i shirudo-dev-clickhouse clickhouse-client --query "SELECT node_id, status, trust, loaded FROM shirudo.node_status FORMAT PrettyCompactMonoBlock"+ ┌─node_id────┬─status──┬─trust────┬─loaded─┐+ 1. │ quickstart │ healthy │ enrolled │ 0 │+ └────────────┴─────────┴──────────┴────────┘++ The backend works ``node_status`` out once a minute; the first command+ has it do so at once. The row comes from the keepalives the target+ sends: each is the target's status with a TPM quote over it, and+ ``enrolled`` says that the quote verified against the key you loaded.++3. Read the checks behind that status:++ .. code-block:: console++ operator$ docker exec -i shirudo-dev-clickhouse clickhouse-client --query "SELECT arrayJoin(log) FROM shirudo.node_status"+ 1 signed: pass, enrolled, 0 rejected in the last hour+ 2 fresh: pass, last record 2 s ago+ 3 reported: pass, verdict ok, cond 0x1555, flags 0, tamper +0, build 59400f7e+ 4 chain: no tree+ 5 head: no tree+ 6 set: no tree+ 7 peers: no tree++ Checks 4 to 7 compare what the target applied with the upatch tree,+ and the backend knows no tree yet. The guides append to the tree and+ read these lines again. :doc:`/operate/backend/status` describes each+ check.++Watch the target+----------------++1. Start :doc:`xtop </operate/backend/xtop>` in a second terminal:++ .. code-block:: console++ operator$ make xtop++ xtop is a terminal view of the same tables: the nodes with their+ status, the shields the backend knows as available and the ones each+ node runs. It needs ``bun`` on the host. Leave it running while you+ follow a guide.++Stop the services+-----------------++1. Remove the VM, and the containers with their data, when you are+ done with the guides:++ .. code-block:: console++ operator$ make vm-stop VM_NAME=quickstart+ operator$ make vm-clean VM_NAME=quickstart+ operator$ make stack-down++ Stopping the VM ends the target shell. The VM's disk and TPM state,+ the registry, the tree in it, the backend's tables and the CA are+ gone. A VM that is left running trusts the removed CA, so a stack+ you start later needs a fresh one.++Next steps+----------++- :doc:`live-patching` blocks a kernel vulnerability and guards a JVM+ with upatches the target pulls from the tree.+- :doc:`system-hardening` puts an application in a sandbox.+- :doc:`runtime-observability` collects what runs, connects and reads+ on the target.+- :doc:`/operate/backend/index` explains the backend and its tables.diff --git a/Documentation/start/guides/example-workflows.rst b/Documentation/start/guides/example-workflows.rstnew file mode 100644index 00000000..6e15d991--- /dev/null+++ b/Documentation/start/guides/example-workflows.rst@@ -0,0 +1,21 @@+..+ SPDX-License-Identifier: BSD-2-Clause+ Copyright (c) 2026 Authors of shirudo++Example workflows+=================++Each of these tutorials takes one use case through the whole pipeline on+the test VM, with the services of :doc:`backend`: it publishes a+package, appends it to the upatch tree the target follows, shows its+effect on the target and in the backend, and takes it back. The packages+are the ones under :src:`upatches/`: shields that block a kernel and a+JDK vulnerability, a sandbox around a web server, and observability of+what the target runs.++.. toctree::+ :titlesonly:++ live-patching+ system-hardening+ runtime-observabilitydiff --git a/Documentation/start/guides/index.rst b/Documentation/start/guides/index.rstindex 7662c90d..1f741066 100644--- a/Documentation/start/guides/index.rst+++ b/Documentation/start/guides/index.rst@@ -10,9 +10,16 @@ test VM. Each takes one task from start to finish: writing a upatch ofyour own, shipping one as a package through an OCI registry, andenrolling the target's TPM to verify what the target runs.+The backend guide then starts a registry, a collector and the example+backend on your host, and the :doc:`example workflows+<example-workflows>` take a use case each through the whole pipeline+with them: live patching, system hardening and runtime observability.+.. toctree:::titlesonly:first-upatchpublish-packageattest-target+ backend+ example-workflowsdiff --git a/Documentation/start/guides/live-patching.rst b/Documentation/start/guides/live-patching.rstnew file mode 100644index 00000000..6837f819--- /dev/null+++ b/Documentation/start/guides/live-patching.rst@@ -0,0 +1,346 @@+..+ SPDX-License-Identifier: BSD-2-Clause+ Copyright (c) 2026 Authors of shirudo++:page-type: Tutorial+:audience: Operators, upatch authors++Live patch a kernel and a JVM+=============================++In this tutorial we walk through the end-to-end workflow to close two+vulnerabilities on a running target without a reboot and without a+restart of the kernel or the JDK. For example purposes we picked two+vulnerabilities that were both well documented and fixes have been+published and available for some time. First for a kernel based example+we pick Copy Fail (CVE-2026-31431) a vulnerability in the kernel's ``AF_ALG``+sockets. A BPF upatch will block and record when processes try to open+potentially exploitable socket types. The second is java2shell (CVE-2026-114938)+an exploit in the Base64 decoder of the JDK, which a Java agent guards.+To protect against this vulnerability we sanitize input arguments which+should only block inputs that match the input structure described in the+bug fix.++We publish both as packages, append them to the upatch tree the target+follows, and watch the target pull them. We then pop the upatch off the+tree which is the final stage used once the kernel and JVM source updates+have been rolled out.++Both examples are shipped in the source code and tested as part of the+end-to-end CI and can be found in :src:`upatches/`. We call these upatch+fixes "shields".++Before you begin+----------------++- A shell that may lock memory, which ``shirudo`` does as it starts:++ .. code-block:: console++ operator$ sudo prlimit --pid $$ --memlock=unlimited:unlimited++ ``ulimit -l`` then prints ``unlimited``. Under a lower limit+ ``shirudo`` stops with ``hardening: cannot lock process memory``, and+ ``make vm`` with ``cannot fingerprint the bundle's own certificate``+ or ``cannot read the version_id of the bundle's shirudo``. The limit+ belongs to the shell: set it in each terminal you run the commands of+ this guide in.+- The local stack and the test VM, started from the root of your+ checkout, the settings of the stack in your operator shell and the+ target enrolled in the backend:++ .. code-block:: console++ operator$ make stack-up && make vm VM_NAME=quickstart+ operator$ . build/test-vm/stack/env+ operator$ make vm-enroll VM_NAME=quickstart++ :doc:`backend` explains these lines. A shell you open later needs the+ second line again.++- ``jq`` on the operator host+- A root shell on the target, in which ``shirudo`` runs the runtime+ binary:++ .. code-block:: console++ operator$ make vm-ssh VM_NAME=quickstart++- An x86-64 host, for the second part: the Base64 flaw is in the+ decoder's AVX-512 code, and the package selects that architecture+- A JDK of release 24 or later on the operator host, for ``javac`` and+ ``jar``++Reproduce both flaws+--------------------++1. Run the probe for CVE-2026-31431 on the target:++ .. code-block:: console++ target# python3 /workspace/shirudo/upatches/kernel-cve/sources/cve-2026-31431-crypto-algif-aead-copy-fail/reproducer/cve-2026-31431-splice-probe.py+ SPLICE_OK++ The probe splices a page of a file into an ``AF_ALG`` socket without a+ copy, the step the exploit of the CVE builds on. ``SPLICE_OK`` says+ the kernel took it. The target mounts your checkout read-only at+ ``/workspace/shirudo``.++2. Build a program that feeds the Base64 decoder the crafted input:++ .. code-block:: console++ operator$ upatches/test/build.sh++ It writes ``upatches/test/badDecoder.jar`` from+ :src:`upatches/test/BadDecoder.java`.++3. Run it on the target in a JVM that a user manager starts:++ .. code-block:: console++ target# sh /workspace/shirudo/testing/end2end/guarded-jvm.sh /workspace/shirudo/upatches/test/badDecoder.jar+ badDecoder: no guard, the JDK refused: Last unit does not have enough valid bits+ status 1++ The input reaches the decoder of the JDK. This JDK is not vulnerable+ and refuses the input itself; a vulnerable one writes past the+ destination array. :src:`testing/end2end/guarded-jvm.sh` creates a+ user, starts a user manager for it and runs the jar in a service of+ that manager, which is how a JVM comes to load the Java agents of a+ target: :doc:`/upatches/write/java-agents` explains why.++Publish the shields+-------------------++1. Build both packages and push them to one namespace of the registry:++ .. code-block:: console++ operator$ mkdir -p build/tutorial+ operator$ tools/put-shields --version 1.0.0 --keys-dir "$KEYS" --catalog build/tutorial/shields.json --new-index oci://127.0.0.1:15444/live-patching upatches/kernel-cve/cve-2026-31431-alg-splice-block.bee upatches/java-base64+ wrote /tmp/shirudo-bpm-build.qTghwI/0.upatch (insns=992 sig=4853 data=39256 sections=2 maps=0 progs=1 decoders=0 name=cve-2026-31431-alg-splice-block)+ wrote /tmp/shirudo-bpm-build.qTghwI/0.unload.upatch (insns=1320 sig=4853 data=2832 sections=2 maps=1 progs=1 decoders=0 name=cve-2026-31431-alg-splice-block UNLOAD)+ put-shields: pushed oci://127.0.0.1:15444/live-patching/cve-2026-31431-alg-splice-block:1.0.0 sha256:907fd7f79f14e3d2d869ba5d7bb140cd16dee131ec3b3b1d68aca686a049994f+ shirudo bpm tree append oci://127.0.0.1:15444/live-patching/cve-2026-31431-alg-splice-block:1.0.0 --package-digest sha256:907fd7f79f14e3d2d869ba5d7bb140cd16dee131ec3b3b1d68aca686a049994f oci://<registry>/<tree> --tree-id <tree-id>+ wrote /tmp/shirudo-bpm-build.oQlqSq/0.upatch (java sig=4853 data=7904 name=java-base64)+ wrote /tmp/shirudo-bpm-build.oQlqSq/0.unload.upatch (java sig=4853 data=360 name=java-base64 UNLOAD)+ put-shields: pushed oci://127.0.0.1:15444/live-patching/java-base64:1.0.0 sha256:d37ad3d8a345f3a1e5e19a9d85ebe66e076b9a0540f8f17952d3709030aebbb4+ shirudo bpm tree append oci://127.0.0.1:15444/live-patching/java-base64:1.0.0 --package-digest sha256:d37ad3d8a345f3a1e5e19a9d85ebe66e076b9a0540f8f17952d3709030aebbb4 oci://<registry>/<tree> --tree-id <tree-id>++ :src:`tools/put-shields` runs ``shirudo bpm build`` and ``shirudo bpm+ push`` for each package, which sign the upatches and the namespace's+ index with the key in ``KEYS``. For each package it prints the+ ``shirudo bpm tree append`` command that takes it into a tree, by its+ reference and the digest of its manifest. Your digests differ.++2. Keep the two digests for the commands below:++ .. code-block:: console++ operator$ CVE_DIGEST=$(jq -r 'first(.shields[] | select(.package == "cve-2026-31431-alg-splice-block")).manifest_digest' build/tutorial/shields.json)+ operator$ JAVA_DIGEST=$(jq -r 'first(.shields[] | select(.package == "java-base64")).manifest_digest' build/tutorial/shields.json)++ The catalog ``put-shields`` wrote holds, for each package, the+ ``sha256:`` value its command printed after ``--package-digest``.++3. Tell the backend that the shields are available:++ .. code-block:: console++ operator$ tools/backend/jobs/shields-put build/tutorial/shields.json+ shields-put: oci://127.0.0.1:15444/live-patching/cve-2026-31431-alg-splice-block:1.0.0 cve-2026-31431-alg-splice-block (CVE-2026-31431)+ shields-put: oci://127.0.0.1:15444/live-patching/java-base64:1.0.0 java-base64 (CVE-2026-114938)+ shields-put: loaded shields: 2++ ``--catalog`` had ``put-shields`` write what it pushed, with the+ advisories each shield mitigates, and+ :doc:`/operate/backend/shields-put` loads that file. xtop lists the+ two in its shields view. Nothing runs on the target yet: a published+ package reaches a target only through the tree.++Block the kernel flaw+---------------------++1. Append the kernel shield to the tree:++ .. code-block:: console++ operator$ shirudo bpm tree append oci://127.0.0.1:15444/live-patching/cve-2026-31431-alg-splice-block:1.0.0 --package-digest "$CVE_DIGEST" "$TREE" --tree-id local-tree --keys-dir "$KEYS"+ oci://127.0.0.1:15444/shirudo/local-tree:stable sha256:b13473fa4bdff594dd39f948e5d19fc4276fd3363ace67ab80b5ba0849efbebe++ The tree is a signed list of operations. This one says ``add`` with+ the upatch's payload digest and its selector, which reads the kernel+ configuration: only a target built with+ ``CONFIG_CRYPTO_USER_API_AEAD`` loads it.++2. Wait for the target's next sync, at most 10 seconds on the test VM,+ and list its upatches:++ .. code-block:: console++ target# shirudo upatch list+ Archived upatches (/var/lib/shirudo/upatches):+ NAME LOADED TYPE KIND PAYLOAD+ cve-2026-31431-alg-splice-block yes load bpf 42dc3be289a0f3d7..++ ``shirudo-bpm-tree-sync.timer`` ran ``shirudo bpm tree sync``, which+ fetched the tree, verified its signature against the sealed keyring,+ pulled the package and loaded the upatch through the signed loader,+ with the load extended into the TPM register. You ran nothing on the+ target.++3. Run the probe again:++ .. code-block:: console++ target# python3 /workspace/shirudo/upatches/kernel-cve/sources/cve-2026-31431-crypto-algif-aead-copy-fail/reproducer/cve-2026-31431-splice-probe.py+ SPLICE_BLOCKED++ The upatch refuses the splice in an LSM hook, and every other use of+ the socket goes on as before. The kernel is the one that booted.++4. Load the tree into the backend and read the target's checks:++ .. code-block:: console++ operator$ tools/backend/jobs/tree-ingest --shirudo "$PWD/shirudo" --cert "$KEYS/cert.der" "$TREE"+ tree-ingest: loaded local-tree generation 1 (operations: 1, fixes: 1)+ operator$ docker exec -i shirudo-dev-clickhouse clickhouse-client --query "SYSTEM REFRESH VIEW shirudo.node_status_mv; SYSTEM WAIT VIEW shirudo.node_status_mv"+ operator$ docker exec -i shirudo-dev-clickhouse clickhouse-client --query "SELECT arrayJoin(log) FROM shirudo.node_status"+ 1 signed: pass, enrolled, 0 rejected in the last hour+ 2 fresh: pass, last record 1 s ago+ 3 reported: FAIL, verdict ok, cond 0x1555, flags 0, tamper +22, build 59400f7e+ 4 chain: pass, root 4de4d83c+ 5 head: pass, seq 1 of 1, generation 1+ 6 set: pass, 1 loaded+ 7 peers: no peers, 1 in group++ :doc:`/operate/backend/tree-ingest` reads the tree as a target does.+ Checks 4 to 6 then hold the target's keepalive against it: the target+ is at operation 1 of 1 and runs the one upatch that operation leaves+ loaded. Check 3 fails here because the target's tamper counters rose+ after its first record; :doc:`/operate/backend/status` says how each+ check reads a record.++Guard the JVM+-------------++1. Append the Java shield:++ .. code-block:: console++ operator$ shirudo bpm tree append oci://127.0.0.1:15444/live-patching/java-base64:1.0.0 --package-digest "$JAVA_DIGEST" "$TREE" --tree-id local-tree --keys-dir "$KEYS"+ oci://127.0.0.1:15444/shirudo/local-tree:stable sha256:02c6eb7391955e4c95e12883400f8def7c96f5fd79c5e2334c6704c5aafef566++2. After the next sync, list the target's upatches:++ .. code-block:: console++ target# shirudo upatch list+ Archived upatches (/var/lib/shirudo/upatches):+ NAME LOADED TYPE KIND PAYLOAD+ cve-2026-31431-alg-splice-block yes load bpf 42dc3be289a0f3d7..+ java-base64 yes load java fea9e483dd384ec7..++ A Java upatch is a signed agent jar. The target verified it as it+ verifies a BPF upatch, sealed the jar and named it in+ ``JAVA_TOOL_OPTIONS`` for the JVMs that start from here on.++3. Run the crafted input again:++ .. code-block:: console++ target# sh /workspace/shirudo/testing/end2end/guarded-jvm.sh /workspace/shirudo/upatches/test/badDecoder.jar+ Picked up JAVA_TOOL_OPTIONS: -javaagent:/run/shirudo-java/java-base64.jar+ OpenJDK 64-Bit Server VM warning: Sharing is only supported for boot loader classes because bootstrap classpath has been appended+ Base64 guard installed on java.util.Base64$Decoder.decode0+ Base64 guard rejected candidate: length=66, padding=1, remainder=2, alphabet=standard+ badDecoder: refused by the guard+ status 0++ The agent refuses the input before the decoder of the JDK sees it. The+ JDK and the application's jar are unchanged.++Take the shields back+---------------------++1. Append a delete for each shield:++ .. code-block:: console++ operator$ shirudo bpm tree append oci://127.0.0.1:15444/live-patching/java-base64:1.0.0 --package-digest "$JAVA_DIGEST" "$TREE" --tree-id local-tree --keys-dir "$KEYS" --op delete+ oci://127.0.0.1:15444/shirudo/local-tree:stable sha256:21a2aaa16532bb25d310014ec3c32d0cf282b7ead233bb0df911cf05d4942a65+ operator$ shirudo bpm tree append oci://127.0.0.1:15444/live-patching/cve-2026-31431-alg-splice-block:1.0.0 --package-digest "$CVE_DIGEST" "$TREE" --tree-id local-tree --keys-dir "$KEYS" --op delete+ oci://127.0.0.1:15444/shirudo/local-tree:stable sha256:4817283178193d0ef0c858b701db7e585efbcad153abee015caba0efc67c6f19++ The tree only grows: a delete is one more signed operation, and the+ adds stay on record before it.++2. After the next sync, check that the target unloaded both:++ .. code-block:: console++ target# shirudo upatch list+ Archived upatches (/var/lib/shirudo/upatches):+ none+ target# sh /workspace/shirudo/testing/end2end/guarded-jvm.sh /workspace/shirudo/upatches/test/badDecoder.jar+ badDecoder: no guard, the JDK refused: Last unit does not have enough valid bits+ status 1+ target# python3 /workspace/shirudo/upatches/kernel-cve/sources/cve-2026-31431-crypto-algif-aead-copy-fail/reproducer/cve-2026-31431-splice-probe.py+ SPLICE_OK++ Each unload ran the signed unload directive of its package and is in+ the TPM register like the load.++3. Load the tree into the backend again and read the checks:++ .. code-block:: console++ operator$ tools/backend/jobs/tree-ingest --shirudo "$PWD/shirudo" --cert "$KEYS/cert.der" "$TREE"+ tree-ingest: loaded local-tree generation 4 (operations: 4, fixes: 2)+ operator$ docker exec -i shirudo-dev-clickhouse clickhouse-client --query "SYSTEM REFRESH VIEW shirudo.node_status_mv; SYSTEM WAIT VIEW shirudo.node_status_mv"+ operator$ docker exec -i shirudo-dev-clickhouse clickhouse-client --query "SELECT arrayJoin(log) FROM shirudo.node_status"+ 1 signed: pass, enrolled, 0 rejected in the last hour+ 2 fresh: pass, last record 10 s ago+ 3 reported: FAIL, verdict ok, cond 0x1555, flags 0, tamper +50, build 59400f7e+ 4 chain: pass, root 75c9c1c3+ 5 head: pass, seq 4 of 4, generation 4+ 6 set: pass, 0 loaded+ 7 peers: no peers, 1 in group++ The target is at operation 4 of 4 with nothing loaded, which is what+ two adds and two deletes leave.++Tear down+---------++The guides share the stack, the VM and the tree: skip this section to+go on to another one.++1. Remove the VM, the stack and the files of this guide:++ .. code-block:: console++ operator$ make vm-stop VM_NAME=quickstart+ operator$ make vm-clean VM_NAME=quickstart+ operator$ make stack-down+ operator$ rm build/tutorial/shields.json++ Stopping the VM ends the target shell. The VM's disk and TPM state,+ the registry with the tree in it, the backend's tables and the CA+ are gone. The first lines of this guide start again from nothing.++Next steps+----------++- :doc:`/upatches/learn/kernel-fix-tutorial` writes a upatch for a+ kernel CVE, from the fix to the published package.+- :doc:`/upatches/write/java-agents` explains Java upatches and which+ JVMs load them.+- :doc:`/upatches/publish/publishing` describes the tree, its selectors+ and its segments.+- :doc:`/operate/backend/exposure` shows which nodes run a vulnerable+ package or kernel and which shield covers them.+- :doc:`system-hardening` and :doc:`runtime-observability` use the same+ tree for a sandbox and for observability.diff --git a/Documentation/start/guides/runtime-observability.rst b/Documentation/start/guides/runtime-observability.rstnew file mode 100644index 00000000..784fb248--- /dev/null+++ b/Documentation/start/guides/runtime-observability.rst@@ -0,0 +1,318 @@+..+ SPDX-License-Identifier: BSD-2-Clause+ Copyright (c) 2026 Authors of shirudo++:page-type: Tutorial+:audience: Operators, upatch authors++Observe a target at runtime+===========================++In this tutorial you collect what happens on a running target: which+programs it executes, where it connects, which names it resolves and who+reads its credential files. The ``kernel-obs`` upatch of+:src:`upatches/kernel-obs/` records these in tables inside the kernel,+the target exports the tables over OpenTelemetry every few seconds, and+you query the records in the collector's ClickHouse. Nothing on the+target listens, and no agent runs between exports.++Every hook of ``kernel-obs`` observes. It refuses nothing, so loading it+changes no behavior of the target.++Before you begin+----------------++- A shell that may lock memory, which ``shirudo`` does as it starts:++ .. code-block:: console++ operator$ sudo prlimit --pid $$ --memlock=unlimited:unlimited++ ``ulimit -l`` then prints ``unlimited``. Under a lower limit+ ``shirudo`` stops with ``hardening: cannot lock process memory``, and+ ``make vm`` with ``cannot fingerprint the bundle's own certificate``+ or ``cannot read the version_id of the bundle's shirudo``. The limit+ belongs to the shell: set it in each terminal you run the commands of+ this guide in.+- The local stack and the test VM, started from the root of your+ checkout, the settings of the stack in your operator shell and the+ target enrolled in the backend:++ .. code-block:: console++ operator$ make stack-up && make vm VM_NAME=quickstart+ operator$ . build/test-vm/stack/env+ operator$ make vm-enroll VM_NAME=quickstart++ :doc:`backend` explains these lines. A shell you open later needs the+ second line again.++- ``jq`` on the operator host+- A root shell on the target, in which ``shirudo`` runs the runtime+ binary:++ .. code-block:: console++ operator$ make vm-ssh VM_NAME=quickstart++Publish and deliver kernel-obs+------------------------------++1. Build the package and push it to a namespace of the registry:++ .. code-block:: console++ operator$ mkdir -p build/tutorial+ operator$ tools/put-shields --version 1.0.0 --keys-dir "$KEYS" --catalog build/tutorial/observability.json --new-index oci://127.0.0.1:15444/observability upatches/kernel-obs+ wrote /tmp/shirudo-bpm-build.H0hmLw/0.upatch (insns=40024 sig=4853 data=842568 sections=3 maps=19 progs=35 decoders=9 name=kernel-obs)+ wrote /tmp/shirudo-bpm-build.H0hmLw/0.unload.upatch (insns=1320 sig=4853 data=2832 sections=2 maps=1 progs=1 decoders=0 name=kernel-obs UNLOAD)+ wrote /tmp/shirudo-bpm-build.H0hmLw/1.upatch (insns=1184 sig=4853 data=3208 sections=2 maps=1 progs=1 decoders=0 name=userns-unshare-counter)+ wrote /tmp/shirudo-bpm-build.H0hmLw/1.unload.upatch (insns=1320 sig=4853 data=2832 sections=2 maps=1 progs=1 decoders=0 name=userns-unshare-counter UNLOAD)+ put-shields: pushed oci://127.0.0.1:15444/observability/kernel-obs:1.0.0 sha256:88f955c13ee9c768141f8035c7ebefc7676931ce0dd81fb06bba1d40941a35fb+ shirudo bpm tree append oci://127.0.0.1:15444/observability/kernel-obs:1.0.0 --package-digest sha256:88f955c13ee9c768141f8035c7ebefc7676931ce0dd81fb06bba1d40941a35fb oci://<registry>/<tree> --tree-id <tree-id>++ :src:`tools/put-shields` runs ``shirudo bpm build`` and ``shirudo bpm+ push`` for the package of :src:`upatches/kernel-obs/`, which sign its+ upatches and the namespace's index with the key in ``KEYS``. The+ ``kernel-obs`` upatch holds 35 BPF programs and 9 decoders. A decoder+ is a signed Lua script that turns the bytes of one table into the+ records the target exports, so the meaning of a table ships with the+ upatch that fills it. The last line is the command that appends the+ package to a tree, by its reference and the digest of its manifest.+ Your digest differs.++2. Keep the digest and tell the backend that the package is available:++ .. code-block:: console++ operator$ OBS_DIGEST=$(jq -r '.shields[0].manifest_digest' build/tutorial/observability.json)+ operator$ tools/backend/jobs/shields-put build/tutorial/observability.json+ shields-put: oci://127.0.0.1:15444/observability/kernel-obs:1.0.0 kernel-obs (no advisory)+ shields-put: loaded shields: 1++ The catalog ``put-shields`` wrote holds the ``sha256:`` value its+ command printed after ``--package-digest``.++3. Append the package to the tree:++ .. code-block:: console++ operator$ shirudo bpm tree append oci://127.0.0.1:15444/observability/kernel-obs:1.0.0 --package-digest "$OBS_DIGEST" "$TREE" --tree-id local-tree --keys-dir "$KEYS"+ oci://127.0.0.1:15444/shirudo/local-tree:stable sha256:50a07b7010b81cee2cadc0ad6fbc4becb78ebd2c4393fe8890b3cd90c1fa3b90++ The tree is a signed list of operations. A tree takes the upatches of+ a package that have an ``[upatches.tree]`` table in the ``Beefile``:+ here ``kernel-obs``, without a selector, so that every target that+ follows the tree loads it. ``userns-unshare-counter``, the second+ upatch of the package, has no such table and stays out.++4. Wait for the target's next sync, at most 10 seconds on the test VM,+ and list its upatches and their maps:++ .. code-block:: console++ target# shirudo upatch list+ Archived upatches (/var/lib/shirudo/upatches):+ NAME LOADED TYPE KIND PAYLOAD+ kernel-obs yes load bpf c96d3d59730d5aa1..+ target# shirudo upatch map kernel-obs+ Pinned maps (9):+ UPATCH MAP TYPE ENTRIES+ kernel-obs watch_stat percpu_array max=1 (per-cpu)+ kernel-obs file array max=1+ kernel-obs priv array max=1+ kernel-obs dns array max=1+ kernel-obs watch array max=1+ kernel-obs listen array max=1+ kernel-obs socket array max=1+ kernel-obs net array max=1+ kernel-obs exec array max=1++ Each map but ``watch_stat`` stands for one table in the upatch's BPF+ arena. ``shirudo-map-export.timer`` runs ``shirudo upatch map --all``+ every 5 seconds, which drains every table through its serializer and+ decoder and sends the records to the collector.++5. Load the tree into the backend and read the target's checks:++ .. code-block:: console++ operator$ tools/backend/jobs/tree-ingest --shirudo "$PWD/shirudo" --cert "$KEYS/cert.der" "$TREE"+ tree-ingest: loaded local-tree generation 1 (operations: 1, fixes: 0)+ operator$ docker exec -i shirudo-dev-clickhouse clickhouse-client --query "SYSTEM REFRESH VIEW shirudo.node_status_mv; SYSTEM WAIT VIEW shirudo.node_status_mv"+ operator$ docker exec -i shirudo-dev-clickhouse clickhouse-client --query "SELECT arrayJoin(log) FROM shirudo.node_status"+ 1 signed: pass, enrolled, 0 rejected in the last hour+ 2 fresh: pass, last record 10 s ago+ 3 reported: FAIL, verdict ok, cond 0x1555, flags 0, tamper +8, build 59400f7e+ 4 chain: pass, root a2e481e0+ 5 head: pass, seq 1 of 1, generation 1+ 6 set: pass, 1 loaded+ 7 peers: no peers, 1 in group++ Checks 4 to 6 say that the target is at the head of the tree and runs+ the one upatch it leaves loaded. Check 3 fails here because the+ target's tamper counters rose after its first record;+ :doc:`/operate/backend/status` says how each check reads a record.++Cause events and read their records+-----------------------------------++1. Resolve a name, open a TCP connection and read a credential file on+ the target:++ .. code-block:: console++ target# getent hosts example.com+ 2606:4700:10::ac42:93f3 example.com+ 2606:4700:10::6814:179a example.com+ target# curl --silent --output /dev/null http://10.0.2.2:18124/ping+ target# head -c 1 /etc/shadow >/dev/null++2. Wait for the next export and count what the collector holds for each+ table:++ .. code-block:: console++ operator$ docker exec -i shirudo-dev-clickhouse clickhouse-client --query "SELECT LogAttributes['shirudo.map.name'] AS map, count() AS snapshots, sum(length(JSONExtractArrayRaw(Body, 'records'))) AS records FROM shirudo.otel_logs WHERE EventName = 'shirudo.bpf.map.snapshot' GROUP BY map ORDER BY map FORMAT PrettyCompactMonoBlock"+ ┌─map────┬─snapshots─┬─records─┐+ 1. │ dns │ 6 │ 12 │+ 2. │ exec │ 6 │ 438 │+ 3. │ file │ 6 │ 19 │+ 4. │ listen │ 6 │ 0 │+ 5. │ net │ 6 │ 45 │+ 6. │ priv │ 6 │ 262 │+ 7. │ socket │ 6 │ 1098 │+ 8. │ watch │ 6 │ 0 │+ └────────┴───────────┴─────────┘++ Each export of a table is one OpenTelemetry log record, a snapshot,+ whose body is a JSON document with the records of that interval. Most+ of them come from the target's own services and from your shell+ session. Your counts differ.++3. Find the programs you ran:++ .. code-block:: console++ operator$ docker exec -i shirudo-dev-clickhouse clickhouse-client --query "SELECT JSONExtractString(r, 'path') AS path, JSONExtractUInt(r, 'uid') AS uid, JSONExtractUInt(r, 'pid') AS pid FROM shirudo.otel_logs ARRAY JOIN JSONExtractArrayRaw(Body, 'records') AS r WHERE LogAttributes['shirudo.map.name'] = 'exec' AND match(path, '/(getent|curl|head)\$') ORDER BY pid FORMAT PrettyCompactMonoBlock"+ ┌─path──────────────────────────────┬─uid─┬──pid─┐+ 1. │ /usr/bin/getent │ 0 │ 3304 │+ 2. │ /usr/bin/curl │ 0 │ 3305 │+ 3. │ /usr/lib/cargo/bin/coreutils/head │ 0 │ 3306 │+ └───────────────────────────────────┴─────┴──────┘++ The ``exec`` table has a record for each program a task executed,+ with its path, its user and the program that called it. The path is+ that of the file the kernel ran: ``/usr/bin/head`` is a symbolic link+ on the test VM, and the record names what it points to.++4. Find the connection ``curl`` opened:++ .. code-block:: console++ operator$ docker exec -i shirudo-dev-clickhouse clickhouse-client --query "SELECT JSONExtractString(r, 'address') AS address, JSONExtractUInt(r, 'port') AS port, JSONExtractString(r, 'proto') AS proto, JSONExtractString(r, 'role') AS role FROM shirudo.otel_logs ARRAY JOIN JSONExtractArrayRaw(Body, 'records') AS r WHERE LogAttributes['shirudo.map.name'] = 'net' AND port = 18124 FORMAT PrettyCompactMonoBlock"+ ┌─address──┬──port─┬─proto─┬─role──────┐+ 1. │ 10.0.2.2 │ 18124 │ tcp │ initiator │+ └──────────┴───────┴───────┴───────────┘++ The ``net`` table has one record per peer, with the bytes and packets+ each way and the executable that owns the socket.++5. Find the name you resolved:++ .. code-block:: console++ operator$ docker exec -i shirudo-dev-clickhouse clickhouse-client --query "SELECT DISTINCT JSONExtractString(r, 'names', 1, 'name') AS name, JSONExtractString(r, 'address') AS address FROM shirudo.otel_logs ARRAY JOIN JSONExtractArrayRaw(Body, 'records') AS r WHERE LogAttributes['shirudo.map.name'] = 'dns' AND name = 'example.com' FORMAT PrettyCompactMonoBlock"+ ┌─name────────┬─address─────────────────────────────────┐+ 1. │ example.com │ 2606:4700:0010:0000:0000:0000:ac42:93f3 │+ 2. │ example.com │ 2606:4700:0010:0000:0000:0000:6814:179a │+ └─────────────┴─────────────────────────────────────────┘++ The ``dns`` table keeps the addresses of DNS answers with the names+ that resolved to them, so that a connection to an address can be read+ as a connection to a name.++6. Find the read of the credential file:++ .. code-block:: console++ operator$ docker exec -i shirudo-dev-clickhouse clickhouse-client --query "SELECT JSONExtractString(r, 'path') AS path, JSONExtractString(r, 'mode') AS mode, JSONExtractUInt(r, 'pid') AS pid FROM shirudo.otel_logs ARRAY JOIN JSONExtractArrayRaw(Body, 'records') AS r WHERE LogAttributes['shirudo.map.name'] = 'file' AND path = '/etc/shadow' ORDER BY Timestamp DESC, pid DESC LIMIT 1 FORMAT PrettyCompactMonoBlock"+ ┌─path────────┬─mode─┬──pid─┐+ 1. │ /etc/shadow │ r │ 3306 │+ └─────────────┴──────┴──────┘++ The ``file`` table records opens of the credential and persistence+ files that :src:`upatches/kernel-obs/file-watch.list` names. The+ process is the ``head`` of the step before.++7. Read the counter the upatch exports as a metric:++ .. code-block:: console++ operator$ docker exec -i shirudo-dev-clickhouse clickhouse-client --query "SELECT MetricName, Attributes['outcome'] AS outcome, max(Value) AS value FROM shirudo.otel_metrics_sum GROUP BY MetricName, outcome ORDER BY outcome FORMAT PrettyCompactMonoBlock"+ ┌─MetricName────────────────┬─outcome─┬─value─┐+ 1. │ kernel_obs.watch_attempts │ checked │ 100 │+ 2. │ kernel_obs.watch_attempts │ matched │ 0 │+ └───────────────────────────┴─────────┴───────┘++ ``watch_stat`` counts the connections checked against the watched+ destinations of :src:`upatches/kernel-obs/watch.list`. Its decoder+ exports it as an OpenTelemetry sum, where the tables go out as log+ records.++Stop observing+--------------++1. Append a delete for the package:++ .. code-block:: console++ operator$ shirudo bpm tree append oci://127.0.0.1:15444/observability/kernel-obs:1.0.0 --package-digest "$OBS_DIGEST" "$TREE" --tree-id local-tree --keys-dir "$KEYS" --op delete+ oci://127.0.0.1:15444/shirudo/local-tree:stable sha256:db6416ab39111b60d222c51ccd4416bfde1ed0908edfc7516e25f7a01ee32cce++2. After the next sync, check that the upatch and its maps are gone:++ .. code-block:: console++ target# shirudo upatch list+ Archived upatches (/var/lib/shirudo/upatches):+ none+ target# shirudo upatch map+ Pinned maps (0):+ none++ The records already exported stay in the collector's tables.++Tear down+---------++The guides share the stack, the VM and the tree: skip this section to+go on to another one.++1. Remove the VM, the stack and the files of this guide:++ .. code-block:: console++ operator$ make vm-stop VM_NAME=quickstart+ operator$ make vm-clean VM_NAME=quickstart+ operator$ make stack-down+ operator$ rm build/tutorial/observability.json++ Stopping the VM ends the target shell. The VM's disk and TPM state,+ the registry with the tree in it, the backend's tables and the CA+ are gone. The first lines of this guide start again from nothing.++Next steps+----------++- :doc:`/upatches/learn/examples` describes every table of+ ``kernel-obs`` and its records.+- :doc:`/operate/run/telemetry` sets the collector, its TLS and the+ export interval on a real target, and says what to alert on.+- :doc:`/operate/integrations/index` has collector recipes for+ ClickHouse, Elasticsearch, Grafana and Splunk.+- :doc:`/upatches/write/maps-arenas-serializers` and+ :doc:`/upatches/write/decoders` explain how a upatch of your own+ exports its state.+- :doc:`live-patching` and :doc:`system-hardening` use the same tree+ for shields and for a sandbox.diff --git a/Documentation/start/guides/system-hardening.rst b/Documentation/start/guides/system-hardening.rstnew file mode 100644index 00000000..213b1428--- /dev/null+++ b/Documentation/start/guides/system-hardening.rst@@ -0,0 +1,309 @@+..+ SPDX-License-Identifier: BSD-2-Clause+ Copyright (c) 2026 Authors of shirudo++:page-type: Tutorial+:audience: Operators, upatch authors++Sandbox Vulnerable Apache+=========================++In this tutorial we put Apache in an application sandbox to reduce lateral+movement and privilege escalations inside the network and host if the+php2shell or other vulnerabilities were leveraged to gain control of the+process. To sandbox the application the example scopes two+operations: first executes only the programs listed in the policy, second+connects only to the networks specified in the policy. This is the example+case the policy engine can also be further leveraged to scope privileged+operations, such as user namespaces, mounts, and file access. We then+simulate an attacker attempting to upload a php script and connect to a+remote server, in this case 1.1.1.1:80.++The sandbox is the ``app-sandbox`` upatch of :src:`upatches/app-sandbox/`,+built with rules you write, published as a package and delivered through the+upatch tree. The application is not changed, restarted with other options or+wrapped: the rules apply to every task that executes its file.++The package ships example rules for Apache httpd and PHP-FPM that are used+in this example workflow. The policy can be further scoped or relaxed as+needed in individual environments.++Before you begin+----------------++- A shell that may lock memory, which ``shirudo`` does as it starts:++ .. code-block:: console++ operator$ sudo prlimit --pid $$ --memlock=unlimited:unlimited++ ``ulimit -l`` then prints ``unlimited``. Under a lower limit+ ``shirudo`` stops with ``hardening: cannot lock process memory``, and+ ``make vm`` with ``cannot fingerprint the bundle's own certificate``+ or ``cannot read the version_id of the bundle's shirudo``. The limit+ belongs to the shell: set it in each terminal you run the commands of+ this guide in.+- The local stack and the test VM, started from the root of your+ checkout, the settings of the stack in your operator shell and the+ target enrolled in the backend:++ .. code-block:: console++ operator$ make stack-up && make vm VM_NAME=quickstart+ operator$ . build/test-vm/stack/env+ operator$ make vm-enroll VM_NAME=quickstart++ :doc:`backend` explains these lines. A shell you open later needs the+ second line again.++- ``jq`` on the operator host+- A root shell on the target, in which ``shirudo`` runs the runtime+ binary:++ .. code-block:: console++ operator$ make vm-ssh VM_NAME=quickstart+- Docker on the operator host, also for the image of the web server++Install the web server+----------------------++1. Build the image of the web server and write its file system to an+ archive:++ .. code-block:: console++ operator$ mkdir -p build/tutorial+ operator$ upatches/app-sandbox/demo/build.sh build/tutorial/apache-php.tar+ shirudo-app-sandbox-demo -> build/tutorial/apache-php.tar++ :src:`upatches/app-sandbox/demo/` holds the image: Apache httpd with+ PHP, as the official ``php:8.4-apache`` image builds it, a TLS site on+ port 8443 and two scripts. The first build pulls that image. PHP runs+ inside the Apache processes here, so the ``apache`` sandbox of the+ package is the one that applies; where PHP-FPM runs the scripts, its+ processes are in the ``php-fpm`` sandbox.++2. Unpack the archive on the target:++ .. code-block:: console++ target# sh /workspace/shirudo/upatches/app-sandbox/demo/apache.sh install /workspace/shirudo/build/tutorial/apache-php.tar++ :src:`upatches/app-sandbox/demo/apache.sh` unpacks the image under+ ``/var/lib/app-sandbox-demo``, to run Apache from there in a chroot,+ since the target has no Docker. It also makes ``/usr/sbin/apache2`` a+ hard link to the server's binary: that is the path the package names,+ and a hard link is the same file. The target mounts your checkout+ read-only at ``/workspace/shirudo``. Apache does not run yet.++Publish and deliver the sandbox+-------------------------------++1. Build the package as it ships and push it to a namespace of the+ registry:++ .. code-block:: console++ operator$ tools/put-shields --version 1.0.0 --keys-dir "$KEYS" --catalog build/tutorial/sandbox.json --new-index oci://127.0.0.1:15444/hardening upatches/app-sandbox+ wrote /tmp/shirudo-bpm-build.Fr0mUH/0.upatch (insns=9408 sig=4853 data=145888 sections=3 maps=5 progs=12 decoders=0 name=app-sandbox)+ wrote /tmp/shirudo-bpm-build.Fr0mUH/0.unload.upatch (insns=1320 sig=4853 data=2832 sections=2 maps=1 progs=1 decoders=0 name=app-sandbox UNLOAD)+ put-shields: pushed oci://127.0.0.1:15444/hardening/app-sandbox:1.0.0 sha256:af1e98233268d1862b6835ed4dcf2d1f3c168198440733d478404d5588841bf7+ shirudo bpm tree append oci://127.0.0.1:15444/hardening/app-sandbox:1.0.0 --package-digest sha256:af1e98233268d1862b6835ed4dcf2d1f3c168198440733d478404d5588841bf7 oci://<registry>/<tree> --tree-id <tree-id>++ The package has two parts. :src:`upatches/app-sandbox/Beefile` names+ the files of each sandbox by path, ``/usr/sbin/apache2`` among those+ of ``apache``, and :src:`upatches/app-sandbox/sandbox.toml` gives each+ sandbox its rules. The tasks of ``apache`` execute no file but their+ own, connect and send only to loopback and private networks, and+ create, rename and open for writing no file whose name ends in+ ``.php``. The build compiles the rules into the signed upatch, so+ nobody on the target can change them. :src:`tools/put-shields` prints+ the command that appends the package to a tree. Your digest differs.++2. Keep the digest and tell the backend that the package is available:++ .. code-block:: console++ operator$ SANDBOX_DIGEST=$(jq -r '.shields[0].manifest_digest' build/tutorial/sandbox.json)+ operator$ tools/backend/jobs/shields-put build/tutorial/sandbox.json+ shields-put: oci://127.0.0.1:15444/hardening/app-sandbox:1.0.0 app-sandbox (CVE-2026-109618, CVE-2026-109619)+ shields-put: loaded shields: 1++ The catalog ``put-shields`` wrote holds the ``sha256:`` value its+ command printed after ``--package-digest``. The backend lists the+ package with the two advisories its ``Beefile`` names as the ones it+ mitigates.++3. Append the package to the tree:++ .. code-block:: console++ operator$ shirudo bpm tree append oci://127.0.0.1:15444/hardening/app-sandbox:1.0.0 --package-digest "$SANDBOX_DIGEST" "$TREE" --tree-id local-tree --keys-dir "$KEYS"+ oci://127.0.0.1:15444/shirudo/local-tree:stable sha256:cbf0590ad56459e675282d8ed34ea37dd8debd631cac338d6068912cf011505e++ The tree is a signed list of operations, and this one says ``add``+ with the upatch's payload digest. The package has no selector, so+ every target that follows the tree loads it.++4. Wait for the target's next sync, at most 10 seconds on the test VM,+ and list its upatches:++ .. code-block:: console++ target# shirudo upatch list+ Archived upatches (/var/lib/shirudo/upatches):+ NAME LOADED TYPE KIND PAYLOAD+ app-sandbox yes load bpf c6d5d7e6214b1f23..++5. Read the label the load put on the server's binary:++ .. code-block:: console++ target# python3 -c 'import os; print(os.getxattr("/usr/sbin/apache2", "security.bpf.shirudo.policy").hex())'+ 0100000000000000++ When the target loads the upatch, shirudo labels the files the+ ``Beefile`` names with the bit of their policy, ``0x1`` for+ ``apache``. A task that executes a labeled file carries the bit from+ then on, as do the tasks it starts. Only shirudo sets or removes the+ label; :doc:`/internals/seal` describes it.++Run the server in its sandbox+-----------------------------++1. Start Apache:++ .. code-block:: console++ target# sh /workspace/shirudo/upatches/app-sandbox/demo/apache.sh start++ Apache executes the labeled binary and is in the ``apache`` sandbox+ from its first instruction, with every worker it starts.++2. Request a page of the site:++ .. code-block:: console++ target# curl --silent --insecure https://127.0.0.1:8443/index.php+ GET get=0 post=0++ The site answers as it does without a sandbox.++3. Request the script that does what an attacker does next:++ .. code-block:: console++ target# curl --silent --insecure https://127.0.0.1:8443/attack.php+ write note.txt: ok+ write shell.php: refused+ rename note.txt note.php: refused+ mkdir d.php: refused+ run a command: did not run+ connect 127.0.0.1 port 8443: ok+ connect 1.1.1.1 port 80: errno 13+ target# ls /var/lib/app-sandbox-demo/var/www/html/uploads+ data.txt+ note.txt++ :src:`upatches/app-sandbox/demo/htdocs/attack.php` stands for a+ vulnerability that lets a request run PHP of the attacker's choice. In+ the site's upload directory it writes a text file, as the site does,+ and then a script the server would run on the next request, renames+ the text file to a script, runs a command and connects to a host on+ the internet. The site's own write and its connection to the target+ go through. The script cannot be planted, the command does not run+ and the connection to the internet ends in ``EACCES``, errno 13,+ although Apache started as root. Neither Apache nor PHP was changed+ or configured for it.++4. Load the tree into the backend and read the target's checks:++ .. code-block:: console++ operator$ tools/backend/jobs/tree-ingest --shirudo "$PWD/shirudo" --cert "$KEYS/cert.der" "$TREE"+ tree-ingest: loaded local-tree generation 1 (operations: 1, fixes: 2)+ operator$ docker exec -i shirudo-dev-clickhouse clickhouse-client --query "SYSTEM REFRESH VIEW shirudo.node_status_mv; SYSTEM WAIT VIEW shirudo.node_status_mv"+ operator$ docker exec -i shirudo-dev-clickhouse clickhouse-client --query "SELECT arrayJoin(log) FROM shirudo.node_status"+ 1 signed: pass, enrolled, 0 rejected in the last hour+ 2 fresh: pass, last record 7 s ago+ 3 reported: FAIL, verdict ok, cond 0x1555, flags 0, tamper +16, build 59400f7e+ 4 chain: pass, root 2beddd58+ 5 head: pass, seq 1 of 1, generation 1+ 6 set: pass, 1 loaded+ 7 peers: no peers, 1 in group++ Checks 4 to 6 say that the target is at the head of the tree and runs+ the one upatch it leaves loaded. Check 3 fails here because the+ target's tamper counters rose after its first record;+ :doc:`/operate/backend/status` says how each check reads a record.++Release the server+------------------++1. Append a delete for the package:++ .. code-block:: console++ operator$ shirudo bpm tree append oci://127.0.0.1:15444/hardening/app-sandbox:1.0.0 --package-digest "$SANDBOX_DIGEST" "$TREE" --tree-id local-tree --keys-dir "$KEYS" --op delete+ oci://127.0.0.1:15444/shirudo/local-tree:stable sha256:c852a788e10affb3405a5def41e481eada639eb2785fb86846a01e5bfc384d7a++2. After the next sync, request the attacker's script again:++ .. code-block:: console++ target# shirudo upatch list+ Archived upatches (/var/lib/shirudo/upatches):+ none+ target# curl --silent --insecure https://127.0.0.1:8443/attack.php+ write note.txt: ok+ write shell.php: ok+ rename note.txt note.php: ok+ mkdir d.php: ok+ run a command: ran+ connect 127.0.0.1 port 8443: ok+ connect 1.1.1.1 port 80: ok++ The rules went with the upatch. This is what the sandbox held back:+ the same server, with nothing around it, plants the script, runs the+ command and reaches the internet.++3. Stop Apache and remove it from the target:++ .. code-block:: console++ target# sh /workspace/shirudo/upatches/app-sandbox/demo/apache.sh remove++Tear down+---------++The guides share the stack, the VM and the tree: skip this section to+go on to another one.++1. Remove the VM, the stack and the files of this guide:++ .. code-block:: console++ operator$ make vm-stop VM_NAME=quickstart+ operator$ make vm-clean VM_NAME=quickstart+ operator$ make stack-down+ operator$ rm build/tutorial/sandbox.json build/tutorial/apache-php.tar++ Stopping the VM ends the target shell. The VM's disk and TPM state,+ the registry with the tree in it, the backend's tables and the CA+ are gone. The first lines of this guide start again from nothing.++Next steps+----------++- :doc:`/upatches/learn/examples` describes the ``app-sandbox`` package,+ every key of its rules and how to write a sandbox for another+ application.+- :doc:`/reference/formats/beefile` describes ``[[upatches.policy]]``+ and every other key of a ``Beefile``.+- :doc:`/internals/seal` explains the labels and the marks a task+ carries.+- :doc:`/operate/plan/hardening` hardens the target itself: kernel+ configuration, boot chain and TPM.+- :doc:`live-patching` and :doc:`runtime-observability` use the same+ tree for shields and for observability.diff --git a/Documentation/start/index.rst b/Documentation/start/index.rstindex 54b10100..822e5085 100644--- a/Documentation/start/index.rst+++ b/Documentation/start/index.rst@@ -11,7 +11,8 @@ life. The next pages explain the problem shirudo addresses, who it isfor and the path a upatch takes from a kernel fix to a measured load.The installation page and the quick guides then cover the first tasks:installing the packages, writing a upatch, publishing a package and-attesting a target.+attesting a target, and then the use cases with a backend: live+patching, system hardening and runtime observability... toctree:::titlesonly:diff --git a/Documentation/start/quickstart.rst b/Documentation/start/quickstart.rstindex 8b213d3c..782d623e 100644--- a/Documentation/start/quickstart.rst+++ b/Documentation/start/quickstart.rst@@ -625,6 +625,10 @@ Next steps- :doc:`guides/publish-package` ships a upatch through an OCI registry.- :doc:`guides/attest-target` enrolls the target's TPM and verifies itsevidence.+- :doc:`guides/backend` starts a registry, a collector and the example+ backend for the use-case guides: :doc:`guides/live-patching`,+ :doc:`guides/system-hardening` and+ :doc:`guides/runtime-observability`.- :doc:`how-it-works` explains each step of this page.- :doc:`install` installs shirudo on real hosts, and:doc:`/operate/deploy/boot-integration` brings a target up.