The privileges gate mirrors the controller's security-review fixes (image-bound entry, more classes, drive-namespace roots)
gates / gates (push) Successful in 5s
gates / gates (push) Successful in 5s
Claude-Session: https://claude.ai/code/session_0159rPz1ZhFKsS53msqPYxtS
This commit is contained in:
1 parent
d5a443dbd1
commit
6b7d40d80b
4 files changed
+48
-11
No files matched your search
@@ -12,11 +12,13 @@ classes below unless that app's service has exactly that setting on the allow-li
|
||||
fails here before it is pushed instead of being refused on every box and alarming the operator.
|
||||
|
||||
THE CLASSES (the same setting strings as the controller's — a mismatch makes this gate and the box disagree):
|
||||
privileged, cap_add, device, device_cgroup_rule, network_mode, pid, ipc, uts, userns_mode, cgroup, security_opt
|
||||
(except no-new-privileges), sysctl, volumes_from, build, extends_file, env_file outside the stack dir, bind (a host
|
||||
path outside ${HDD_PATH} / ${USERDATA_PATH} / ${IMPORT_PATH}, the Docker socket anywhere, mount propagation), volume
|
||||
privileged, cap_add, device, device_cgroup_rule, network_mode, pid, ipc, uts, userns_mode, cgroup, cgroup_parent,
|
||||
runtime, isolation, security_opt (except no-new-privileges), sysctl, volumes_from, gpus, device_request (deploy
|
||||
reservations), provider, post_start / pre_stop, build, extends_file, env_file outside the stack dir, bind (a host path
|
||||
outside ${HDD_PATH} / ${USERDATA_PATH} / ${IMPORT_PATH}, the Docker socket anywhere, mount propagation), volume
|
||||
(driver / driver_opts / external / name), config_file / secret_file outside the stack dir, include, and
|
||||
`interpolated <key>` for a ${VAR} inside any of the privileged keys.
|
||||
`interpolated <key>` for a ${VAR} inside any of the privileged keys. An allowed setting holds only while its service
|
||||
runs the entry's image repository with the image's own entrypoint and command.
|
||||
|
||||
THE LIST: scripts/privilege-allowlist.json, a BYTE-IDENTICAL copy of the controller's
|
||||
internal/privpolicy/allowlist.json (pinned there by TestAllowList_CatalogCopyIsIdentical, and here by this gate when the
|
||||
@@ -46,9 +48,11 @@ PLACEHOLDER_ENV = {
|
||||
"SUBDOMAIN": "check",
|
||||
}
|
||||
ROOT_VARS = ("HDD_PATH", "USERDATA_PATH", "IMPORT_PATH")
|
||||
SCALAR_KEYS = ("network_mode", "pid", "ipc", "uts", "userns_mode", "cgroup")
|
||||
SCALAR_KEYS = ("network_mode", "pid", "ipc", "uts", "userns_mode", "cgroup", "cgroup_parent", "runtime", "isolation")
|
||||
PRIVILEGED_KEYS = ("privileged", "cap_add", "devices", "device_cgroup_rules", "network_mode", "pid", "ipc", "uts",
|
||||
"userns_mode", "cgroup", "security_opt", "sysctls", "volumes_from")
|
||||
"userns_mode", "cgroup", "cgroup_parent", "runtime", "isolation", "security_opt", "sysctls",
|
||||
"volumes_from", "gpus", "provider", "post_start", "pre_stop")
|
||||
DRIVE_NAMESPACE = "/mnt/felhom-drives/"
|
||||
|
||||
|
||||
# ---------- a small YAML reader for compose files ----------
|
||||
@@ -336,7 +340,7 @@ def valid_roots(env):
|
||||
out = []
|
||||
for r in ROOT_VARS:
|
||||
v = env.get(r, "")
|
||||
if v and v.startswith("/") and os.path.normpath(v) == v and v != "/" and not has_dotdot(v) and v.startswith("/mnt/"):
|
||||
if v and v.startswith("/") and os.path.normpath(v) == v and v != "/" and not has_dotdot(v) and v.startswith(DRIVE_NAMESPACE):
|
||||
out.append(v)
|
||||
return out
|
||||
|
||||
@@ -394,6 +398,17 @@ def violations(doc, env):
|
||||
add(name, "volumes_from " + render(v, env))
|
||||
if "build" in sd:
|
||||
add(name, "build")
|
||||
if "gpus" in sd:
|
||||
add(name, "gpus " + canon(sd["gpus"], env))
|
||||
res = ((sd.get("deploy") or {}).get("resources") or {}) if isinstance(sd.get("deploy"), dict) else {}
|
||||
rv = res.get("reservations") if isinstance(res, dict) else None
|
||||
if isinstance(rv, dict) and "devices" in rv:
|
||||
add(name, "device_request " + canon(rv["devices"], env))
|
||||
if "provider" in sd:
|
||||
add(name, "provider " + canon(sd["provider"], env))
|
||||
for hook in ("post_start", "pre_stop"):
|
||||
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))
|
||||
@@ -450,6 +465,12 @@ def volume(v, env, roots):
|
||||
return None
|
||||
|
||||
|
||||
def image_repo(ref):
|
||||
ref = ref.strip().split("@", 1)[0]
|
||||
i = ref.rfind(":")
|
||||
return ref[:i] if i > ref.rfind("/") else ref
|
||||
|
||||
|
||||
def judge_files(root):
|
||||
tdir = os.path.join(root, "templates")
|
||||
files = []
|
||||
@@ -468,7 +489,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"]) for e in json.loads(raw_list)["entries"]}
|
||||
allowed = {(e["app"], e["service"], e["setting"]): e["image"] 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:
|
||||
@@ -493,8 +514,16 @@ def main(argv):
|
||||
bad.append("%s: cannot be read (%s) — the box refuses a definition it cannot check" % (rel, e))
|
||||
continue
|
||||
for svc, setting in violations(doc, PLACEHOLDER_ENV):
|
||||
where = "%s: %s%s" % (rel, (svc + ": ") if svc else "", setting)
|
||||
if (app, svc, setting) not in allowed:
|
||||
bad.append("%s: %s%s — not on the allow-list (scripts/privilege-allowlist.json)" % (rel, (svc + ": ") if svc else "", setting))
|
||||
bad.append(where + " — not on the allow-list (scripts/privilege-allowlist.json)")
|
||||
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)])
|
||||
elif "entrypoint" in sd or "command" in sd:
|
||||
bad.append(where + " — allowed only with the image's own entrypoint and command")
|
||||
for b in bad:
|
||||
print("REFUSED " + b)
|
||||
if bad:
|
||||
|
||||
Reference in new issue
Block a user