Files
zapret-autotune/deploy/managed-target/check_static.py
T
ZeusinaandGPT-6 Bot 0398e6fe28 fix(managed): guard dropped-UID queue ownership inspection
Require effective SYS_PTRACE only for native owned workers and distinguish denied FD inspection from foreign queue ownership. Keep inode proof authoritative and constrain deployment to its private PID namespace.

Co-authored-by: GPT-6 <gpt-6@openai.com>
2026-10-11 21:48:06 +03:00

60 lines
3.5 KiB
Python

"""Static deployment guard; run with python3 deploy/managed-target/check_static.py."""
from pathlib import Path
directory = Path(__file__).resolve().parent
compose = (directory / "compose.yaml").read_text()
entrypoint = (directory.parents[1] / "managed-target-entrypoint.sh").read_text()
readme = (directory / "README.md").read_text()
# ponytail: checks the committed Compose shape, not arbitrary YAML; use a YAML
# parser if this definition grows beyond its single target service.
assert " privileged: false\n" in compose
assert " image: ${ZAPRET_AUTOTUNE_IMAGE:-zapret-autotune-managed-target:local}\n" in compose
assert " cap_drop: [ALL]\n" in compose
assert " cap_add: [NET_ADMIN, NET_RAW, SETUID, SETGID, KILL, SYS_PTRACE]\n" in compose
assert "pid:" not in compose # Keep inspection confined to the private PID namespace.
assert compose.count(" - type: bind\n") == 1
assert " source: ./target-state\n" in compose
assert " target: /var/lib/zapret-autotune/target\n" in compose
assert " create_host_path: false\n" in compose
assert "SS_PASSWORD: ${SS_PASSWORD:?Set SS_PASSWORD in the deployment environment}" in compose
for setting in (
'SS_DNS_SERVER: ${SS_DNS_SERVER-}',
'ZAPRET_AUTOTUNE_YOUTUBE_SERVICE: ${ZAPRET_AUTOTUNE_YOUTUBE_SERVICE-0}',
'ZAPRET_AUTOTUNE_GOOGLEVIDEO_MODE: ${ZAPRET_AUTOTUNE_GOOGLEVIDEO_MODE-cold}',
'ZAPRET_AUTOTUNE_VIDEO_ID: ${ZAPRET_AUTOTUNE_VIDEO_ID-dQw4w9WgXcQ}',
"ZAPRET_AUTOTUNE_GOOGLEVIDEO_VIDEO_IDS: '${ZAPRET_AUTOTUNE_GOOGLEVIDEO_VIDEO_IDS-[\"${ZAPRET_AUTOTUNE_VIDEO_ID-dQw4w9WgXcQ}\"]}'",
):
assert setting in compose, setting
assert entrypoint.index('target-config-check || exit 64') < entrypoint.index('cat > "$config_dir/server.json"')
assert 'set -- "$@" -d "$SS_DNS_SERVER"' in entrypoint
assert 'eval ' not in entrypoint
assert "secrets:" not in compose
assert "ss_password=${SS_PASSWORD-}" in entrypoint
assert "unset SS_PASSWORD" in entrypoint
assert "export ss_password" not in entrypoint
assert "export SS_PASSWORD" not in entrypoint
assert "Docker administrators/root can still read container" in readme
assert "removed\nfrom the entrypoint environment" in readme
assert "No host networking" in readme
assert ' restart: "no"\n' in compose
assert " stop_grace_period: 240s\n" in compose
assert 'bounded_wait "$monitor_pid" 45' in entrypoint
assert '/bin/sh /opt/managed-target-supervision.sh --watchdog' in entrypoint
assert 'setsid /bin/sh /opt/managed-target-supervision.sh --monitor' in entrypoint
assert entrypoint.index('if ! cleanup_session; then') < entrypoint.index('if timeout -k 5 45 /usr/local/bin/zapret-autotune managed reconcile; then')
assert 'COPY managed-target-supervision.sh /opt/managed-target-supervision.sh' in (directory.parents[1] / 'Dockerfile.target').read_text()
assert '!managed-target-supervision.sh' in (directory.parents[1] / '.dockerignore').read_text()
assert '"$count" -lt 3' in entrypoint
assert '"$((now - started))" -lt 21600' in entrypoint
assert "backoff=15" in entrypoint
assert "systemctl" not in entrypoint and "docker " not in entrypoint
assert "timeout -k 5 30 /opt/zapret2/init.d/sysv/zapret2 stop" in entrypoint
for command, seconds in (("/usr/local/bin/zapret-autotune managed init", 45),
("/usr/local/bin/zapret-autotune managed reconcile", 45),
("/opt/zapret2/init.d/sysv/zapret2 start", 30)):
assert f"timeout -k 5 {seconds} {command} || exit 78" in entrypoint
assert entrypoint.index("managed reconcile || exit 78") < entrypoint.index("zapret2 start || exit 78")