From b3bb51f8ae0125c657c5cdb6f8eb8d01c5e25c2f Mon Sep 17 00:00:00 2001 From: architect Date: Thu, 26 Nov 2026 22:03:15 +0300 Subject: [PATCH] [ARCH] Add secret scanner for audit/docs (0 hits) --- ops/audit/tests/secret_scan.py | 47 ++++++++++++++++++++++++++++++++++ 1 file changed, 47 insertions(+) create mode 100644 ops/audit/tests/secret_scan.py diff --git a/ops/audit/tests/secret_scan.py b/ops/audit/tests/secret_scan.py new file mode 100644 index 0000000..9b35f91 --- /dev/null +++ b/ops/audit/tests/secret_scan.py @@ -0,0 +1,47 @@ +#!/usr/bin/env python3 +"""Scan audit exports and repo docs for key-like material; print paths only.""" +import argparse +import re +import subprocess +from pathlib import Path + +PATTERNS = [ + re.compile(r"sk-[A-Za-z0-9]{20,}"), + re.compile(r"ghp_[A-Za-z0-9]{20,}"), + re.compile(r"AIza[0-9A-Za-z_-]{20,}"), + re.compile(r"-----BEGIN (RSA|OPENSSH|PRIVATE) KEY-----"), + re.compile(r"xox[baprs]-[A-Za-z0-9-]{10,}"), +] + + +def scan(path: Path): + try: + text = path.read_text(errors="ignore") + except OSError: + return False + return any(p.search(text) for p in PATTERNS) + + +def main(): + ap = argparse.ArgumentParser() + ap.add_argument("paths", nargs="*", default=["ops/audit", "docs"]) + args = ap.parse_args() + root = Path("/root/buryan-infra") + hits = [] + for raw in args.paths: + base = root / raw + if base.is_file(): + files = [base] + else: + files = [p for p in base.rglob("*") if p.is_file() and p.suffix.lower() in (".md", ".txt", ".json", ".yaml", ".yml", ".sh", ".py")] + for p in files: + if scan(p): + hits.append(str(p.relative_to(root))) + for h in hits: + print(h) + print("hits=%d" % len(hits)) + raise SystemExit(1 if hits else 0) + + +if __name__ == "__main__": + main()