Skip to content
Draft
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
16 changes: 10 additions & 6 deletions compose/layered.yml
Original file line number Diff line number Diff line change
Expand Up @@ -3,26 +3,26 @@
# All state and app volumes are EXTERNAL and cannot be deleted by down -v.
name: winebot-layered
services:
# Optional-startup controller: second flock domain serializes the *entire*
# Compose bootstrap before state-init, through runtime writer admission.
# Isolated disposable controller, no network or access to other state.
# Opt-in controller: its authority is held on an external, root-owned,
# protected CONTROL volume that is NOT mounted into the Wine runtime.
# Other persistent user/app volumes are excluded from this service.
deployment-gate:
image: ${WINEBOT_APP_BUNDLE_IMAGE:?pin application pack to sha256 digest}
entrypoint: ["/bin/sh", "/usr/local/bin/winebot-deployment-gate"]
user: "0:0"
network_mode: none
read_only: true
cap_drop: [ALL]
cap_add: [DAC_OVERRIDE]
# The root owner of the protected control volume needs NO DAC_OVERRIDE.
security_opt: [no-new-privileges:true]
pids_limit: 32
mem_limit: 128m
tmpfs:
- /run:rw,nosuid,nodev,mode=0700,size=1m
volumes:
- type: volume
source: artifacts
target: /state/artifacts
source: control-plane
target: /winebot-control
volume:
nocopy: true
healthcheck:
Expand Down Expand Up @@ -193,3 +193,7 @@ volumes:
shared:
external: true
name: ${WINEBOT_SHARED_VOLUME:?provide persistent shared state volume name}

control-plane:
external: true
name: ${WINEBOT_CONTROL_VOLUME:?provide protected root-owned control-plane volume name}
35 changes: 30 additions & 5 deletions formal/LAYERED_DEPLOYMENT_GATE.md
Original file line number Diff line number Diff line change
Expand Up @@ -10,12 +10,13 @@ state and win a race to start. We do **not** claim a seamless transfer of the
runtime lock FD across containers.

An **independent deployment gate** instead takes an exclusive, nonblocking
flock on `/state/artifacts/sessions/.winebot-deployment-gate.lock` and
flock on `/winebot-control/.winebot-deployment-gate.lock` in an independent
root-owned external control volume that is not mounted into the runtime and
**retains the open file description** for the entire lifetime of a small,
isolated OCI service. Both `state-init` and `winebot-interactive` depend
on the gate's health, which is only declared after lock admission. As the
controller stays alive across service startup, a second conforming Compose
project with the same external artifacts volume cannot start its own
project with the same external protected control volume cannot start its own
`state-init` even in the gap between initial setup and WineBot runtime lock.

## State machine / linearization points
Expand Down Expand Up @@ -45,9 +46,9 @@ using `docker run` without the controller, malicious same-UID writers,
a privileged host attacker, compromised/multi-host NFS, independent
uncoordinated orchestrators, and state owners pointing at mismatched
external mounts are out of model. Filesystem path identity + OCI digest
attestation still need host-level qualification. Deployment gate currently
runs root with cap DAC_OVERRIDE and artifacts RW; security review is a
specific release gate. Controller health is admission evidence, not an
attestation still need host-level qualification. Deployment gate is root-owned but has no DAC_OVERRIDE capability and
only mounts its protected control volume RW. Host volume custody, root
namespace and guest mount denial require independent security review. Controller health is admission evidence, not an
authenticated long-lived lease or an atomic cross-layer mutation.

Persistent-owner pointer CAS is **not yet wired** to restart flow. A passing
Expand All @@ -64,3 +65,27 @@ tests two distinct Compose projects with a real source-built Wine11 runtime,
then existing competing initializer, extended soak, WM recovery, SIGKILL
and durable user-state replay. Both are public disposable CI only; no
real host state or private data. Never merge on source-only green.

## R2 protected-controller correction (2026-11-23)

This is a **partial** remedy for the same-UID lock-file substitution
counterexample recorded in draft #210. The controller now holds its
long-lived deployment-gate lock inside a dedicated, root-owned mode-0700
external volume. Its Compose service is the ONLY service that mounts
`control-plane`; neither runtime nor one-shot state-init mounts it.
The controller has all Linux capabilities dropped and no network. An
unprivileged Wine UID1000 cannot unlink the controller's lock even if a
synthetic test explicitly mounts its control volume into another
unprivileged container; real Wine has no such mount.

