R-1019: the download folders of qBittorrent, Transmission (+ watch), NZBGet, SABnzbd and MeTube are excluded from every backup tier; gate download-binds with decoys
gates / gates (push) Successful in 38s

This commit is contained in:
admin committed 2026-10-20 09:29:06 +02:00
1 parent 5e37aa6e2f
commit c50adfc641
11 files changed
+248 -14

No files matched your search

+3
View File
@@ -167,6 +167,9 @@ GATES = [
# R-986 (2026-10-19): the shared dependency and secret scanner, WARN-FIRST (exit 0 whatever it finds). It reads no
# network here (no Go module, so no govulncheck); gitleaks on the pushed commits, ~1 s. CI fetches the pinned gitleaks
# (FELHOM_SCAN_FETCH=1 in gates.yml).
# R-1019 (2026-10-20): a download client's download folder (bound at /downloads or /watch) is declared `excluded`,
# so no tier copies it — optional mirrored every download to the second drive, unlisted sent it off-site.
("download-binds", "check-download-binds.py", False, True, False),
("security-scan", "check-security-scan.py", False, True, False),
# R-1115 (2026-10-17): the gates' OWN decoy suite — every gate above is red-proved against its decoys here. It
# was not in this table, so a case that stopped convicting (a template edit removed its premise) failed for a
+134
View File
@@ -0,0 +1,134 @@
#!/usr/bin/env python3
# -*- coding: utf-8 -*-
"""check-download-binds.py — a download client's download folder is never backed up (`excluded`).
python3 scripts/check-download-binds.py # every template under templates/
python3 scripts/check-download-binds.py --root DIR # another checkout (the decoy harness)
WHY (R-1019, 2026-10-20; felhom.eu `architecture/15-media-library.md` §7). A download folder is large and can be
fetched again. Declared `optional`, it is mirrored to the household's second drive every night (Tier 2 = mandatory +
optional) and can fill it with films; left UNLISTED, the controller classes a writable `${…_PATH}` bind MANDATORY and
it goes off-site too (`stacks/classify_binds.go`; measured 2026-10-14 for Transmission's watch folder). So every
download folder is declared `excluded`: no tier copies it (`appbackup.tierKeeps`).
WHAT IS A DOWNLOAD FOLDER — judged by the FACT, not by an app name: a `${USERDATA_PATH}/<folder>` bind of
templates/<app>/docker-compose.yml whose CONTAINER target is `/downloads` or `/watch` (or below them) — where every
download client of the catalog writes (qBittorrent, Transmission, NZBGet, SABnzbd on 2026-10-20). The same folder
bound a second time elsewhere (qBittorrent binds it at its own path too) is the same folder. Its class is read from
.felhom.yml `backup: userdata:` (`- path: <folder>` + `class:`); it must be `excluded`. NOT judged, on purpose:
steps/<key>.yml — a ladder step carries the compose only; the backup classes live in .felhom.yml alone.
STANDARD LIBRARY ONLY (the CI runner has no PyYAML); comments never count.
Exit 0 clean · 1 a download folder is optional, mandatory or unlisted · 3 nothing to judge.
"""
import io
import os
import re
import sys
ROOT = os.path.dirname(os.path.dirname(os.path.abspath(__file__)))
DOWNLOAD_TARGETS = ("/downloads", "/watch")
BIND = re.compile(r"""^\s*-\s*["']?\$\{USERDATA_PATH\}/([^:"'\s]+):([^:"'\s]+)""")
def strip_comment(line):
out, q = [], None
for c in line:
if q:
if c == q:
q = None
elif c in "'\"":
q = c
elif c == "#":
break
out.append(c)
return "".join(out).rstrip()
def is_download_target(target):
t = target.rstrip("/")
return any(t == d or t.startswith(d + "/") for d in DOWNLOAD_TARGETS)
def download_folders(compose):
"""The userdata folders a compose binds at a download target (sorted, de-duplicated)."""
out = set()
with io.open(compose, encoding="utf-8") as f:
for raw in f:
m = BIND.match(strip_comment(raw.rstrip("\n")))
if m and is_download_target(m.group(2)):
out.add(m.group(1).rstrip("/"))
return sorted(out)
def userdata_classes(felhom):
"""{path: class} from .felhom.yml `backup:` → `userdata:` — a line reader for the catalog's own shape."""
out, in_backup, in_userdata, cur = {}, False, False, None
if not os.path.exists(felhom):
return out
with io.open(felhom, encoding="utf-8") as f:
for raw in f:
line = strip_comment(raw.rstrip("\n"))
if not line.strip():
continue
ind = len(line) - len(line.lstrip(" "))
if ind == 0:
in_backup, in_userdata, cur = line.startswith("backup:"), False, None
continue
if not in_backup:
continue
if ind == 2:
in_userdata, cur = line.strip() == "userdata:", None
continue
if not in_userdata:
continue
m = re.match(r"^\s*-\s*path:\s*['\"]?([^'\"]+?)['\"]?\s*$", line)
if m:
cur = m.group(1).strip().rstrip("/")
out[cur] = ""
continue
m = re.match(r"^\s*class:\s*['\"]?([A-Za-z]+)['\"]?\s*$", line)
if m and cur is not None:
out[cur] = m.group(1)
return out
def main(argv):
root = ROOT
for a in argv:
if a.startswith("--root="):
root = a.split("=", 1)[1]
tdir = os.path.join(root, "templates")
if not os.path.isdir(tdir):
print("download-binds: nothing to judge — no templates/ under %s" % root)
return 3
judged, bad = [], []
for app in sorted(os.listdir(tdir)):
compose = os.path.join(tdir, app, "docker-compose.yml")
if not os.path.isfile(compose):
continue
folders = download_folders(compose)
if not folders:
continue
classes = userdata_classes(os.path.join(tdir, app, ".felhom.yml"))
for folder in folders:
cls = classes.get(folder)
judged.append("%s:%s=%s" % (app, folder, cls or "UNLISTED"))
if cls != "excluded":
why = ("UNLISTED in backup.userdata — the controller classes it MANDATORY (every tier, off-site included)"
if cls is None else "declared `%s` — %s" % (cls, "a nightly copy on the second drive" if cls == "optional" else "copied by the backup"))
bad.append("templates/%s: the download folder %s is %s; declare it `class: excluded` (R-1019)" % (app, folder, why))
if not judged:
print("download-binds: nothing to judge — no template binds a folder at %s" % " or ".join(DOWNLOAD_TARGETS))
return 3
if bad:
print("download-binds gate FAILED (%d of %d download folder(s)):" % (len(bad), len(judged)))
for b in bad:
print(" " + b)
return 1
print("download-binds gate OK — %d download folder(s), every one `excluded`: %s" % (len(judged), ", ".join(judged)))
return 0
if __name__ == "__main__":
sys.exit(main(sys.argv[1:]))
+49
View File
@@ -71,6 +71,7 @@ COVERS = {
"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 read-only socket on a test list carrying its old entry - each passes; vs the facts: privileged true, cap_add, a host-root bind, a ${OTHER} bind, homepage's socket on the REAL list (R-981: no exception), app a binding app b's appdata folder or the whole appdata/ or a look-alike name, a folder entry that is a path (R-1142; paperless-ngx's listed appdata/paperless passes), 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)",
"download-binds": "the download target `/downloads` only in a COMMENT, `class: excluded` only in a COMMENT while the field says optional, the folder bound only in a steps/ file (not judged on purpose), a library bind at /media (not a download target) - vs the facts: a download folder optional, mandatory, UNLISTED (the controller classes it mandatory), a `/watch` sub-folder optional under an excluded parent, a target below /downloads - each refused naming the app; excluded passes; no templates/ and no download bind at all are rc 3, never a pass (R-1019)",
"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",
}
@@ -825,6 +826,53 @@ def redis_persistence_cases():
shutil.rmtree(ws, ignore_errors=True)
def download_binds_cases():
"""check-download-binds.py reads templates/*/docker-compose.yml + .felhom.yml under --root; steps/ not (R-1019)."""
global ran
ws = tempfile.mkdtemp(prefix="catalog-dlbinds-")
try:
def compose(binds, comment=""):
return ("services:\n dl:\n image: example/dl:1.0\n volumes:\n - dl_config:/config\n%s%s"
"volumes:\n dl_config:\n" % (comment, "".join(" - %s\n" % b for b in binds)))
def felhom(entries, comment=""):
body = "".join(" - path: %s\n class: %s\n" % (p, c) for p, c in entries)
return ("display_name: \"DL\"\nbackup:\n volumes:\n - name: dl_config\n class: important\n"
" userdata:\n%s%s" % (body, comment))
def run(name, files, expect_rc, must=(), no_templates=False):
global ran
cat = os.path.join(ws, "cat")
shutil.rmtree(cat, ignore_errors=True)
os.makedirs(cat)
if not no_templates:
os.makedirs(os.path.join(cat, "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-download-binds.py"), "--root=" + cat], ROOT)
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:]))
dl = "${USERDATA_PATH}/media/dl:/downloads"
print("\n-- download-binds: genuine and decoys (each passes)")
run("GENUINE: the download folder excluded", {"dl/docker-compose.yml": compose([dl]), "dl/.felhom.yml": felhom([("media/dl", "excluded")])}, 0, ("every one `excluded`",))
run("DECOY: /downloads only in a COMMENT (the field binds /media)", {"dl/docker-compose.yml": compose(["${USERDATA_PATH}/media:/media:ro", "${USERDATA_PATH}/media/dl:/downloads"][:1], comment=" # - ${USERDATA_PATH}/media/dl:/downloads\n") , "dl/.felhom.yml": felhom([("media", "excluded")])}, 3, ("nothing to judge",))
run("DECOY: the folder bound only in a steps/ file (not judged)", {"dl/docker-compose.yml": compose([dl]), "dl/.felhom.yml": felhom([("media/dl", "excluded")]), "dl/steps/0123456789abcdef.yml": compose(["${USERDATA_PATH}/media/other:/downloads"])}, 0, ("1 download folder",))
print("-- download-binds: the facts (each MUST be refused)")
run("FACT: the download folder optional", {"dl/docker-compose.yml": compose([dl]), "dl/.felhom.yml": felhom([("media/dl", "optional")])}, 1, ("templates/dl", "media/dl", "optional"))
run("FACT: the download folder mandatory", {"dl/docker-compose.yml": compose([dl]), "dl/.felhom.yml": felhom([("media/dl", "mandatory")])}, 1, ("mandatory",))
run("FACT: the download folder UNLISTED (mandatory by default)", {"dl/docker-compose.yml": compose([dl]), "dl/.felhom.yml": felhom([("media/other", "excluded")])}, 1, ("UNLISTED",))
run("FACT: `class: excluded` only in a COMMENT, the field optional", {"dl/docker-compose.yml": compose([dl]), "dl/.felhom.yml": felhom([("media/dl", "optional")], comment=" # - path: media/dl\n # class: excluded\n")}, 1, ("optional",))
run("FACT: a /watch sub-folder optional under an excluded parent", {"dl/docker-compose.yml": compose([dl, "${USERDATA_PATH}/media/dl/watch:/watch"]), "dl/.felhom.yml": felhom([("media/dl", "excluded"), ("media/dl/watch", "optional")])}, 1, ("media/dl/watch",))
run("FACT: a target below /downloads", {"dl/docker-compose.yml": compose(["${USERDATA_PATH}/media/done:/downloads/complete"]), "dl/.felhom.yml": felhom([("media/done", "optional")])}, 1, ("media/done",))
run("FACT: no download bind anywhere (nothing to judge)", {"dl/docker-compose.yml": compose(["${USERDATA_PATH}/media:/media:ro"]), "dl/.felhom.yml": felhom([("media", "excluded")])}, 3, ("nothing to judge",))
run("FACT: no templates/ at all (nothing to judge)", {}, 3, ("nothing to judge",), no_templates=True)
finally:
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
@@ -2107,6 +2155,7 @@ i18n:
image_volumes_cases()
redis_persistence_cases()
privileges_cases()
download_binds_cases()
security_scan_cases()
if fails: