fix: resolve 17 confirmed bash-parity drifts from port review

Adversarial parity review of every ported action against its bash source
confirmed 17 real behavioral drifts (of 22 claimed); all fixed here:

- tiers/chown: defaults were compositions/apex/tierN (one level too deep);
  now the tier roots. shared/ base reset is non-recursive again.
- compose: --dry-run was swallowed by argparse.REMAINDER; now stripped.
- host.write_file: rendered files land 0644 (tempfile's 0600 made fresh
  systemd units/crowdsec configs owner-only).
- systemd.deploy_units: top-level non-hidden files only.
- ufw: missing docker/host config dir exits 66; missing /etc/ufw target
  aborts; empty rules dir warns; dotfile .rules excluded.
- sync/packages: Telegram error-trap parity and failed notify exits 1.
  Same notify-failure exit for backup/run and sync/repository.
  repository regains the node-dir guard.
- tiers/useradd: no more secret-bearing .env.bak per run.
- tiers/link: EOF on confirm prompt declines and continues.
- extract-traefik-certs: sudo mkdir inside the notify envelope.
- generate-happ-subscriptions: realpath parent-exists guards + docker check.
- configure/crowdsec: bouncer install goes through install_packages.
- lint-docker-compose: malformed/unreadable anchor-IP inputs are lint errors.
- core compose: APEX_RESTIC_REPOSITORY now ?error; RESTIC_COMPRESSION
  per-node via APEX_RESTIC_COMPRESSION (default auto).
- sys.service_exists line-anchored; tpl docstring corrected.
This commit is contained in:
deytenit committed 2026-07-05 10:50:40 +03:00
1 parent ad47b73928
commit 6aaef35780
20 files changed
+152 -41

No files matched your search

+4 -3
View File
@@ -15,10 +15,11 @@ def run(ctx, args):
log.error(f"Source file not found: {args.source_acme}"); raise SystemExit(1)
abs_src = os.path.realpath(args.source_acme)
src_dir, src_file = os.path.dirname(abs_src), os.path.basename(abs_src)
ctx.sys.sudo(["mkdir", "-p", args.dest_dir])
abs_dest = os.path.realpath(args.dest_dir)
log.info(f"Extracting certs: {abs_src} -> {abs_dest}")
try:
# Inside the notify envelope: bash armed its Telegram ERR trap before this mkdir.
ctx.sys.sudo(["mkdir", "-p", args.dest_dir])
abs_dest = os.path.realpath(args.dest_dir)
log.info(f"Extracting certs: {abs_src} -> {abs_dest}")
ctx.sys.run(["docker", "run", "--rm", "-v", f"{src_dir}:/data", "-v", f"{abs_dest}:/output",
"ldez/traefik-certs-dumper:v2.9.3", "file", "--version", "v3",
"--source", f"/data/{src_file}", "--dest", "/output", "--domain-subdir=true",
@@ -1,6 +1,7 @@
# actions/utils/generate-happ-subscriptions.py
"""Port of utils/generate-happ-subscriptions — build + run the happ generator image."""
import os
import shutil
from engine.descriptor import Meta, Arg
METADATA = Meta(summary="Generate .psub files from a JSON config via the happ generator (docker).",
@@ -11,6 +12,16 @@ def run(ctx, args):
log = ctx.log
src_dir = os.path.join(ctx.paths.commons, "source", "happ-subscription-generator")
inp, out = os.path.realpath(args.input_json), os.path.realpath(args.output_dir)
# GNU realpath (bash) fails unless all but the last component exist — without this
# guard a mistyped path reaches `docker run -v`, which creates it root-owned.
for label, p in (("input_json", inp), ("output_dir", out)):
parent = os.path.dirname(p)
if not os.path.isdir(parent):
log.error(f"Cannot resolve {label}: no such directory: {parent}")
raise SystemExit(1)
if not shutil.which("docker"):
log.error("docker is not installed or not in PATH.")
raise SystemExit(1)
log.info(f"Building {IMAGE}...")
ctx.sys.run(["docker", "build", "-t", IMAGE, src_dir], check=True)
log.info(f"Running generator: {inp} -> {out}")
+12 -2
View File
@@ -50,12 +50,22 @@ def _validate_anchor_ips(ctx) -> int:
f = os.path.join(comp, proj, "docker-compose.yml")
if not os.path.isfile(f):
continue
for m in re.finditer(r"ipv4_address:\s*([0-9.]+)", open(f).read()):
try:
text = open(f).read()
except OSError as e:
ctx.log.error(f"Cannot read {f}: {e}"); rc = 1
continue
for m in re.finditer(r"ipv4_address:\s*([0-9.]+)", text):
ip = m.group(1)
try:
addr = ipaddress.ip_address(ip)
except ValueError: # e.g. "10.0.0." — a lint error, not a crash
ctx.log.error(f"Malformed anchor IP {ip!r} in {proj}"); rc = 1
continue
if ip in seen:
ctx.log.error(f"Duplicate anchor IP {ip} in {proj} and {seen[ip]}"); rc = 1
seen[ip] = proj
if subnet is not None and ipaddress.ip_address(ip) not in subnet:
if subnet is not None and addr not in subnet:
ctx.log.error(f"Anchor IP {ip} ({proj}) not in node subnet {subnet}"); rc = 1
if rc == 0:
ctx.log.info("Anchor IP validation passed.")