**DO NOT CALL THIS PRODUCTION-SECURE:** the separate runtime writer
lock is *still* in `/artifacts/sessions`, which is guest-writable.
The persistent-owner CAS file remains in that same writable namespace
and is not wired into active restart. A guest may be able to subvert
that writer lock or the CAS pointer. Full release requires moving all
trusted state, generation fencing and mutation authority out of the
untrusted guest's writable namespace, with independent guest/control
process principal separation and authenticated capability-scoped IPC.
Check host mount identities, process capabilities and wrong-volume
aliasing before release. Passing the protected-controller negative
test cannot close those remaining gaps.
28 changes: 21 additions & 7 deletions scripts/ci/qualify-disposable-layers.sh
Original file line number Diff line number Diff line change
Expand Up @@ -32,6 +32,7 @@ export WINEBOT_CONFIG_VOLUME="$prefix-config"
export WINEBOT_USERDATA_VOLUME="$prefix-userdata"
export WINEBOT_ARTIFACT_VOLUME="$prefix-artifacts"
export WINEBOT_SHARED_VOLUME="$prefix-shared"
export WINEBOT_CONTROL_VOLUME="$prefix-control"
export WINEBOT_API_TOKEN=synthetic-ci-only-token
export WINEBOT_VNC_PASSWORD=synthetic-ci-only-password

Expand All @@ -41,7 +42,7 @@ bash scripts/layers/preflight.sh --create >/dev/null 2>&1 || fail preflight_crea
bash scripts/layers/preflight.sh --check >/dev/null 2>&1 || fail preflight_check
volumes=("$WINEBOT_APP_VOLUME" "$WINEBOT_PREFIX_VOLUME" "$WINEBOT_HOME_VOLUME"
"$WINEBOT_CONFIG_VOLUME" "$WINEBOT_USERDATA_VOLUME" "$WINEBOT_ARTIFACT_VOLUME"
"$WINEBOT_SHARED_VOLUME")
"$WINEBOT_SHARED_VOLUME" "$WINEBOT_CONTROL_VOLUME")
docker compose -f compose/layered.yml config --quiet >/dev/null 2>&1 || fail compose_invalid

mkdir -p apps/ci-fixture
Expand Down Expand Up @@ -82,20 +83,20 @@ docker run --rm --network none --read-only --cap-drop ALL \
# Hold the cross-container deployment lease while first and replay state
# initializers complete; the lock must reject a second independent process.
deployment_gate_cid="$(docker run -d --network none --read-only --cap-drop ALL \
--cap-add DAC_OVERRIDE --security-opt no-new-privileges \
--security-opt no-new-privileges \
--memory 128m --pids-limit 32 --tmpfs /run:rw,nosuid,nodev,mode=0700 \
--entrypoint /bin/sh \
-v "$WINEBOT_ARTIFACT_VOLUME:/state/artifacts" \
-v "$WINEBOT_CONTROL_VOLUME:/winebot-control" \
"$app_image" /usr/local/bin/winebot-deployment-gate 2>/dev/null)" ||
fail deployment_gate_start
docker exec "$deployment_gate_cid" test -f /run/winebot-deployment-ready \
>/dev/null 2>&1 || fail deployment_gate_not_ready
gate_log="$(mktemp)"
if docker run --rm --network none --read-only --cap-drop ALL \
--cap-add DAC_OVERRIDE --security-opt no-new-privileges \
--security-opt no-new-privileges \
--memory 128m --pids-limit 32 --tmpfs /run:rw,nosuid,nodev,mode=0700 \
--entrypoint /bin/sh \
-v "$WINEBOT_ARTIFACT_VOLUME:/state/artifacts" \
-v "$WINEBOT_CONTROL_VOLUME:/winebot-control" \
"$app_image" /usr/local/bin/winebot-deployment-gate >"$gate_log" 2>&1; then
rm -f "$gate_log"
fail competing_gate_admitted
Expand All @@ -107,6 +108,19 @@ fi
rm -f "$gate_log"
echo 'LAYER_RDTE stage=competing_gate_rejected'

