The privileges gate: the early warning for the box's catalog allow-list (R-971, D2 = A)
gates / gates (push) Successful in 7s
gates / gates (push) Successful in 7s
check-privileges.py (stdlib, --fast) judges every template and ladder step against the same classes the controller v0.328.0 refuses; scripts/privilege-allowlist.json is a byte-identical copy of the controller's list. Decoys + a reader-equals-PyYAML check in test_gate_decoys.py. Claude-Session: https://claude.ai/code/session_0159rPz1ZhFKsS53msqPYxtS
This commit is contained in:
1 parent
1af6ea7508
commit
d5a443dbd1
5 files changed
+619
No files matched your search
@@ -69,6 +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, 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",
|
||||
}
|
||||
|
||||
@@ -823,6 +824,77 @@ def redis_persistence_cases():
|
||||
shutil.rmtree(ws, ignore_errors=True)
|
||||
|
||||
|
||||
def privileges_cases():
|
||||
"""check-privileges.py reads templates/*/docker-compose.yml AND steps/*.yml under --root (R-971)."""
|
||||
global ran
|
||||
ws = tempfile.mkdtemp(prefix="catalog-privileges-")
|
||||
allow = io.open(os.path.join(ROOT, "scripts", "privilege-allowlist.json"), encoding="utf-8").read()
|
||||
try:
|
||||
def compose(extra="", vol=""):
|
||||
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")
|
||||
def run(name, files, expect_rc, must=(), no_templates=False, list_body=None, controller_copy=None):
|
||||
global ran
|
||||
cat = os.path.join(ws, "cat")
|
||||
shutil.rmtree(cat, ignore_errors=True)
|
||||
os.makedirs(os.path.join(cat, "scripts"))
|
||||
io.open(os.path.join(cat, "scripts", "privilege-allowlist.json"), "w", encoding="utf-8").write(list_body or allow)
|
||||
if controller_copy is not None:
|
||||
cc = os.path.join(ws, "felhom-controller", "controller", "internal", "privpolicy")
|
||||
os.makedirs(cc, exist_ok=True)
|
||||
io.open(os.path.join(cc, "allowlist.json"), "w", encoding="utf-8").write(controller_copy)
|
||||
if not no_templates:
|
||||
for rel, body in files.items():
|
||||
p = os.path.join(cat, "templates", rel)
|
||||
os.makedirs(os.path.dirname(p), exist_ok=True)
|
||||
io.open(p, "w", encoding="utf-8").write(body)
|
||||
r = sh([sys.executable, os.path.join(ROOT, "scripts", "check-privileges.py"), "--root=" + cat], ROOT)
|
||||
shutil.rmtree(os.path.join(ws, "felhom-controller"), ignore_errors=True)
|
||||
out = r.stdout + r.stderr; ran += 1
|
||||
ok = r.returncode == expect_rc and all(m in out for m in must)
|
||||
print(" %s %-70s rc=%d (expected %d)" % ("ok" if ok else "XX", name, r.returncode, expect_rc))
|
||||
if not ok:
|
||||
fails.append("%s: rc=%d expected %d; missing %s\n%s" % (name, r.returncode, expect_rc, [m for m in must if m not in out], out[-400:]))
|
||||
print("\n-- privileges: genuine and decoys (each passes)")
|
||||
run("GENUINE: a named volume and a ${HDD_PATH} bind", {"a/docker-compose.yml": compose(vol=" - ${HDD_PATH}/appdata/a:/config\n")}, 0, ("every class-setting",))
|
||||
run("DECOY: privileged: true only in a COMMENT", {"a/docker-compose.yml": compose(" # privileged: true\n")}, 0)
|
||||
run("DECOY: privileged: false", {"a/docker-compose.yml": compose(" privileged: false\n")}, 0)
|
||||
run("DECOY: no-new-privileges (a hardening)", {"a/docker-compose.yml": compose(" security_opt:\n - no-new-privileges:true\n")}, 0)
|
||||
run("DECOY: the docker socket only in a COMMENT", {"a/docker-compose.yml": compose(vol=" # - /var/run/docker.sock:/var/run/docker.sock\n")}, 0)
|
||||
run("GENUINE: homepage's allow-listed read-only socket", {"homepage/docker-compose.yml": homepage}, 0)
|
||||
print("-- privileges: the facts (each MUST be refused)")
|
||||
run("FACT: privileged true", {"a/docker-compose.yml": compose(" privileged: true\n")}, 1, ("app: privileged true",))
|
||||
run("FACT: cap_add", {"a/docker-compose.yml": compose(" cap_add: [SYS_ADMIN]\n")}, 1, ("cap_add SYS_ADMIN",))
|
||||
run("FACT: the host root bound", {"a/docker-compose.yml": compose(vol=" - /:/host\n")}, 1, ("bind / -> /host rw",))
|
||||
run("FACT: a bind through another variable", {"a/docker-compose.yml": compose(vol=" - ${OTHER}/x:/x\n")}, 1, ("bind ${OTHER}/x",))
|
||||
run("FACT: homepage's socket READ-WRITE", {"homepage/docker-compose.yml": homepage.replace("docker.sock:ro", "docker.sock")}, 1, ("docker.sock rw",))
|
||||
run("FACT: the allowed socket in ANOTHER app", {"glance/docker-compose.yml": homepage}, 1, ("glance/docker-compose.yml",))
|
||||
run("FACT: network_mode host", {"a/docker-compose.yml": compose(" network_mode: host\n")}, 1, ("network_mode host",))
|
||||
run("FACT: a driver_opts bind volume", {"a/docker-compose.yml": compose().replace("volumes:\n app_data:\n", "volumes:\n app_data:\n driver_opts:\n type: none\n o: bind\n device: /\n")}, 1, ("volume app_data driver_opts",))
|
||||
run("FACT: a ${VAR} in a privileged key", {"a/docker-compose.yml": compose(" privileged: ${PRIV}\n")}, 1, ("interpolated privileged",))
|
||||
run("FACT: privileged in a steps/ file", {"a/docker-compose.yml": compose(), "a/steps/0123456789abcdef.yml": compose(" privileged: true\n")}, 1, ("a/steps/0123456789abcdef.yml",))
|
||||
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)
|
||||
# The stdlib reader against PyYAML on every catalog file (this suite needs PyYAML anyway).
|
||||
import importlib.util
|
||||
import yaml
|
||||
spec = importlib.util.spec_from_file_location("check_privileges", os.path.join(ROOT, "scripts", "check-privileges.py"))
|
||||
m = importlib.util.module_from_spec(spec)
|
||||
spec.loader.exec_module(m)
|
||||
_, files = m.judge_files(ROOT)
|
||||
bad = [p for p in files if m.violations(yaml.safe_load(io.open(p, encoding="utf-8")), m.PLACEHOLDER_ENV)
|
||||
!= m.violations(m.load(io.open(p, encoding="utf-8").read()), m.PLACEHOLDER_ENV)]
|
||||
ran += 1
|
||||
ok = len(files) >= 100 and not bad
|
||||
print(" %s %-70s files=%d differ=%d" % ("ok" if ok else "XX", "READER: the stdlib reader equals PyYAML on the catalog", len(files), len(bad)))
|
||||
if not ok:
|
||||
fails.append("privileges reader differs from PyYAML on %s (files=%d)" % (bad[:5], len(files)))
|
||||
finally:
|
||||
shutil.rmtree(ws, ignore_errors=True)
|
||||
|
||||
|
||||
def unclean_boot_cases():
|
||||
"""check-unclean-boot-images.py reads FILES: templates/*/.felhom.yml + docker-compose.yml (+ steps/), via --root (R-1007)."""
|
||||
global ran
|
||||
@@ -1968,6 +2040,7 @@ i18n:
|
||||
login_kind_cases()
|
||||
image_volumes_cases()
|
||||
redis_persistence_cases()
|
||||
privileges_cases()
|
||||
|
||||
if fails:
|
||||
print()
|
||||
|
||||
Reference in new issue
Block a user