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.
36 lines
2.1 KiB
Python
36 lines
2.1 KiB
Python
# actions/utils/extract-traefik-certs.py
|
|
"""Port of utils/extract-traefik-certs — dump traefik v3 acme.json to pem via docker."""
|
|
import os
|
|
from engine.descriptor import Meta, Arg
|
|
|
|
METADATA = Meta(summary="Extract Traefik v3 acme.json certs into fullchain.pem/privkey.pem (via docker).",
|
|
args=[Arg("source_acme", "path to acme.json"),
|
|
Arg("dest_dir", "destination directory"),
|
|
Arg("telegram_bot_url", "(optional) Telegram Bot URL", required=False)])
|
|
TITLE = "Traefik Cert Extraction"
|
|
|
|
def run(ctx, args):
|
|
log, node, url = ctx.log, ctx.node.name, args.telegram_bot_url
|
|
if not os.path.isfile(args.source_acme):
|
|
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)
|
|
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",
|
|
"--crt-name=fullchain", "--crt-ext=.pem", "--key-name=privkey", "--key-ext=.pem"],
|
|
check=True)
|
|
log.info("Setting secure permissions (600) on extracted keys...")
|
|
ctx.sys.sudo(["find", abs_dest, "-type", "f", "-name", "*.pem", "-exec", "chmod", "600", "{}", "+"])
|
|
ctx.sys.sudo(["chown", "-R", f"{os.getuid()}:{os.getgid()}", abs_dest])
|
|
log.success("Certificates extracted.")
|
|
ctx.notify.success(TITLE, url, f"Certificates extracted for {node}", node)
|
|
except Exception as e:
|
|
log.error(str(e)); ctx.notify.error(TITLE, url, f"cert extraction failed: {e}", node)
|
|
raise SystemExit(1)
|