Files
buryan-infra/ops/audit/tests/secret_scan.py
T
architect b3bb51f8ae
lint / hygiene (push) Failing after 22s
standard / check (push) Successful in 10s
lint / hygiene (pull_request) Failing after 24s
standard / check (pull_request) Successful in 10s
[ARCH] Add secret scanner for audit/docs (0 hits)
2026-11-26 22:03:15 +03:00

48 lines
1.3 KiB
Python

#!/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()