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')
|
||||
@@ -0,0 +1,29 @@
|
||||
"""Inspect actual container privileges, mounts, published ports and limits."""
|
||||
import json
|
||||
import subprocess
|
||||
|
||||
ids = subprocess.check_output(['docker','compose','ps','-q'], text=True).split()
|
||||
assert ids, 'stack not running'
|
||||
containers = json.loads(subprocess.check_output(['docker','inspect',*ids], text=True))
|
||||
seen = set()
|
||||
for c in containers:
|
||||
role=c['Config']['Labels']['com.docker.compose.service']
|
||||
seen.add(role)
|
||||
host=c['HostConfig']
|
||||
assert not host['Privileged'], role
|
||||
assert host['NetworkMode'] != 'host', role
|
||||
assert host['Memory'] > 0 and host['NanoCpus'] > 0, role
|
||||
for mount in c['Mounts']:
|
||||
assert 'docker.sock' not in mount['Source'] and 'docker.sock' not in mount['Destination'], role
|
||||
assert not mount['Source'].endswith(('/ca.key','/openbao-operator.json')), role
|
||||
for ports in (c['NetworkSettings'].get('Ports') or {}).values():
|
||||
for port in ports or []:
|
||||
assert role in {'load_balancer','openbao','grafana'}, role
|
||||
assert port['HostIp']=='127.0.0.1', role
|
||||
if role in {'api-a','api-b','worker'}:
|
||||
assert c['Config']['User'].split(':')[0] not in {'','0','root'}, role
|
||||
assert 'ALL' in host['CapDrop'], role
|
||||
assert not host['CapAdd'], role
|
||||
assert 'no-new-privileges:true' in host['SecurityOpt'], role
|
||||
assert {'api-a','api-b','worker','load_balancer'} <= seen
|
||||
print('PASS runtime: scoped ports, no privileged/host/socket/operator keys; resource limits; non-root app/worker')
|
||||
@@ -1,5 +1,10 @@
|
||||
"""Check allowed and denied S3 prefixes using the current service identity."""
|
||||
import json
|
||||
import http.client
|
||||
import urllib.parse
|
||||
from botocore.auth import S3SigV4Auth
|
||||
from botocore.awsrequest import AWSRequest
|
||||
from botocore.credentials import Credentials
|
||||
import os
|
||||
import ssl
|
||||
import urllib.request
|
||||
@@ -38,3 +43,24 @@ else:
|
||||
finally:
|
||||
client.close()
|
||||
print(f'PASS {role}: allowed staging write; forbidden prefix denied')
|
||||
|
||||
# Repeated Authorization fields must fail even for an otherwise allowed read.
|
||||
endpoint = urllib.parse.urlsplit(os.environ['S3_ENDPOINT'])
|
||||
path = '/' + bucket + '/' + allowed
|
||||
req = AWSRequest(method='GET', url=os.environ['S3_ENDPOINT'] + path)
|
||||
S3SigV4Auth(Credentials(values['S3_ACCESS_KEY_ID'], values['S3_SECRET_ACCESS_KEY']),
|
||||
's3', 'us-east-1').add_auth(req)
|
||||
conn = http.client.HTTPSConnection(endpoint.hostname, endpoint.port,
|
||||
context=ssl.create_default_context(cafile=os.environ['AWS_CA_BUNDLE']), timeout=10)
|
||||
try:
|
||||
conn.putrequest('GET', path)
|
||||
for key, value in req.headers.items():
|
||||
conn.putheader(key, value)
|
||||
conn.putheader('Authorization', req.headers['Authorization'])
|
||||
conn.endheaders()
|
||||
response = conn.getresponse()
|
||||
assert response.status == 403, 'duplicate Authorization not denied'
|
||||
response.read()
|
||||
finally:
|
||||
conn.close()
|
||||
print(f'PASS {role}: duplicate Authorization denied')
|
||||
|
||||
@@ -0,0 +1,35 @@
|
||||
"""Linux DAC regression; run as root in a disposable container with synthetic data."""
|
||||
import os
|
||||
from pathlib import Path
|
||||
import subprocess
|
||||
import sys
|
||||
import tempfile
|
||||
|
||||
with tempfile.TemporaryDirectory() as directory:
|
||||
root = Path(directory)
|
||||
root.chmod(0o755)
|
||||
mounted = root / 'mounted'
|
||||
mounted.write_text('synthetic-secret')
|
||||
os.chown(mounted, 1000, 12345)
|
||||
mounted.chmod(0o640)
|
||||
host = root / 'operator'
|
||||
host.mkdir(mode=0o700)
|
||||
os.chown(host, 1000, 12345)
|
||||
protected = host / 'secret'
|
||||
protected.write_text('synthetic-secret')
|
||||
os.chown(protected, 1000, 12345)
|
||||
protected.chmod(0o640)
|
||||
def can_read(path, groups):
|
||||
def identity():
|
||||
os.setgroups(groups)
|
||||
os.setgid(65534)
|
||||
os.setuid(65534)
|
||||
return subprocess.run([sys.executable, '-c',
|
||||
'from pathlib import Path; import sys; Path(sys.argv[1]).read_bytes()', str(path)],
|
||||
preexec_fn=identity, stdout=subprocess.DEVNULL, stderr=subprocess.DEVNULL).returncode == 0
|
||||
assert not can_read(mounted, [])
|
||||
assert can_read(mounted, [12345])
|
||||
assert not can_read(protected, [12345])
|
||||
mounted.chmod(0o600)
|
||||
assert not can_read(mounted, [12345])
|
||||
print('PASS Linux DAC: original failure reproduced; group access works; host directory protected')
|
||||
Reference in New Issue
Block a user