# Even with the protected volume deliberately mounted into an unrelated
# unprivileged synthetic test container, UID1000 cannot access or unlink
# the controller's root-owned directory entry. The real runtime never
# mounts this volume at all.
if docker run --rm --network none --read-only --user 1000:1000 \
--cap-drop ALL --security-opt no-new-privileges --entrypoint /bin/sh \
-v "$WINEBOT_CONTROL_VOLUME:/winebot-control" "$app_image" -ec '
rm /winebot-control/.winebot-deployment-gate.lock
' >/dev/null 2>&1; then
fail untrusted_guest_replaced_controller_lock
fi
echo 'LAYER_RDTE stage=guest_control_lock_unlink_rejected'

# One-shot root task prepares only volume root ownership, never user contents.
docker run --rm --network none --read-only --cap-drop ALL --cap-add CHOWN --cap-add DAC_OVERRIDE \
--security-opt no-new-privileges --memory 256m --pids-limit 64 \
Expand Down Expand Up @@ -168,10 +182,10 @@ docker run --rm --network none --read-only --user 1000:1000 --cap-drop ALL \
# identical gate must then successfully acquire it (synthetic volumes only).
docker rm -f "$deployment_gate_cid" >/dev/null 2>&1 || fail gate_stop
deployment_gate_cid="$(docker run -d --network none --read-only --cap-drop ALL \
--cap-add DAC_OVERRIDE --security-opt no-new-privileges \
--security-opt no-new-privileges \
--memory 128m --pids-limit 32 --tmpfs /run:rw,nosuid,nodev,mode=0700 \
--entrypoint /bin/sh \
-v "$WINEBOT_ARTIFACT_VOLUME:/state/artifacts" \
-v "$WINEBOT_CONTROL_VOLUME:/winebot-control" \
"$app_image" /usr/local/bin/winebot-deployment-gate 2>/dev/null)" ||
fail gate_restart
docker exec "$deployment_gate_cid" test -f /run/winebot-deployment-ready \
Expand Down
5 changes: 4 additions & 1 deletion scripts/ci/qualify-wine11-layered.sh
Original file line number Diff line number Diff line change
Expand Up @@ -22,11 +22,12 @@ export WINEBOT_CONFIG_VOLUME="$prefix-config"
export WINEBOT_USERDATA_VOLUME="$prefix-userdata"
export WINEBOT_ARTIFACT_VOLUME="$prefix-artifacts"
export WINEBOT_SHARED_VOLUME="$prefix-shared"
export WINEBOT_CONTROL_VOLUME="$prefix-control"
export WINEBOT_API_TOKEN=synthetic-hil-local-only-token
export WINEBOT_VNC_PASSWORD=synthetic-hil-local-only-password
volumes=("$WINEBOT_APP_VOLUME" "$WINEBOT_PREFIX_VOLUME" "$WINEBOT_HOME_VOLUME"
"$WINEBOT_CONFIG_VOLUME" "$WINEBOT_USERDATA_VOLUME" "$WINEBOT_ARTIFACT_VOLUME"
"$WINEBOT_SHARED_VOLUME")
"$WINEBOT_SHARED_VOLUME" "$WINEBOT_CONTROL_VOLUME")
cleanup() {
docker compose -p "$prefix-challenger" -f compose/layered.yml down --remove-orphans >/dev/null 2>&1 || true
docker compose -f compose/layered.yml down --remove-orphans >/dev/null 2>&1 || true
Expand Down Expand Up @@ -188,6 +189,8 @@ docker compose -f compose/layered.yml exec -T winebot-interactive /bin/sh -ec '
printf "durable-wineprefix\n" > /wineprefix/hil-proof
printf "durable-evidence\n" > /artifacts/hil-proof
test -s /apps/.winebot-app-content-sha256
# The runtime has no control-volume mount at any guest-reachable path.
test ! -e /winebot-control
if touch /apps/unauthorized-executable.exe >/dev/null 2>&1; then exit 13; fi
if touch /opt/winebot/unauthorized-root-write >/dev/null 2>&1; then exit 14; fi
' >/dev/null 2>&1 || fail state_write_or_readonly
Expand Down
27 changes: 17 additions & 10 deletions scripts/layers/deployment-gate.sh
Original file line number Diff line number Diff line change
@@ -1,23 +1,30 @@
#!/bin/sh
# Hold a *separate* host-local, cooperative deployment admission until Compose
# stops this container. This spans state-init's release of runtime-writer flock.
# NOT distributed consensus, a hostile same-UID defense, or a privilege boundary.
# stops this container. The lock volume is root-owned and NEVER mounted into
# the Wine guest runtime. It spans state-init's release of runtime-writer flock.
# NOT distributed consensus, per-guest access policy, or a full trust boundary.
set -eu
fail() {
printf 'DEPLOYMENT_GATE stage=%s\n' "$1" >&2
exit 73
}
[ "$(id -u)" = 0 ] || fail invalid_identity
command -v flock >/dev/null 2>&1 || fail lock_unavailable
parent=/state/artifacts
root="$parent/sessions"
root=/winebot-control
lock="$root/.winebot-deployment-gate.lock"
[ -d "$parent" ] && [ ! -L "$parent" ] || fail mount_unavailable
if [ ! -d "$root" ]; then
[ ! -e "$root" ] && [ ! -L "$root" ] || fail lock_identity_invalid
mkdir -m 0700 "$root" >/dev/null 2>&1 || fail lock_unavailable
fi
[ -d "$root" ] && [ ! -L "$root" ] || fail lock_identity_invalid
[ -d "$root" ] && [ ! -L "$root" ] || fail mount_unavailable
# A fresh external Docker volume normally starts as root-owned 0755.
# The controller may reduce permissions as the directory owner; it must
# never adopt user-owned or group-writable control state.
[ "$(stat -c '%u:%g' "$root" 2>/dev/null)" = "0:0" ] ||
fail control_root_owner_invalid
case "$(stat -c '%a' "$root" 2>/dev/null)" in
700) ;;
755) chmod 0700 "$root" >/dev/null 2>&1 || fail control_root_permissions ;;
*) fail control_root_permissions ;;
esac
[ "$(stat -c '%u:%g:%a' "$root" 2>/dev/null)" = "0:0:700" ] ||
fail control_root_permissions
if [ ! -e "$lock" ]; then
[ ! -L "$lock" ] || fail lock_identity_invalid
(umask 077; : > "$lock") 2>/dev/null || fail lock_unavailable
Expand Down
2 changes: 1 addition & 1 deletion scripts/layers/preflight.sh
Original file line number Diff line number Diff line change
Expand Up @@ -17,7 +17,7 @@ done
variables=(
WINEBOT_APP_VOLUME WINEBOT_PREFIX_VOLUME WINEBOT_HOME_VOLUME
WINEBOT_CONFIG_VOLUME WINEBOT_USERDATA_VOLUME WINEBOT_ARTIFACT_VOLUME
WINEBOT_SHARED_VOLUME
WINEBOT_SHARED_VOLUME WINEBOT_CONTROL_VOLUME
)
declare -A seen=()
for variable in "${variables[@]}"; do
Expand Down
14 changes: 13 additions & 1 deletion tests/test_disposable_layer_contract.py
Original file line number Diff line number Diff line change
Expand Up @@ -42,7 +42,7 @@ def test_seed_is_idempotent_and_never_replaces_existing_apps(self):

