forked from mtusi2026/mtusi2026lab7
test(security): automate lifecycle and login budget measurements
This commit is contained in:
@@ -2,9 +2,11 @@
|
||||
|
||||
import argparse
|
||||
import json
|
||||
import subprocess
|
||||
from datetime import UTC, datetime
|
||||
|
||||
from scripts.bootstrap_security import (
|
||||
OPERATOR,
|
||||
SECRET,
|
||||
key_bytes,
|
||||
make_root,
|
||||
@@ -12,7 +14,8 @@ from scripts.bootstrap_security import (
|
||||
sign_leaf,
|
||||
write_private,
|
||||
)
|
||||
from scripts.stand import ROOT, command, compose
|
||||
from scripts.stand import ROOT, command
|
||||
from scripts.verify_clean import redact
|
||||
|
||||
|
||||
def main():
|
||||
@@ -32,23 +35,43 @@ def main():
|
||||
mode=0o644,
|
||||
)
|
||||
write_private(fixture / "foreign/key.pem", key_bytes(key), mode=0o644)
|
||||
result = json.loads(
|
||||
compose(
|
||||
for name in ["cert.pem", "key.pem"]:
|
||||
write_private(
|
||||
fixture / "operator" / name,
|
||||
(OPERATOR / "client" / name).read_bytes(),
|
||||
mode=0o644,
|
||||
)
|
||||
process = subprocess.run(
|
||||
[
|
||||
"docker",
|
||||
"compose",
|
||||
"--profile",
|
||||
"operator",
|
||||
"run",
|
||||
"--rm",
|
||||
"--no-deps",
|
||||
"operator-probe",
|
||||
)
|
||||
],
|
||||
cwd=ROOT,
|
||||
capture_output=True,
|
||||
text=True,
|
||||
)
|
||||
try:
|
||||
result = json.loads(process.stdout)
|
||||
except ValueError:
|
||||
result = {"complete": False}
|
||||
result["probe_exit_code"] = process.returncode
|
||||
if process.returncode:
|
||||
result["failure"] = redact(process.stderr, ROOT)
|
||||
result.update(
|
||||
date=datetime.now(UTC).isoformat(),
|
||||
source_commit=command(["git", "rev-parse", "HEAD"]),
|
||||
)
|
||||
output.parent.mkdir(parents=True, exist_ok=True)
|
||||
output.write_text(json.dumps(result, ensure_ascii=False, indent=2) + "\n")
|
||||
assert result["complete"]
|
||||
assert process.returncode == 0 and result["complete"], (
|
||||
"Security probe failed; see saved receipt"
|
||||
)
|
||||
print(
|
||||
"PASS: real mTLS identities, server CA/hostname, closed plaintext boundaries and worker least privilege"
|
||||
)
|
||||
|
||||
Reference in New Issue
Block a user