forked from mtusi2026/mtusi2026lab7
25 lines
1.1 KiB
Python
25 lines
1.1 KiB
Python
#!/usr/bin/env python3
|
|
"""Check publishable files against actual local secret values without printing them."""
|
|
import json
|
|
from pathlib import Path
|
|
import subprocess
|
|
values=[]
|
|
def collect(x):
|
|
if isinstance(x,dict):
|
|
for v in x.values(): collect(v)
|
|
elif isinstance(x,list):
|
|
for v in x: collect(v)
|
|
elif isinstance(x,str) and len(x)>=20: values.append(x.encode())
|
|
for p in ('operator/credentials.json','operator/bao-init.json'):
|
|
collect(json.loads(Path(p).read_text()))
|
|
files=subprocess.check_output(['git','ls-files','--cached','--others','--exclude-standard'],text=True).splitlines()
|
|
for file in files:
|
|
p=Path(file)
|
|
if not p.is_file(): continue
|
|
data=p.read_bytes()
|
|
assert not any(v in data for v in values), 'secret value in '+file
|
|
# Split literals avoid scanner matching its own source code.
|
|
for marker in (b'-----BEGIN '+b'PRIVATE KEY-----',b'-----BEGIN RSA '+b'PRIVATE KEY-----'):
|
|
assert marker not in data,'private key in '+file
|
|
print('PASS no generated credential/root/unseal values or private keys in publishable files')
|