def test_external_volumes_and_disposable_runtime_are_enforced(self):
source = (ROOT / "compose/layered.yml").read_text(encoding="utf-8")
self.assertEqual(source.count("external: true"), 7)
self.assertEqual(source.count("external: true"), 8)
self.assertIn("condition: service_completed_successfully", source)
self.assertIn("read_only: true", source)
self.assertIn("user: \"1000:1000\"", source)
Expand Down Expand Up @@ -71,6 +71,18 @@ def test_deployment_gate_spans_state_initializer_to_runtime_admission(self):
self.assertLess(gate.index("flock -n -x 9"),
gate.index("winebot-deployment-ready"))
self.assertIn("exec sleep infinity", gate)
self.assertIn("source: control-plane", compose)
self.assertIn("target: /winebot-control", compose)
self.assertIn("WINEBOT_CONTROL_VOLUME:", compose)
self.assertIn("root=/winebot-control", gate)
self.assertIn("control_root_owner_invalid", gate)
self.assertNotIn("/state/artifacts", gate)
self.assertIn("guest_control_lock_unlink_rejected", fixture)
self.assertIn("test ! -e /winebot-control", hil)
self.assertNotIn("cap_add: [DAC_OVERRIDE]", compose)
self.assertIn("WINEBOT_CONTROL_VOLUME", (
ROOT / "scripts/layers/preflight.sh"
).read_text())
self.assertIn("stage=competing_gate_rejected", fixture)
self.assertIn("stage=gate_release_reacquire_passed", fixture)
self.assertIn("stage=competing_deployment_rejected", hil)
Expand Down