Drop the hardcoded-domain FQDN regex and every hardcoded domain from commons. Node identity is now explicit in node.env: APEX_NODE_FQDN (real FQDN, traefik Host()), APEX_NODE_HOST (public host name — backup --host, obs/notify instance), APEX_SUBNET. The short name (log prefix, sync/<node> branch, messages) is derived as the first host label. notify instance is just the host (no hardcoded prefix); the git bot identity moves to APEX_GIT_AUTHOR_NAME/EMAIL (node.env) with generic defaults. Alloy node+instance labels use APEX_NODE_HOST. Fallbacks keep a node working if it omits a var (host<-fqdn<-hostname). BREAKING CHANGE: removes APEX_NODE and APEX_CLUSTER env vars; node name is now derived from APEX_NODE_FQDN
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}")
|
|
except Exception as e:
|
|
log.error(str(e)); ctx.notify.error(TITLE, url, f"cert extraction failed: {e}")
|
|
raise SystemExit(1)
|