This commit is contained in:
@@ -0,0 +1,35 @@
|
||||
"""Check that request-controlled secrets are absent from actual access logs."""
|
||||
from datetime import datetime, timezone
|
||||
import os
|
||||
from pathlib import Path
|
||||
import ssl
|
||||
import subprocess
|
||||
import time
|
||||
import urllib.error
|
||||
import urllib.request
|
||||
from uuid import uuid4
|
||||
|
||||
root = Path(__file__).resolve().parents[1]
|
||||
ctx = ssl.create_default_context(cafile=str(root / 'secrets/ca.crt'))
|
||||
base = os.environ.get('BASE_URL', 'https://localhost:8443').rstrip('/')
|
||||
marker = 'audit-private-' + uuid4().hex
|
||||
since = datetime.now(timezone.utc).isoformat()
|
||||
for path in ('/health/ready?token=' + marker, '/missing/' + marker):
|
||||
request = urllib.request.Request(base + path, headers={
|
||||
'Authorization': 'Bearer ' + marker, 'X-Request-Id': marker})
|
||||
try:
|
||||
with urllib.request.urlopen(request, context=ctx, timeout=10) as response:
|
||||
response.read()
|
||||
except urllib.error.HTTPError as error:
|
||||
assert error.code == 404
|
||||
error.read()
|
||||
for attempt in range(20):
|
||||
logs = subprocess.check_output(['docker', 'compose', 'logs', '--since', since,
|
||||
'load_balancer', 'api-a', 'api-b'], cwd=root, text=True)
|
||||
assert marker not in logs, 'request secret leaked into container logs'
|
||||
if 'ingress status=200' in logs and 'ingress status=404' in logs and 'http.request' in logs:
|
||||
break
|
||||
time.sleep(0.25)
|
||||
else:
|
||||
raise AssertionError('missing positive evidence of access logging')
|
||||
print('PASS: ingress/API access records present; query, path and header markers absent')
|
||||
Reference in New Issue
Block a user