feat: implement pki-ingress-mtls

Local CA script, HTTPS ingress on :8443, mandatory mTLS LB -> API
with an identity allowlist, separate health listener, random
X-Instance-Id alias; tests, hooks and driver over HTTPS.

Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com>
This commit is contained in:
2026-11-16 11:38:32 +03:00
co-authored by Claude Opus 5.5
parent fef97b39ae
commit 50cb54f0a1
13 changed files with 549 additions and 71 deletions
+53 -16
View File
@@ -576,7 +576,13 @@ def cmd_start(port: int) -> int:
# Valkey работает, но мимо кэша; без S3 — 503 на путях вложений; без
# брокера загрузка — 202, задание ждёт в PostgreSQL
# pki_stand — файлы PKI стенда (identity ingress для HTTPS консоли)
targets = ["pki_stand", "upgrade", "start_cache", "start_s3", "start_broker"]
targets = [
"pki_stand",
"upgrade",
"start_cache",
"start_s3",
"start_broker",
]
upgrade = subprocess.run(
["make", *targets],
cwd=ROOT,
@@ -12827,11 +12833,16 @@ def cmd_stand_from_scratch(
)
def stand_pki_digest() -> str:
# отпечатки файлов PKI рабочего стенда: прогон их не трогает
# отпечатки файлов PKI рабочего стенда: прогон их не трогает. CRL
# не в счёт: make run_docker без --fresh-pki зовёт pki_stand того же
# каталога, а он по design (решение 1) выпускает CRL заново всегда;
# ca.crt, сертификаты и ключи leaf остаются прежними
stand = pki_stand_dir()
return hashlib.sha256(
b"".join(
p.read_bytes() for p in sorted(stand.glob("*")) if p.is_file()
p.read_bytes()
for p in sorted(stand.glob("*"))
if p.is_file() and p.name != "crl.pem"
),
).hexdigest()
@@ -12852,7 +12863,9 @@ def cmd_stand_from_scratch(
"PKI_STAND_DIR": str(pki_dir / "stand"),
}
try:
rows.extend(scratch_run(project, run, run_env, scratch, pki_dir))
rows.extend(
scratch_run(project, run, run_env, scratch, pki_dir),
)
finally:
remove()
if pki_dir is not None:
@@ -12887,7 +12900,7 @@ def cmd_stand_from_scratch(
)
rows.append(
(
f"working stand {working}: PKI files unchanged",
f"working stand {working}: PKI files unchanged (but CRL)",
"yes",
yes(stand_pki_digest() == pki_before),
),
@@ -15461,7 +15474,9 @@ def mc_networks(container: str) -> dict[str, str]:
nets = json.loads(raw or "{}")
except json.JSONDecodeError:
return {}
return {name: str(item.get("IPAddress", "")) for name, item in nets.items()}
return {
name: str(item.get("IPAddress", "")) for name, item in nets.items()
}
def mc_pki(args: list[str], env: dict[str, str]) -> None:
@@ -15527,15 +15542,18 @@ def mc_probe(
def mc_describe(result: dict[str, object]) -> str:
if result.get("outcome") == "http":
return f"HTTP {result.get('status')} {result.get('version', '')}".strip()
return (
f"HTTP {result.get('status')} {result.get('version', '')}".strip()
)
return f"no HTTP ({result.get('outcome')}: {result.get('detail', '')})"
def mc_wait_healthy(container: str) -> bool:
return bool(
poll(
lambda: mc_inspect(container, "{{.State.Health.Status}}")
== "healthy",
lambda: (
mc_inspect(container, "{{.State.Health.Status}}") == "healthy"
),
timeout=MC_READY_S,
interval=1,
),
@@ -15553,7 +15571,9 @@ def cmd_mtls_check(port: int) -> int:
replicas = service_ids("api")
lbs = service_ids("haproxy")
if not replicas or not lbs:
print("mtls-check: no running api replicas or haproxy: start the stand")
print(
"mtls-check: no running api replicas or haproxy: start the stand",
)
return 2
image = mc_inspect(replicas[0], "{{.Config.Image}}")
shared = set(mc_networks(lbs[0])) & set(mc_networks(replicas[0]))
@@ -15749,10 +15769,22 @@ def mtls_check(
yes(bool(rejected)),
),
)
rows.extend(mc_foreign(port, image, network, api_port, project, tag, label,
material, {a for _, a in targets.values()}))
rows.extend(mc_control(image, network, api_port, project, tag, label,
material))
rows.extend(
mc_foreign(
port,
image,
network,
api_port,
project,
tag,
label,
material,
{a for _, a in targets.values()},
),
)
rows.extend(
mc_control(image, network, api_port, project, tag, label, material),
)
return report_reconcile(
rows,
passed="replicas accept only the haproxy identity of the stand CA; a "
@@ -15899,8 +15931,13 @@ def mc_control(
timeout=120,
)
healthy = code == 0 and mc_wait_healthy(name)
rows = [("control replica (allowlist with the probe) healthy", "yes",
yes(healthy))]
rows = [
(
"control replica (allowlist with the probe) healthy",
"yes",
yes(healthy),
),
]
if not healthy:
print(out[-300:])
return rows