"""lab7: TLS/mTLS-аудит всей trust matrix (contracts/trust-matrix.md) изнутри внутренних сетей. python student-tests/test_tls_matrix.py [группа ...] # группы: lb-api broker collector postgres redis s3 # openbao telemetry (по умолчанию все) Запускает student-tests/tls_probe.py в одноразовом контейнере probe (compose profile tools): он во всех внутренних сетях, но без ключа CA, паролей и токенов. Результат — таблица и evidence/tls-matrix.json. """ import json import subprocess import sys from common import EVIDENCE, ROOT, check def main(): groups = sys.argv[1:] result = subprocess.run(["docker", "compose", "--profile", "tools", "run", "--rm", "-T", "probe", "python", "/probe/tls_probe.py", "matrix", *groups], cwd=ROOT, capture_output=True, check=False) rows, summary = [], None for line in result.stdout.decode("utf-8", "replace").splitlines(): try: item = json.loads(line) except ValueError: continue if item.get("summary"): summary = item else: rows.append(item) check(summary is not None, "probe did not finish: " + result.stderr.decode("utf-8", "replace")[-600:]) link = None for row in rows: if row["link"] != link: link = row["link"] print(f"\n{link}") mark = "PASS" if row["pass"] else "FAIL" print(f" {mark} {row['case']:<58} -> {row['observed']}" + ("" if row["pass"] else f" (expected {row['expect']}; {row['detail'][:120]})")) out = EVIDENCE / "tls-matrix.json" out.write_text(json.dumps({"summary": summary, "checks": rows}, ensure_ascii=False, indent=1), encoding="utf-8") print(f"\n{summary['checks']} checks, {summary['failed']} failed; saved to {out}") check(summary["failed"] == 0, "trust matrix has failed checks") print("PASS: every link of the trust matrix accepts the allowed identity and rejects the rest") if __name__ == "__main__": try: main() except AssertionError as exc: print(f"FAIL: {exc}") raise SystemExit(1)