Files
alzeo/tests/test_engine_config_read_only.py
Hasan BasbunarandClaude Opus 5.5 716116aca8 Flash FP4-Local unit: its engine sees the two files of the config directory it reads, and no other
The unit mounted the whole of ~/.config/qwen38, read-only, into a container that runs a community
image, from one account, as root on the host's network. The engine reads two files there, its key
and its chat template, and the directory also holds the cockpit's own secret, enough to forge a
session of the cockpit, which drives a sudo allowlist, and the other services' keys: read-only is not
hidden (found in review, 2026-10-20). It now mounts those two files alone, read-only, with --mount,
which fails the start when a source is not there where -v made a directory in its place, owned by
root (both checked on the reference box's Docker 29.6.2 in the lane's image). The cockpit's check that
a lane does not start on an empty template read the directory's mount only, and passed this lane by:
it reads a template mounted on its own too.

Tests: the unit mounts no directory at /out and exactly those two files, read-only, and gives the
engine no other /out path; an empty template holds the lane's start back, a whole one does not.
Both fail on the code before.

Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com>
2026-10-20 09:28:08 +02:00

88 lines
5.2 KiB
Python

#!/usr/bin/env python3
"""The docker engines see the config directory read-only.
Every docker engine of the text lanes mounted ~/.config/qwen38 at /out read-write, as root in
its container: the 27B and its 1M unit (both with --trust-remote-code), the flash launcher,
Kolibri, both Nemotron lanes, and run.sh. They only read there (a chat template,
engine-secrets.yaml, the flash draft's token map, the vLLM lanes' api-key), but the directory
also holds what systemd runs as this user before or as a lane starts (engine-preflight.sh,
engine-secrets.sh, launch-flash.sh, launch-speech.sh): code that ran in an engine, a
checkpoint's own or a flaw of the engine's, could rewrite them and run as the box's user at
the next start, which a crash brings on. The image and video lanes were closed to that on
2026-10-16 and 17 (a read-only tmpfs over the directory); this is the same for the docker
lanes (found in a cloud review, 2026-10-18, and not yet run on the box). Read-only is not
hidden: an engine still reads every file there, so the review gives a mount of only the files
each engine reads as the next step.
"""
import pathlib
import re
import unittest
REPO = pathlib.Path(__file__).resolve().parents[1]
ENGINES = ("qwen38-sglang.service.template", "qwen38-sglang-1m.service.template",
"qwen38-flash-launch.sh.template", "qwen38-kolibri.service.template",
"qwen38-nemotron.service.template", "qwen38-nemotron-super.service.template", "run.sh")
# -v SOURCE:/out[:OPTIONS], the source in quotes or not
MOUNT = re.compile(r"""-v\s+["']?([^\s"':]+)["']?:/out(?::([\w,]+))?(?=["'\s]|$)""", re.M)
# what an engine is given to read under /out
READS = re.compile(r"(?:--chat-template|--config|--speculative-token-map)\s+/out/|QWEN38_KEY_FILE=/out/")
def code(name):
"""The file without its comment lines."""
return "\n".join(ln for ln in (REPO / name).read_text().splitlines() if not ln.lstrip().startswith("#"))
class TheEnginesReadTheConfigDirectory(unittest.TestCase):
def test_every_engine_mounts_it_read_only(self):
for name in ENGINES:
mounts = MOUNT.findall(code(name))
self.assertEqual(len(mounts), 1, f"{name}: {mounts}")
self.assertIn("ro", mounts[0][1].split(","), f"{name} mounts the config directory read-write")
def test_what_an_engine_finds_there_it_only_reads(self):
# a flag that wrote under /out would fail on a read-only mount: each /out/ path an
# engine is given is one it reads
for name in ENGINES:
text = code(name)
self.assertEqual(text.count("/out/"), len(READS.findall(text)),
f"{name}: an /out/ path that is not a chat template, a config, a token map or the key")
def test_the_draft_vocabulary_job_still_writes_its_map_there(self):
# not an engine: build-token-map.py writes the map it is asked for into /out, a short
# job of the installer and the switch (lanes.sh), as root: unlike its siblings in
# switch-model.sh, prepare-lane.sh and vllm-lane.sh it passes no --user (pointed out by
# the box's own agent, 2026-10-18)
text = code("lanes.sh")
job = text[text.index("docker run --rm --init --entrypoint python3"):]
job = job[:job.index("|| return 1")]
self.assertEqual(MOUNT.findall(job), [("$CONFIG_DIR", "")], job)
self.assertIn('--out "/out/$name"', job)
def test_the_flash_local_engine_sees_only_the_two_files_it_reads(self):
# a community image, from one account: the directory holds the cockpit's own secret and the
# other services' keys besides the two files this engine reads, its key and its template, and
# read-only is not hidden (found in review, 2026-10-20). --mount, not -v: a source that is not
# there fails the start instead of becoming a directory root makes in its place.
text = code("qwen38-flash-local.service.template")
self.assertEqual(MOUNT.findall(text), [], "the whole directory mounted")
mounts = re.findall(r"--mount type=bind,source=__HOME__/\.config/qwen38/([\w.-]+),target=/out/([\w.-]+),readonly",
text)
self.assertEqual(sorted(mounts), [("api-key", "api-key"),
("chat-template-flash-local.jinja", "chat-template-flash-local.jinja")])
self.assertEqual(sorted(set(re.findall(r"/out/([\w.-]+)", text))), ["api-key", "chat-template-flash-local.jinja"])
self.assertEqual(text.count("/out/") - 2, len(READS.findall(text)), "an /out/ path it is not given to read")
def test_the_shapes_are_read(self):
# so a pattern that stopped matching would not leave the scans above green and blind
for line, want in ((' -v __HOME__/.config/qwen38:/out \\', [("__HOME__/.config/qwen38", "")]),
(' -v __HOME__/.config/qwen38:/out:ro \\', [("__HOME__/.config/qwen38", "ro")]),
(' -v "$CONFIG_DIR":/out:ro \\', [("$CONFIG_DIR", "ro")]),
(' -v "/h/cfg:/out:ro,z" \\', [("/h/cfg", "ro,z")]),
(' -v /h/cfg:/output \\', [])):
self.assertEqual(MOUNT.findall(line), want, line)
if __name__ == "__main__":
unittest.main()