Secure, Fast, and Extensible Sandbox runtime for AI agents.
feat(fast-sandbox-env): default execd_run_as_init on and verify the in-guest process topology
高然0348ee20c0ac
diff --git a/scripts/fast-sandbox-env/README.md b/scripts/fast-sandbox-env/README.mdindex b25ac50a9..b5a0656b1 100644--- a/scripts/fast-sandbox-env/README.md+++ b/scripts/fast-sandbox-env/README.md@@ -97,7 +97,7 @@ Everything else comes from the OpenSandbox Helm charts (`manifests/charts`), ren`up`: preflight → sysctl → fast-sandbox checkout (pinned commit) → build images (6 fast-sandbox images via `manifests/release/build-fast-sandbox.sh` + egress + server + ingress) → XFS StateRoot → kind cluster + node labels (host ports 18080/18081) → RustFS → charts rendered + applied: base + fast-sandbox (CRDs, RBAC, control plane, installer, agent) → credentials → **MITM CA material (Secret + echo leaf cert)** → installer/agent roster asserted → charts rendered + applied: server + ingress gateway → **TLS echo endpoint (kind-network container)** → SandboxTemplate golden image **built through the server `POST /templates` API, CA baked** → SandboxPool (fastlet Ready, egress Ready, pool conditions, actions protocol check, **pinned CA fingerprint**).-`verify-native`: end-to-end verify (templateId create → signed gateway route → execd `/ping` → delete) → pause/resume round-trip (POST pause → poll `Paused` + route released → POST resume → poll `Running` → fresh-route `/ping` → delete) → vault lifecycle → **MITM CA chain verify (pinning three-way, passthrough negative control, SNI credential injection, post-resume injection)** → idle-pause/wake (IDLE_PAUSE profile) → snapshot round trip.+`verify-native`: end-to-end verify (templateId create → signed gateway route → execd `/ping` → delete) → **execd-as-init in-guest process verify** (PID 1 = guest init, execd `--init` as its subreaper child, entrypoint supervised by execd, orphan reparenting, hardening report `init_mode=subreaper`) → pause/resume round-trip (POST pause → poll `Paused` + route released → POST resume → poll `Running` → fresh-route `/ping` → delete) → vault lifecycle → **MITM CA chain verify (pinning three-way, passthrough negative control, SNI credential injection, post-resume injection)** → idle-pause/wake (IDLE_PAUSE profile) → snapshot round trip.`verify-overlaybd`: overlaybd SandboxTemplate build (oci:// publication) → the same verify matrix against the overlaybd template.@@ -123,6 +123,7 @@ The RustFS migration replaces the previous `MINIO_*` and `MC_IMAGE` overrides. B| `POOL_MIN` / `POOL_MAX` | `2` / `2` | pool capacity (auto `1`/`1` when `KIND_SINGLE=1`) || `WARM_IMAGES` | `0` | `1` = preheat pool instead of on-demand first-sandbox pull || `SBX_IMAGE` / `EXECD` | `opensandbox/fsb-sandbox-golden:latest` / `opensandbox/execd:latest` | template build inputs |+| `EXECD_RUN_AS_INIT` | `true` | OSEP-0018 execd-as-init: the server config sets `runtime.execd_run_as_init`, so templates bake `EXECD_INIT=1` and the guest boots `bootstrap.sh` into `execd --init` (subreaper under the guest init; pinned by the init-mode verify stage). `false` restores the classic background-and-wait topology — the init-mode verify stage fails by design. || `RUSTFS_IMAGE` / `RC_IMAGE` | `rustfs/rustfs:latest` / `rustfs/rc:latest` | RustFS server and CLI images || `RUSTFS_PORT` | `19000` | host-side S3 API publish; in-cluster clients use the RustFS container IP on port `9000` || `RUSTFS_CONSOLE_PORT` | `19001` | host-side RustFS console publish (human-only; override on port collision) |diff --git a/scripts/fast-sandbox-env/integration-env.sh b/scripts/fast-sandbox-env/integration-env.shindex 6beda19f2..34f87988d 100755--- a/scripts/fast-sandbox-env/integration-env.sh+++ b/scripts/fast-sandbox-env/integration-env.sh@@ -25,12 +25,16 @@# end: sandbox create via the opensandbox CLI, execd /ping through the signed# gateway route, delete, a pause/resume round trip, a snapshot -># restore-from-snapshotId boot, the egress-held credential vault lifecycle-# (OSEP-0022 FastPath relay), and the full MITM CA chain (OSEP-0022 trust+# (OSEP-0022 FastPath relay), the full MITM CA chain (OSEP-0022 trust# anchor): a self-signed CA is provisioned as the versioned Secret, the# server bakes it into the golden image, the pool pins the keypair into# mitmdump, and a guest HTTPS request proves the template↔pool fingerprint# pinning plus per-subject credential injection against a CA-signed TLS echo-# endpoint.+# endpoint, and the execd-as-init in-guest process verify (OSEP-0018: the+# server config carries runtime.execd_run_as_init, so the guest boots+# bootstrap.sh into `execd --init`; the stage pins PID 1 = guest init,+# execd --init as its child, the entrypoint supervised by execd, orphan+# reparenting to the subreaper, and hardening.init_mode=subreaper).## All Kubernetes resources come from the charts via `helm template` + plain# `kubectl apply` (no helm release state); the only env-owned manifests are@@ -61,6 +65,10 @@# SERVER_HOST_PORT / GATEWAY_HOST_PORT host-side publishes (default 18080/18081)# WARM_IMAGES=1 preheat pool warmImages (default: on-demand first-sandbox pull)# SBX_IMAGE / EXECD template build inputs (default opensandbox/fsb-sandbox-golden:latest / opensandbox/execd:latest)+# EXECD_RUN_AS_INIT OSEP-0018 execd-as-init (default true): the server+# config sets runtime.execd_run_as_init so templates bake+# EXECD_INIT=1; false restores the classic topology (the+# init-mode verify stage fails by design)# POOL_MIN / POOL_MAX pool capacity (default 2/2; auto 1/1 when KIND_SINGLE=1)# MAX_SANDBOXES_PER_POD per-fastlet sandbox capacity (default 8)# XFS_STATEROOT / XFS_SIZE reflink StateRoot on/off and virtual size@@ -131,6 +139,13 @@ RC_CONFIG_DIR="$WORK/rc-config"SBX_IMAGE="${SBX_IMAGE:-opensandbox/fsb-sandbox-golden:latest}"EXECD="${EXECD:-opensandbox/execd:latest}"+# OSEP-0018 execd-as-init: the server config carries runtime.execd_run_as_init,+# so every golden-image template bakes EXECD_INIT=1 and the guest boots+# bootstrap.sh into `execd --init` (execd supervises the workload as a+# subreaper under the fsb guest init; the init-mode verify stage pins the+# in-guest process topology). Set EXECD_RUN_AS_INIT=false for the classic+# background-and-wait topology (the init-mode verify stage will then fail).+EXECD_RUN_AS_INIT="${EXECD_RUN_AS_INIT:-true}"# WARM_IMAGES=1 preheats pool warmImages (keyed by template id); the default# is the on-demand first-sandbox pull through DART.WARM_IMAGES="${WARM_IMAGES:-0}"@@ -2341,7 +2356,8 @@ render_server_config() { # > $GEN_DIR/osb-server-config.tomlmkdir -p "$GEN_DIR"awk -v api_key="$SERVER_API_KEY" \-v fastpath="$FASTPATH_ENDPOINT" -v fsb_ns="$RESOURCE_NS" -v pool="$POOL_NAME" \- -v execd="$EXECD" -v oci_secret="$OCI_REGISTRY_SECRET" -v oci_stack="$OCI_STACK" \+ -v execd="$EXECD" -v execd_init="$EXECD_RUN_AS_INIT" \+ -v oci_secret="$OCI_REGISTRY_SECRET" -v oci_stack="$OCI_STACK" \-v mitm_ca="$MITM_CA_SECRET" '{ if ($0 == "# @OCI_PUBLISH_SECRET@") {# emitted in-place so the key stays inside [kubernetes].@@ -2354,6 +2370,7 @@ render_server_config() { # > $GEN_DIR/osb-server-config.tomlgsub(/@FSB_NAMESPACE@/, fsb_ns)gsub(/@POOL_NAME@/, pool)gsub(/@EXECD_IMAGE@/, execd)+ gsub(/@EXECD_RUN_AS_INIT@/, execd_init)gsub(/@MITM_CA_SECRET@/, mitm_ca)gsub(/@GATEWAY_ADDRESS@/, gateway)print }@@ -2369,6 +2386,10 @@ level = "INFO"[runtime]type = "kubernetes"execd_image = "@EXECD_IMAGE@"+# OSEP-0018: templates bake EXECD_INIT=1 so the guest boots bootstrap.sh into+# `execd --init` (subreaper under the fsb guest init); pinned by the+# init-mode verify stage.+execd_run_as_init = @EXECD_RUN_AS_INIT@[kubernetes]# One block for CR reads + fsb settings; sandboxes live in the pool's@@ -2805,6 +2826,116 @@ pause_resume_verify() {wait_for "pause/resume sandbox deleted" 120 verify_sandbox_gone}+# --- stage: execd-as-init in-guest process verify (OSEP-0018) -------------------+# NOTE: verify/init-mode.sh carries the split-layout copy of this stage; keep+# the two in sync until the env.sh split is completed and the verify scripts+# become the single home.++# guest_out <words...>: run a command in the sandbox through the CLI; stdout+# is the guest command's output (framing lines tolerated downstream).+guest_out() {+ osb_api command run "$VERIFY_ID" -- "$@" 2>"$LOGS_DIR/init-mode-cmd.err"+}++# guest_value <key> <words...>: extract the VALUE of the guest's KEY=VALUE+# line (first match wins; non-matching framing lines are skipped).+guest_value() { # <key> <probe-words...>+ local key="$1" line+ shift+ while IFS= read -r line || [[ -n "$line" ]]; do+ case "$line" in+ "$key="*) printf '%s\n' "${line#*=}"; return 0 ;;+ esac+ done < <(guest_out "$@")+ return 1+}++init_mode_verify() { # [template-id]+ local template_id="${1:-$TEMPLATE_ID}"+ local created execd_pid probe++ log "verify (init-mode): creating a sandbox via the opensandbox CLI (templateId=$template_id)"+ created="$(osb_api sandbox create --template "$template_id" --timeout 1h \+ --metadata origin=fast-sandbox-env-init-mode -o json 2>/dev/null)" \+ || fail "osb sandbox create failed against $SERVER_URL"+ VERIFY_ID="$(printf '%s' "$created" | jq -r '.id')"+ [[ -n "$VERIFY_ID" && "$VERIFY_ID" != "null" ]] || fail "create response carried no id"+ wait_for "init-mode target Running" 600 sandbox_running++ # 0. The full in-guest process table, verbatim: the ground truth every+ # assertion below filters, and the first evidence a failure reads.+ log "verify (init-mode): in-guest process table (pid ppid pgid sid stat args):"+ guest_out sh -c 'ps -eo pid,ppid,pgid,sid,stat,args || ps -ef' \+ | tee "$LOGS_DIR/init-mode-processes.txt" >&2 \+ || log "verify (init-mode): process table dump failed (continuing; the probes below carry the diagnostics)"++ # 1. PID 1 is the fsb guest init (not bootstrap.sh, not execd).+ probe="$(guest_value PID1 sh -c 'echo "PID1=$(tr "\0" " " < /proc/1/cmdline)"')" \+ || fail "init-mode: /proc/1/cmdline probe failed: $(head -c 300 "$LOGS_DIR/init-mode-cmd.err" 2>/dev/null)"+ case "$probe" in+ *sandbox-init*) pass "guest PID 1 is the fsb guest init ($probe)" ;;+ *) fail "guest PID 1 is not the guest init: /proc/1/cmdline = $probe" ;;+ esac++ # 2. execd is present and armed with --init.+ execd_pid="$(guest_value EXECD_PID sh -c 'echo "EXECD_PID=$(pgrep -x execd | head -1)"')" \+ || fail "init-mode: execd pgrep probe failed: $(head -c 300 "$LOGS_DIR/init-mode-cmd.err" 2>/dev/null)"+ case "$execd_pid" in+ ''|*[!0-9]*) fail "execd process not found in the guest (EXECD_PID='$execd_pid')" ;;+ esac+ probe="$(guest_value INIT_FLAG sh -c "tr \"\\0\" \"\\n\" < /proc/$execd_pid/cmdline | grep -qx -- --init && echo INIT_FLAG=1")" \+ || fail "init-mode: execd cmdline probe failed: $(head -c 300 "$LOGS_DIR/init-mode-cmd.err" 2>/dev/null)"+ [[ "$probe" == "1" ]] \+ || fail "execd (pid $execd_pid) does not carry --init (cmdline probe output: $probe)"+ pass "execd runs with --init (pid $execd_pid)"++ # 3. execd is a direct child of PID 1 (bootstrap.sh exec'd away).+ probe="$(guest_value EXECD_PPID sh -c "echo \"EXECD_PPID=\$(grep '^PPid:' /proc/$execd_pid/status | grep -o '[0-9]*')\"")" \+ || fail "init-mode: execd PPid probe failed: $(head -c 300 "$LOGS_DIR/init-mode-cmd.err" 2>/dev/null)"+ [[ "$probe" == "1" ]] \+ || fail "execd (pid $execd_pid) is not a child of PID 1: PPid=$probe"+ pass "execd is a direct child of the guest init (PPid=1)"++ # 4. The baked entrypoint is supervised by execd (its child, not a+ # sibling of bootstrap: the template default is tail -f /dev/null).+ probe="$(guest_value TAIL_PPID sh -c 'p=$(pgrep -f "tail -f /dev/null" | head -1); echo "TAIL_PPID=$(grep "^PPid:" /proc/$p/status | grep -o "[0-9]*")"')" \+ || fail "init-mode: entrypoint PPid probe failed: $(head -c 300 "$LOGS_DIR/init-mode-cmd.err" 2>/dev/null)"+ [[ "$probe" == "$execd_pid" ]] \+ || fail "the entrypoint is not a child of execd (pid $execd_pid): entrypoint PPid=$probe"+ pass "the baked entrypoint is supervised by execd (entrypoint PPid=$execd_pid)"++ # 5. Subreaper semantics: an orphaned background process reparents to+ # execd (the nearest subreaper ancestor), not to PID 1.+ guest_out sh -c 'sleep 30 >/dev/null 2>&1 & echo $! > /tmp/osb-init-mode-orphan.pid' >/dev/null \+ || fail "init-mode: orphan spawn failed: $(head -c 300 "$LOGS_DIR/init-mode-cmd.err" 2>/dev/null)"+ probe="$(guest_value ORPHAN_PPID sh -c 'p=$(cat /tmp/osb-init-mode-orphan.pid); echo "ORPHAN_PPID=$(grep "^PPid:" /proc/$p/status | grep -o "[0-9]*")"')" \+ || fail "init-mode: orphan PPid probe failed: $(head -c 300 "$LOGS_DIR/init-mode-cmd.err" 2>/dev/null)"+ [[ "$probe" == "$execd_pid" ]] \+ || fail "the orphan did not reparent to execd (pid $execd_pid): orphan PPid=$probe"+ pass "orphaned processes reparent to execd (subreaper; orphan PPid=$execd_pid)"+ guest_out sh -c 'kill $(cat /tmp/osb-init-mode-orphan.pid) 2>/dev/null; rm -f /tmp/osb-init-mode-orphan.pid' >/dev/null 2>&1 || true++ # 6. The capabilities endpoint reports the fsb/Pool init tier: execd owns+ # the process tree as a subreaper; the kernel PID 1 signal shield+ # stays with the fsb guest init.+ local hardening_line+ hardening_line="$(guest_out curl -fsS http://127.0.0.1:44772/v1/isolated/capabilities 2>/dev/null \+ | while IFS= read -r line || [[ -n "$line" ]]; do+ printf '%s' "$line" | jq -ce '.hardening // empty' 2>/dev/null && break+ done)" \+ || fail "init-mode: capabilities probe failed (no .hardening in the response): $(head -c 300 "$LOGS_DIR/init-mode-cmd.err" 2>/dev/null)"+ log "verify (init-mode): hardening report: $hardening_line"+ [[ "$(printf '%s' "$hardening_line" | jq -r '.init_mode')" == "subreaper" ]] \+ || fail "hardening.init_mode is not subreaper: $hardening_line"+ [[ "$(printf '%s' "$hardening_line" | jq -r '.signal_shield')" == "false" ]] \+ || fail "hardening.signal_shield is not false (fsb guest init owns PID 1): $hardening_line"+ pass "capabilities: hardening.init_mode=subreaper, signal_shield=false (fsb/Pool tier; no isolation TOML, floor layers stay disabled)"++ osb_api sandbox kill "$VERIFY_ID" >/dev/null 2>&1 \+ || log "verify cleanup: kill failed; remove $VERIFY_ID manually"+ wait_for "init-mode sandbox deleted" 120 verify_sandbox_gone+}+# --- stage: vault lifecycle (OSEP-0022: egress-held vault over the relay) --------# Status-code-returning variant of server_api for negative-path assertions@@ -3467,6 +3598,7 @@ verify_native() {TEMPLATE_ID="$(cat "$WORK/template-id" 2>/dev/null || true)"[[ -n "$TEMPLATE_ID" ]] || die "no template id at $WORK/template-id (run up first; template_up stores it there)"run_stage "end-to-end verify (API create -> gateway -> execd /ping)" opensandbox_verify+ run_stage "execd-as-init verify (in-guest process topology)" init_mode_verifyrun_stage "pause/resume verify (CLI -> FastPath checkpoint)" pause_resume_verifyrun_stage "vault lifecycle verify (CLI -> relay -> egress-held vault)" vault_lifecycle_verifyrun_stage "MITM CA chain verify (baked CA -> injection -> pinning)" mitm_ca_chain_verify@@ -3485,6 +3617,7 @@ verify_overlaybd() {run_stage "ublk add/del probe (node daemon -> kernel path)" ublk_probe_or_healrun_stage "SandboxTemplate build (overlaybd, oci:// publication)" template_up_overlaybdrun_stage "end-to-end verify (overlaybd template)" opensandbox_verify "$OCI_TEMPLATE_ID"+ run_stage "execd-as-init verify (overlaybd template)" init_mode_verify "$OCI_TEMPLATE_ID"run_stage "pause/resume verify (overlaybd template)" pause_resume_verify "$OCI_TEMPLATE_ID"run_stage "vault lifecycle verify (overlaybd template)" vault_lifecycle_verify "$OCI_TEMPLATE_ID"run_stage "MITM CA chain verify (overlaybd template)" mitm_ca_chain_verify "$OCI_TEMPLATE_ID"diff --git a/scripts/fast-sandbox-env/integration.sh b/scripts/fast-sandbox-env/integration.shindex 0a54b5007..d83a8f682 100755--- a/scripts/fast-sandbox-env/integration.sh+++ b/scripts/fast-sandbox-env/integration.sh@@ -45,6 +45,7 @@# env.sh environment lifecycle: env_up_stages (preflight -># SandboxPool), down, status, pool# verify/sandbox.sh end-to-end sandbox verify + egress policy + lifecycle ops+# verify/init-mode.sh execd-as-init in-guest process verify (OSEP-0018)# verify/pause-resume.sh pause/resume round trip# verify/vault.sh credential-vault relay lifecycle (OSEP-0022)# verify/idle-pause.sh idle-pause / wake-on-access (OSEP-0024, IDLE_PAUSE=1)@@ -92,6 +93,7 @@source "$(cd "$(dirname "${BASH_SOURCE[0]}")" && pwd)/lib.sh"source "$SCRIPT_DIR/env.sh"source "$SCRIPT_DIR/verify/sandbox.sh"+source "$SCRIPT_DIR/verify/init-mode.sh"source "$SCRIPT_DIR/verify/pause-resume.sh"source "$SCRIPT_DIR/verify/vault.sh"source "$SCRIPT_DIR/verify/idle-pause.sh"@@ -212,6 +214,7 @@ case "$ACTION" intrap 'on_error up' ERRenv_up_stagesrun_stage "end-to-end verify (CLI create -> gateway -> execd /ping)" opensandbox_verify+ run_stage "execd-as-init verify (in-guest process topology)" init_mode_verifyrun_stage "pause/resume verify (CLI -> FastPath checkpoint)" pause_resume_verifyrun_stage "vault lifecycle verify (CLI -> relay -> egress-held vault)" vault_lifecycle_verifyrun_stage "idle-pause / wake-on-access verify (OSEP-0024 profile)" idle_pause_verifydiff --git a/scripts/fast-sandbox-env/verify/init-mode.sh b/scripts/fast-sandbox-env/verify/init-mode.shnew file mode 100644index 000000000..a871ab3dd--- /dev/null+++ b/scripts/fast-sandbox-env/verify/init-mode.sh@@ -0,0 +1,162 @@+#!/usr/bin/env bash+# Copyright 2026 The OpenSandbox Authors+#+# Licensed under the Apache License, Version 2.0 (the "License");+# you may not use this file except in compliance with the License.+# You may obtain a copy of the License at+#+# http://www.apache.org/licenses/LICENSE-2.0+#+# Unless required by applicable law or agreed to in writing, software+# distributed under the License is distributed on an "AS IS" BASIS,+# WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.+# See the License for the specific language governing permissions and+# limitations under the License.++# verify/init-mode.sh — execd-as-init in-guest process verify (OSEP-0018)+#+# The server config in this environment sets runtime.execd_run_as_init, so+# every template bakes EXECD_INIT=1 and the golden image's guest init boots+# bootstrap.sh, which execs `execd --init` (execd supervises the workload+# through the fsb guest init, which stays PID 1 — subreaper mode, no PID 1+# signal shield). This stage pins the in-guest process topology that the+# other verifies cannot see, all through one template sandbox driven by+# `osb command run`:+#+# 0. Dump the FULL in-guest process table first (ps pid/ppid/pgid/sid/+# stat/args) — the human-readable ground truth every assertion below+# filters, kept verbatim in the stage log and at+# $LOGS_DIR/init-mode-processes.txt as failure evidence.+# 1. PID 1 is the fsb guest init (cmdline contains sandbox-init), NOT+# bootstrap.sh or execd.+# 2. execd runs with the --init flag (OSEP-0018 init duties armed).+# 3. execd is a direct child of PID 1 (bootstrap exec'd away).+# 4. The baked entrypoint (default tail -f /dev/null) is a child of execd+# — the workload is supervised by execd, not a sibling shell.+# 5. Subreaper semantics: an orphaned process reparents to execd (nearest+# subreaper ancestor), not to PID 1.+# 6. execd /v1/isolated/capabilities reports hardening.init_mode =+# subreaper and signal_shield = false (the documented fsb/Pool tier).+#+# Guest-side tool expectations: the golden image (Debian + procps) provides+# pgrep/awk/grep/curl; each probe prints one KEY=VALUE line that the host+# side extracts (the CLI stream may carry non-JSON framing).+#+# NOTE: integration-env.sh carries an inline copy of this stage (like+# vault.sh); keep the two in sync until the env.sh split is completed.++source "$(cd "$(dirname "${BASH_SOURCE[0]}")/.." && pwd)/lib.sh"++# guest_out <words...>: run a command in the sandbox through the CLI; stdout+# is the guest command's output (framing lines tolerated downstream).+guest_out() {+ osb_api command run "$VERIFY_ID" -- "$@" 2>"$LOGS_DIR/init-mode-cmd.err"+}++# guest_value <key> <words...>: extract the VALUE of the guest's KEY=VALUE+# line (first match wins; non-matching framing lines are skipped).+guest_value() { # <key> <probe-words...>+ local key="$1" line+ shift+ while IFS= read -r line || [[ -n "$line" ]]; do+ case "$line" in+ "$key="*) printf '%s\n' "${line#*=}"; return 0 ;;+ esac+ done < <(guest_out "$@")+ return 1+}++init_mode_verify() { # [template-id]+ local template_id="${1:-$TEMPLATE_ID}"+ local created execd_pid probe++ log "verify (init-mode): creating a sandbox via the opensandbox CLI (templateId=$template_id)"+ created="$(osb_api sandbox create --template "$template_id" --timeout 1h \+ --metadata origin=fast-sandbox-env-init-mode -o json 2>/dev/null)" \+ || fail "osb sandbox create failed against $SERVER_URL"+ VERIFY_ID="$(printf '%s' "$created" | jq -r '.id')"+ [[ -n "$VERIFY_ID" && "$VERIFY_ID" != "null" ]] || fail "create response carried no id"+ wait_for "init-mode target Running" 600 sandbox_running++ # 0. The full in-guest process table, verbatim: the ground truth every+ # assertion below filters, and the first evidence a failure reads.+ log "verify (init-mode): in-guest process table (pid ppid pgid sid stat args):"+ guest_out sh -c 'ps -eo pid,ppid,pgid,sid,stat,args || ps -ef' \+ | tee "$LOGS_DIR/init-mode-processes.txt" >&2 \+ || log "verify (init-mode): process table dump failed (continuing; the probes below carry the diagnostics)"++ # 1. PID 1 is the fsb guest init (not bootstrap.sh, not execd).+ probe="$(guest_value PID1 sh -c 'echo "PID1=$(tr "\0" " " < /proc/1/cmdline)"')" \+ || fail "init-mode: /proc/1/cmdline probe failed: $(head -c 300 "$LOGS_DIR/init-mode-cmd.err" 2>/dev/null)"+ case "$probe" in+ *sandbox-init*) pass "guest PID 1 is the fsb guest init ($probe)" ;;+ *) fail "guest PID 1 is not the guest init: /proc/1/cmdline = $probe" ;;+ esac++ # 2. execd is present and armed with --init.+ execd_pid="$(guest_value EXECD_PID sh -c 'echo "EXECD_PID=$(pgrep -x execd | head -1)"')" \+ || fail "init-mode: execd pgrep probe failed: $(head -c 300 "$LOGS_DIR/init-mode-cmd.err" 2>/dev/null)"+ case "$execd_pid" in+ ''|*[!0-9]*) fail "execd process not found in the guest (EXECD_PID='$execd_pid')" ;;+ esac+ probe="$(guest_value INIT_FLAG sh -c "tr \"\\0\" \"\\n\" < /proc/$execd_pid/cmdline | grep -qx -- --init && echo INIT_FLAG=1")" \+ || fail "init-mode: execd cmdline probe failed: $(head -c 300 "$LOGS_DIR/init-mode-cmd.err" 2>/dev/null)"+ [[ "$probe" == "1" ]] \+ || fail "execd (pid $execd_pid) does not carry --init (cmdline probe output: $probe)"+ pass "execd runs with --init (pid $execd_pid)"++ # 3. execd is a direct child of PID 1 (bootstrap.sh exec'd away).+ probe="$(guest_value EXECD_PPID sh -c "echo \"EXECD_PPID=\$(grep '^PPid:' /proc/$execd_pid/status | grep -o '[0-9]*')\"")" \+ || fail "init-mode: execd PPid probe failed: $(head -c 300 "$LOGS_DIR/init-mode-cmd.err" 2>/dev/null)"+ [[ "$probe" == "1" ]] \+ || fail "execd (pid $execd_pid) is not a child of PID 1: PPid=$probe"+ pass "execd is a direct child of the guest init (PPid=1)"++ # 4. The baked entrypoint is supervised by execd (its child, not a+ # sibling of bootstrap: the template default is tail -f /dev/null).+ probe="$(guest_value TAIL_PPID sh -c 'p=$(pgrep -f "tail -f /dev/null" | head -1); echo "TAIL_PPID=$(grep "^PPid:" /proc/$p/status | grep -o "[0-9]*")"')" \+ || fail "init-mode: entrypoint PPid probe failed: $(head -c 300 "$LOGS_DIR/init-mode-cmd.err" 2>/dev/null)"+ [[ "$probe" == "$execd_pid" ]] \+ || fail "the entrypoint is not a child of execd (pid $execd_pid): entrypoint PPid=$probe"+ pass "the baked entrypoint is supervised by execd (entrypoint PPid=$execd_pid)"++ # 5. Subreaper semantics: an orphaned background process reparents to+ # execd (the nearest subreaper ancestor), not to PID 1.+ guest_out sh -c 'sleep 30 >/dev/null 2>&1 & echo $! > /tmp/osb-init-mode-orphan.pid' >/dev/null \+ || fail "init-mode: orphan spawn failed: $(head -c 300 "$LOGS_DIR/init-mode-cmd.err" 2>/dev/null)"+ probe="$(guest_value ORPHAN_PPID sh -c 'p=$(cat /tmp/osb-init-mode-orphan.pid); echo "ORPHAN_PPID=$(grep "^PPid:" /proc/$p/status | grep -o "[0-9]*")"')" \+ || fail "init-mode: orphan PPid probe failed: $(head -c 300 "$LOGS_DIR/init-mode-cmd.err" 2>/dev/null)"+ [[ "$probe" == "$execd_pid" ]] \+ || fail "the orphan did not reparent to execd (pid $execd_pid): orphan PPid=$probe"+ pass "orphaned processes reparent to execd (subreaper; orphan PPid=$execd_pid)"+ guest_out sh -c 'kill $(cat /tmp/osb-init-mode-orphan.pid) 2>/dev/null; rm -f /tmp/osb-init-mode-orphan.pid' >/dev/null 2>&1 || true++ # 6. The capabilities endpoint reports the fsb/Pool init tier: execd owns+ # the process tree as a subreaper; the kernel PID 1 signal shield+ # stays with the fsb guest init.+ local hardening_line hardening+ hardening_line="$(guest_out curl -fsS http://127.0.0.1:44772/v1/isolated/capabilities 2>/dev/null \+ | while IFS= read -r line || [[ -n "$line" ]]; do+ printf '%s' "$line" | jq -ce '.hardening // empty' 2>/dev/null && break+ done)" \+ || fail "init-mode: capabilities probe failed (no .hardening in the response): $(head -c 300 "$LOGS_DIR/init-mode-cmd.err" 2>/dev/null)"+ log "verify (init-mode): hardening report: $hardening_line"+ [[ "$(printf '%s' "$hardening_line" | jq -r '.init_mode')" == "subreaper" ]] \+ || fail "hardening.init_mode is not subreaper: $hardening_line"+ [[ "$(printf '%s' "$hardening_line" | jq -r '.signal_shield')" == "false" ]] \+ || fail "hardening.signal_shield is not false (fsb guest init owns PID 1): $hardening_line"+ pass "capabilities: hardening.init_mode=subreaper, signal_shield=false (fsb/Pool tier; no isolation TOML, floor layers stay disabled)"++ osb_api sandbox kill "$VERIFY_ID" >/dev/null 2>&1 \+ || log "verify cleanup: kill failed; remove $VERIFY_ID manually"+ wait_for "init-mode sandbox deleted" 120 verify_sandbox_gone+}++# --- standalone entry ----------------------------------------------------------------++if [[ "${BASH_SOURCE[0]}" == "$0" ]]; then+ resolve_osb+ require_template_id+ trap 'on_error verify-init-mode' ERR+ run_stage "execd-as-init verify (in-guest process topology)" init_mode_verify+fi