test(pki): measure phase errors and verify revocation before expiry

This commit is contained in:
2026-11-20 20:24:57 +03:00
parent 82f02a020f
commit 33b8de003b
2 changed files with 76 additions and 4 deletions
+14
View File
@@ -197,6 +197,9 @@ def revoke(operator, leaf):
TRUST / "revoked.json", json.dumps(revoked) + "\n", mode=0o644
)
fixture_check("revoked-lb", reject=True)
assert leaf["expires_at"] > time.time(), (
"Revocation proof must precede natural expiry"
)
old_token = json.loads(
(SECRET / "probe/revoked-lb/secrets.json").read_text()
)["token"]
@@ -217,6 +220,9 @@ def revoke(operator, leaf):
assert issue.status_code in {401, 403}, (
"Old service token could issue a replacement certificate"
)
assert leaf["expires_at"] > time.time(), (
"Revocation checks must finish before natural expiry"
)
return {
"revoked_serial": leaf["serial"],
"still_unexpired_at_check": leaf["expires_at"] > time.time(),
@@ -389,6 +395,10 @@ def rollover():
fixture_check("retired-ca-lb")
# Allow old L4 connections to expire, then remove old trust everywhere.
time.sleep(46)
# Keep the native Bao listener and LB well within their TTL across
# the explicit listener restarts needed to retire client CA trust.
repair(operator, "openbao")
repair(operator, "lb")
for role in [*ROLES, "operator"]:
operator.authorized("DELETE", "auth/cert/certs/" + role + "-v1")
client_key, client_cert = sign_leaf(
@@ -408,6 +418,9 @@ def rollover():
operator.close()
reload_lb()
reload_bao()
assert fixture.not_valid_after_utc.timestamp() > time.time(), (
"CA retirement must be proved with an unexpired old-CA certificate"
)
fixture_check("retired-ca-lb", reject=True)
fixture_check("lb")
journal["phase"] = "complete"
@@ -419,6 +432,7 @@ def rollover():
"old_l4_connections_waited_seconds": 46,
"old_ca_fixture_valid_during_dual_trust": True,
"old_ca_new_connection_denied_after_retirement": True,
"old_ca_fixture_unexpired_at_retirement_check": True,
"services": metadata(),
"image_rebuilt": False,
}
+62 -4
View File
@@ -3,6 +3,7 @@
import argparse
import csv
import json
import math
import socket
import ssl
import time
@@ -165,6 +166,7 @@ def main():
raise AssertionError(
"Expired server certificate was accepted"
)
recovery_started_at = time.time()
recovery = time.monotonic()
operator = Operator()
try:
@@ -178,6 +180,8 @@ def main():
"leaf": leaf,
"waited_seconds": round(wait_seconds, 3),
"expired_certificate_verified_denied": True,
"recovery_started_at": recovery_started_at,
"recovery_ready_at": time.time(),
"recovery_seconds": round(time.monotonic() - recovery, 3),
}
@@ -202,6 +206,7 @@ def main():
)
except httpx.HTTPError as error:
error_type = type(error).__name__
recovery_started_at = time.time()
recovery = time.monotonic()
pki.recover_bao()
bao_sealed = False
@@ -210,6 +215,8 @@ def main():
"sealed_seconds": 70,
"status_after_secret_expiry": status,
"tls_transport_failure": error_type,
"recovery_started_at": recovery_started_at,
"recovery_ready_at": time.time(),
"recovery_seconds": round(time.monotonic() - recovery, 3),
"explicit_operator_recovery": True,
}
@@ -325,11 +332,62 @@ def main():
)
writer.writerows(load.requests)
report["uploads"] = load.uploads
if load is not None:
for entry in report["phases"]:
ended = entry.get("ended_at", time.time())
rows = [
r
for r in load.requests
if entry["started_at"] <= r[0] < ended
]
latencies = sorted(r[3] for r in rows if r[2] == 201)
entry["measured_requests"] = {
"count": len(rows),
"statuses": dict(Counter(str(r[2]) for r in rows)),
"failed_http_or_transport": sum(
r[2] not in {201, -1} for r in rows
),
"client_backpressure_drops": sum(
r[2] == -1 for r in rows
),
"successful_p95_seconds": latencies[
math.ceil(0.95 * len(latencies)) - 1
]
if latencies
else None,
}
result = entry.get("result")
if (
isinstance(result, dict)
and "recovery_started_at" in result
):
recovery = result["recovery_started_at"]
ends = [
r[0] + r[3]
for r in load.requests
if r[2] == 201 and r[0] >= recovery
]
result[
"first_observed_business_write_after_recovery_start_seconds"
] = round(min(ends) - recovery, 6) if ends else None
save()
if lb_stopped:
compose("up", "-d", "--no-deps", "identity-lb")
if bao_sealed:
pki.recover_bao()
try:
if bao_sealed:
pki.recover_bao()
if lb_stopped:
operator = Operator()
try:
repair(operator, "lb")
finally:
operator.close()
compose("up", "-d", "--no-deps", "identity-lb")
except Exception as cleanup_error:
report["recovery_cleanup_error_type"] = type(
cleanup_error
).__name__
save()
if report["complete"]:
raise
print(
"PASS: measured renewal, working-key/leaf rotation, revocation, expiry, seal recovery and CA rollover"
)