diff --git a/scripts/check-privileges.py b/scripts/check-privileges.py index e1c4607..7da8d7e 100644 --- a/scripts/check-privileges.py +++ b/scripts/check-privileges.py @@ -142,7 +142,16 @@ def _scalar(s): return s +ANCHOR = re.compile(r"(^|[\s\[{,:-])[&*][A-Za-z0-9_-]+|<<\s*:") + + def load(text): + for n, line in enumerate(text.split("\n"), 1): + c = _strip_comment(line) + if ANCHOR.search(c): + # the box's YAML library expands anchors and merge keys; this reader does not — refuse rather than judge a + # different document than the box will (a merge can carry an allowed right into another service) + raise YamlError("YAML anchor, alias or merge key at line %d (not used by the catalog; refused)" % n) raw = text.split("\n") lines = [] # (indent, content, rawline) i = 0 @@ -410,8 +419,13 @@ def violations(doc, env): if hook in sd: add(name, hook + " " + canon(sd[hook], env)) ex = sd.get("extends") - if isinstance(ex, dict) and "file" in ex: - add(name, "extends_file " + shown(ex["file"], env)) + if isinstance(ex, dict): + if "file" in ex: + add(name, "extends_file " + shown(ex["file"], env)) + else: + add(name, "extends " + shown(ex.get("service"), env)) + elif isinstance(ex, str): + add(name, "extends " + shown(ex, env)) for v in as_list(sd.get("env_file")): raw = v.get("path") if isinstance(v, dict) else v if not inside_stack(render(raw, env)): @@ -430,6 +444,8 @@ def volume(v, env, roots): if len(parts) < 2: return None raw_src = parts[0] + if raw_src.startswith(("/", ".", "~", "$")) and (not root_led(parts[1]) or (len(parts) > 2 and has_interp(":".join(parts[2:])))): + return "bind " + v + " with a variable in its target or options" src, dst, mode = render(parts[0], env), render(parts[1], env), "rw" if len(parts) > 2: for o in parts[2].split(","): @@ -489,7 +505,7 @@ def main(argv): root = a.split("=", 1)[1] with io.open(os.path.join(root, ALLOWLIST), encoding="utf-8") as f: raw_list = f.read() - allowed = {(e["app"], e["service"], e["setting"]): e["image"] for e in json.loads(raw_list)["entries"]} + allowed = {(e["app"], e["service"], e["setting"]): e for e in json.loads(raw_list)["entries"]} sibling = os.path.join(root, CONTROLLER_COPY) if os.path.exists(sibling): with io.open(sibling, encoding="utf-8") as f: @@ -520,10 +536,17 @@ def main(argv): continue # the entry holds only for its image repository and the image's own start (security review 2026-10-17) sd = (doc.get("services") or {}).get(svc) or {} - if image_repo(render(sd.get("image"), PLACEHOLDER_ENV)) != allowed[(app, svc, setting)]: - bad.append(where + " — allowed only for image " + allowed[(app, svc, setting)]) + e = allowed[(app, svc, setting)] + hc = sd.get("healthcheck") if isinstance(sd.get("healthcheck"), dict) else {} + test = json.dumps(hc["test"], separators=(",", ":")) if "test" in hc else "" + if has_interp(sd.get("image")): + bad.append(where + " — allowed only with a literal image (no variable)") + elif image_repo(render(sd.get("image"), PLACEHOLDER_ENV)) != e["image"]: + bad.append(where + " — allowed only for image " + e["image"]) elif "entrypoint" in sd or "command" in sd: bad.append(where + " — allowed only with the image's own entrypoint and command") + elif test != e.get("healthcheck", ""): + bad.append(where + " — allowed only with the healthcheck the list names") for b in bad: print("REFUSED " + b) if bad: diff --git a/scripts/privilege-allowlist.json b/scripts/privilege-allowlist.json index 1000b9f..2bbfb21 100644 --- a/scripts/privilege-allowlist.json +++ b/scripts/privilege-allowlist.json @@ -1,12 +1,13 @@ { "version": 1, - "note": "R-971 (operator decision D2 = A, 2026-10-17). The box's catalog allow-list, compiled into the controller. Each entry allows ONE exact setting for ONE service of ONE app, only while that service runs the entry's image repository with the image's own entrypoint and command; a changed setting is a different one and is refused. The catalog's scripts/privilege-allowlist.json is a byte-identical copy for its CI gate. Survey: felhom.eu documentation/audits/agent-allowlist-rotation-2026-10-17/P2/survey.md", + "note": "R-971 (operator decision D2 = A, 2026-10-17). The box's catalog allow-list, compiled into the controller. Each entry allows ONE exact setting for ONE service of ONE app, only while that service runs the entry's image repository with the image's own entrypoint and command and the exact healthcheck named; a changed setting is a different one and is refused. The catalog's scripts/privilege-allowlist.json is a byte-identical copy for its CI gate. Survey: felhom.eu documentation/audits/agent-allowlist-rotation-2026-10-17/P2/survey.md", "entries": [ { "app": "homepage", "service": "homepage", "setting": "bind /var/run/docker.sock -> /var/run/docker.sock ro", "image": "ghcr.io/gethomepage/homepage", + "healthcheck": "[\"CMD\",\"wget\",\"--spider\",\"-q\",\"http://127.0.0.1:3000\"]", "why": "the Docker widget and the docker service discovery list the household's containers and their state", "doc": "https://gethomepage.dev/configs/docker/" } diff --git a/scripts/test_gate_decoys.py b/scripts/test_gate_decoys.py index de4fe53..cf30624 100644 --- a/scripts/test_gate_decoys.py +++ b/scripts/test_gate_decoys.py @@ -69,7 +69,7 @@ COVERS = { "login-kind": "login_kind written only in a COMMENT, only inside the English i18n: block, or under ANOTHER mapping (resources:) - none is the field, each passes; vs the facts: an unknown value (`magic`), a wrong case (`EMAIL`), the key twice, and no templates/ at all (rc 3, never a pass); the three known values pass (controller 0.320.0)", "copy-i18n": "Hungarian edited in a COMMENT/README/display_name (label, not copy) vs a real frozen string changed; an English block that is not English, is not matched to a Hungarian twin, or rewrites a credential (R-560). A retrieval promise REGISTERED in ALLOWLIST_EN passes only for its own app+path+sentence with a real reason; an entry for another app, a rewritten sentence, a stale entry or a two-word reason convicts (R-594). Also the DEGRADED mode CI actually runs — PyYAML shadowed out, freeze only (R-595). THE USER GUIDE (2026-10-15): a download-source name only in a COMMENT or in docs_url passes; vs the facts - guide strings not frozen, checked_version in the English block, an empty steps list, an FAQ entry with no answer, an unquoted version, an English guide with no Hungarian one, more English sections than Hungarian, a different step count, and a source name in either language", "redis-persistence": "`--appendonly yes` only in a COMMENT, or only in a steps/ file (a tested step definition, not judged on purpose) - each passes; vs the facts: AOF in string form, in a flow list, in a block list, on a valkey image - each refused naming the app; image default (no command) and `--appendonly no` pass; no templates/ is rc 3 (R-1096)", - "privileges": "a dangerous key only in a COMMENT, `privileged: false`, `no-new-privileges:true`, a ${HDD_PATH} bind, the docker socket only in a comment, homepage's own allow-listed read-only socket - each passes; vs the facts: privileged true, cap_add, a host-root bind, a ${OTHER} bind, homepage's socket READ-WRITE, the same socket in ANOTHER app or under ANOTHER image or with an added entrypoint, gpus / provider / a privileged post_start, network_mode host, a driver_opts bind volume, a ${VAR} in a privileged key, the same in a steps/ file, an allow-list copy that differs from the controller's - each refused naming the setting; no templates/ is rc 3; and the stdlib reader equals PyYAML on every catalog file (R-971)", + "privileges": "a dangerous key only in a COMMENT, `privileged: false`, `no-new-privileges:true`, a ${HDD_PATH} bind, the docker socket only in a comment, homepage's own allow-listed read-only socket - each passes; vs the facts: privileged true, cap_add, a host-root bind, a ${OTHER} bind, homepage's socket READ-WRITE, the same socket in ANOTHER app or under ANOTHER image or with an added entrypoint or a changed healthcheck, a second service extending it, a YAML merge key, a variable in a bind's options, gpus / provider / a privileged post_start, network_mode host, a driver_opts bind volume, a ${VAR} in a privileged key, the same in a steps/ file, an allow-list copy that differs from the controller's - each refused naming the setting; no templates/ is rc 3; and the stdlib reader equals PyYAML on every catalog file (R-971)", "gate-decoys": "this suite, run as a gate of the full run (R-1115): every case above is a decoy of its own gate, and ONE case that stops convicting turns the whole run red - measured 2026-10-17, when the credential-token case had lost its premise (gokapi's login line removed by 326f846) the suite printed FAIL and exited 1; the copy-i18n credential cases now edit an EXISTING line, so a removed premise stops the suite (`edit` raises) instead of passing", } @@ -834,7 +834,9 @@ def privileges_cases(): return ("services:\n app:\n image: example/app:1.0\n%s volumes:\n - app_data:/data\n%s" "volumes:\n app_data:\n" % (extra, vol)) homepage = ("services:\n homepage:\n image: ghcr.io/gethomepage/homepage:v1.13.2\n volumes:\n" - " - homepage_config:/app/config\n - /var/run/docker.sock:/var/run/docker.sock:ro\nvolumes:\n homepage_config:\n") + " - homepage_config:/app/config\n - /var/run/docker.sock:/var/run/docker.sock:ro\n" + " healthcheck:\n test: [\"CMD\", \"wget\", \"--spider\", \"-q\", \"http://127.0.0.1:3000\"]\n" + "volumes:\n homepage_config:\n") def run(name, files, expect_rc, must=(), no_templates=False, list_body=None, controller_copy=None): global ran cat = os.path.join(ws, "cat") @@ -878,6 +880,10 @@ def privileges_cases(): run("FACT: homepage's socket under ANOTHER image", {"homepage/docker-compose.yml": homepage.replace("ghcr.io/gethomepage/homepage", "docker.io/evil/homepage")}, 1, ("allowed only for image",)) run("FACT: homepage's socket with an added entrypoint", {"homepage/docker-compose.yml": homepage.replace(" volumes:", " entrypoint: [sh, -c, id]\n volumes:", 1)}, 1, ("own entrypoint",)) run("FACT: gpus / a provider service / a privileged post_start", {"a/docker-compose.yml": compose(" gpus: all\n provider:\n type: model\n post_start:\n - command: id\n privileged: true\n")}, 1, ("gpus all", "provider", "post_start")) + run("FACT: a second service EXTENDS homepage (inherits the socket)", {"homepage/docker-compose.yml": homepage.replace("volumes:\n homepage_config:", " evil:\n image: evil/x:1\n extends:\n service: homepage\nvolumes:\n homepage_config:")}, 1, ("extends homepage",)) + run("FACT: homepage's healthcheck runs a shell", {"homepage/docker-compose.yml": homepage.replace('["CMD", "wget", "--spider", "-q", "http://127.0.0.1:3000"]', '["CMD-SHELL", "id"]')}, 1, ("healthcheck the list names",)) + run("FACT: a YAML merge key (the box expands it, the reader does not)", {"a/docker-compose.yml": "x-base: &base\n privileged: true\n" + compose(" <<: *base\n")}, 1, ("anchor",)) + run("FACT: a variable in a bind's options", {"a/docker-compose.yml": compose(vol=" - ${HDD_PATH}/a:/a:${MODE}\n")}, 1, ("variable in its target or options",)) run("GENUINE: homepage bumped to a new tag of the same image", {"homepage/docker-compose.yml": homepage.replace("homepage:v1.13.2", "homepage:v1.14.0")}, 0) run("FACT: the list copy differs from the controller's", {"a/docker-compose.yml": compose()}, 1, ("differs",), controller_copy=allow.replace("homepage", "glance")) run("FACT: no templates/ at all (nothing to judge)", {}, 3, ("nothing to judge",), no_templates=True)