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

+11 -7
View File
@@ -22,9 +22,11 @@ def _env_val(path, key):
def run(ctx, args):
log, s = ctx.log, ctx.sys
comp = ctx.paths.compositions
tiers = [os.path.realpath(args.tier1_path or ctx.paths.tier1),
os.path.realpath(args.tier2_path or ctx.paths.tier2),
os.path.realpath(args.tier3_path or ctx.paths.tier3)]
# Defaults are the TIER ROOTS (compositions/@tierN, bash $ROOT_TIERn) — NOT
# ctx.paths.tierN, which is the apex core project's data dir one level deeper.
tiers = [os.path.realpath(args.tier1_path or ctx.paths.root_tier1),
os.path.realpath(args.tier2_path or ctx.paths.root_tier2),
os.path.realpath(args.tier3_path or ctx.paths.root_tier3)]
cp = s.run(["getent", "group", SHARED_GROUP], check=False, capture=True)
if cp.returncode != 0:
@@ -33,10 +35,12 @@ def run(ctx, args):
log.info("Ensuring base structures owned by root...")
for tp in tiers:
s.sudo(["chown", "root:root", tp])
for sub in ("shared", "node-infra"):
p = os.path.join(tp, sub)
if os.path.isdir(p):
s.sudo(["chown", "-R", "root:root", p])
shared = os.path.join(tp, "shared")
if os.path.isdir(shared): # dir inode only — recursing would clobber
s.sudo(["chown", "root:root", shared]) # skipped projects' shared subtrees
infra = os.path.join(tp, "node-infra")
if os.path.isdir(infra):
s.sudo(["chown", "-R", "root:root", infra])
for proj in sorted(os.listdir(comp)):
full = os.path.join(comp, proj)
+4 -1
View File
@@ -16,7 +16,10 @@ def run(ctx, args):
os.path.realpath(args.tier3_path)]
def confirm(msg):
return input(f"{msg} [y/N]: ").strip().lower() in ("y", "yes")
try:
return input(f"{msg} [y/N]: ").strip().lower() in ("y", "yes")
except EOFError: # non-interactive stdin = decline, like bash `read` at EOF
return False
def safe_remove(link, desc):
if os.path.islink(link):
+3 -1
View File
@@ -70,5 +70,7 @@ def _inject_env(ctx, env_path, uid, gid, shared_gid):
new = re.sub(re.escape(START) + r".*?" + re.escape(END) + r"\n", block, text, flags=re.S)
else:
new = block + "\n" + text
ctx.host.write_file(actual, new, backup=True, sudo=True)
# backup=False: bash never left copies; a timestamped .bak would pile up a
# secret-bearing .env duplicate per run next to the bind-mounted project dir.
ctx.host.write_file(actual, new, backup=False, sudo=True)
ctx.log.success(f"Updated {actual} with APEX_UID/GID/SHARED_GID")