forked from mtusi2026/mtusi2026lab7
82 lines
2.4 KiB
Python
82 lines
2.4 KiB
Python
"""Prepare public/negative fixtures and run the operator-only matrix probe."""
|
|
|
|
import argparse
|
|
import json
|
|
import subprocess
|
|
from datetime import UTC, datetime
|
|
|
|
from scripts.bootstrap_security import (
|
|
OPERATOR,
|
|
SECRET,
|
|
key_bytes,
|
|
make_root,
|
|
public,
|
|
sign_leaf,
|
|
write_private,
|
|
)
|
|
from scripts.stand import ROOT, command
|
|
from scripts.verify_clean import redact
|
|
|
|
|
|
def main():
|
|
parser = argparse.ArgumentParser(description=__doc__)
|
|
parser.add_argument("--output", default="evidence/security-first.json")
|
|
args = parser.parse_args()
|
|
output = ROOT / args.output
|
|
assert not output.exists(), "Choose a new receipt path"
|
|
fixture = SECRET / "probe"
|
|
fixture.mkdir(mode=0o755, exist_ok=True)
|
|
root_key, root_cert = make_root()
|
|
key, leaf = sign_leaf(root_key, root_cert, "lb", ["lb"])
|
|
write_private(fixture / "foreign-ca.pem", public(root_cert), mode=0o644)
|
|
write_private(
|
|
fixture / "foreign/cert.pem",
|
|
public(leaf) + public(root_cert),
|
|
mode=0o644,
|
|
)
|
|
write_private(fixture / "foreign/key.pem", key_bytes(key), mode=0o644)
|
|
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 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"
|
|
)
|
|
|
|
|
|
if __name__ == "__main__":
|
|
main()
|