test(pki): measure phase errors and verify revocation before expiry
This commit is contained in:
@@ -197,6 +197,9 @@ def revoke(operator, leaf):
|
|||||||
TRUST / "revoked.json", json.dumps(revoked) + "\n", mode=0o644
|
TRUST / "revoked.json", json.dumps(revoked) + "\n", mode=0o644
|
||||||
)
|
)
|
||||||
fixture_check("revoked-lb", reject=True)
|
fixture_check("revoked-lb", reject=True)
|
||||||
|
assert leaf["expires_at"] > time.time(), (
|
||||||
|
"Revocation proof must precede natural expiry"
|
||||||
|
)
|
||||||
old_token = json.loads(
|
old_token = json.loads(
|
||||||
(SECRET / "probe/revoked-lb/secrets.json").read_text()
|
(SECRET / "probe/revoked-lb/secrets.json").read_text()
|
||||||
)["token"]
|
)["token"]
|
||||||
@@ -217,6 +220,9 @@ def revoke(operator, leaf):
|
|||||||
assert issue.status_code in {401, 403}, (
|
assert issue.status_code in {401, 403}, (
|
||||||
"Old service token could issue a replacement certificate"
|
"Old service token could issue a replacement certificate"
|
||||||
)
|
)
|
||||||
|
assert leaf["expires_at"] > time.time(), (
|
||||||
|
"Revocation checks must finish before natural expiry"
|
||||||
|
)
|
||||||
return {
|
return {
|
||||||
"revoked_serial": leaf["serial"],
|
"revoked_serial": leaf["serial"],
|
||||||
"still_unexpired_at_check": leaf["expires_at"] > time.time(),
|
"still_unexpired_at_check": leaf["expires_at"] > time.time(),
|
||||||
@@ -389,6 +395,10 @@ def rollover():
|
|||||||
fixture_check("retired-ca-lb")
|
fixture_check("retired-ca-lb")
|
||||||
# Allow old L4 connections to expire, then remove old trust everywhere.
|
# Allow old L4 connections to expire, then remove old trust everywhere.
|
||||||
time.sleep(46)
|
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"]:
|
for role in [*ROLES, "operator"]:
|
||||||
operator.authorized("DELETE", "auth/cert/certs/" + role + "-v1")
|
operator.authorized("DELETE", "auth/cert/certs/" + role + "-v1")
|
||||||
client_key, client_cert = sign_leaf(
|
client_key, client_cert = sign_leaf(
|
||||||
@@ -408,6 +418,9 @@ def rollover():
|
|||||||
operator.close()
|
operator.close()
|
||||||
reload_lb()
|
reload_lb()
|
||||||
reload_bao()
|
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("retired-ca-lb", reject=True)
|
||||||
fixture_check("lb")
|
fixture_check("lb")
|
||||||
journal["phase"] = "complete"
|
journal["phase"] = "complete"
|
||||||
@@ -419,6 +432,7 @@ def rollover():
|
|||||||
"old_l4_connections_waited_seconds": 46,
|
"old_l4_connections_waited_seconds": 46,
|
||||||
"old_ca_fixture_valid_during_dual_trust": True,
|
"old_ca_fixture_valid_during_dual_trust": True,
|
||||||
"old_ca_new_connection_denied_after_retirement": True,
|
"old_ca_new_connection_denied_after_retirement": True,
|
||||||
|
"old_ca_fixture_unexpired_at_retirement_check": True,
|
||||||
"services": metadata(),
|
"services": metadata(),
|
||||||
"image_rebuilt": False,
|
"image_rebuilt": False,
|
||||||
}
|
}
|
||||||
|
|||||||
@@ -3,6 +3,7 @@
|
|||||||
import argparse
|
import argparse
|
||||||
import csv
|
import csv
|
||||||
import json
|
import json
|
||||||
|
import math
|
||||||
import socket
|
import socket
|
||||||
import ssl
|
import ssl
|
||||||
import time
|
import time
|
||||||
@@ -165,6 +166,7 @@ def main():
|
|||||||
raise AssertionError(
|
raise AssertionError(
|
||||||
"Expired server certificate was accepted"
|
"Expired server certificate was accepted"
|
||||||
)
|
)
|
||||||
|
recovery_started_at = time.time()
|
||||||
recovery = time.monotonic()
|
recovery = time.monotonic()
|
||||||
operator = Operator()
|
operator = Operator()
|
||||||
try:
|
try:
|
||||||
@@ -178,6 +180,8 @@ def main():
|
|||||||
"leaf": leaf,
|
"leaf": leaf,
|
||||||
"waited_seconds": round(wait_seconds, 3),
|
"waited_seconds": round(wait_seconds, 3),
|
||||||
"expired_certificate_verified_denied": True,
|
"expired_certificate_verified_denied": True,
|
||||||
|
"recovery_started_at": recovery_started_at,
|
||||||
|
"recovery_ready_at": time.time(),
|
||||||
"recovery_seconds": round(time.monotonic() - recovery, 3),
|
"recovery_seconds": round(time.monotonic() - recovery, 3),
|
||||||
}
|
}
|
||||||
|
|
||||||
@@ -202,6 +206,7 @@ def main():
|
|||||||
)
|
)
|
||||||
except httpx.HTTPError as error:
|
except httpx.HTTPError as error:
|
||||||
error_type = type(error).__name__
|
error_type = type(error).__name__
|
||||||
|
recovery_started_at = time.time()
|
||||||
recovery = time.monotonic()
|
recovery = time.monotonic()
|
||||||
pki.recover_bao()
|
pki.recover_bao()
|
||||||
bao_sealed = False
|
bao_sealed = False
|
||||||
@@ -210,6 +215,8 @@ def main():
|
|||||||
"sealed_seconds": 70,
|
"sealed_seconds": 70,
|
||||||
"status_after_secret_expiry": status,
|
"status_after_secret_expiry": status,
|
||||||
"tls_transport_failure": error_type,
|
"tls_transport_failure": error_type,
|
||||||
|
"recovery_started_at": recovery_started_at,
|
||||||
|
"recovery_ready_at": time.time(),
|
||||||
"recovery_seconds": round(time.monotonic() - recovery, 3),
|
"recovery_seconds": round(time.monotonic() - recovery, 3),
|
||||||
"explicit_operator_recovery": True,
|
"explicit_operator_recovery": True,
|
||||||
}
|
}
|
||||||
@@ -325,11 +332,62 @@ def main():
|
|||||||
)
|
)
|
||||||
writer.writerows(load.requests)
|
writer.writerows(load.requests)
|
||||||
report["uploads"] = load.uploads
|
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()
|
save()
|
||||||
if lb_stopped:
|
try:
|
||||||
compose("up", "-d", "--no-deps", "identity-lb")
|
if bao_sealed:
|
||||||
if bao_sealed:
|
pki.recover_bao()
|
||||||
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(
|
print(
|
||||||
"PASS: measured renewal, working-key/leaf rotation, revocation, expiry, seal recovery and CA rollover"
|
"PASS: measured renewal, working-key/leaf rotation, revocation, expiry, seal recovery and CA rollover"
|
||||||
)
|
)
|
||||||
|
|||||||
Reference in New Issue
Block a user