lab7: безопасность, mTLS, OpenBao и PKI lifecycle

This commit is contained in:
Vladislav Kunetskiy
2026-11-10 10:58:07 +03:00
parent 3d216fbd50
commit 3441f2269a
183 changed files with 216667 additions and 3165 deletions
+11 -16
View File
@@ -19,6 +19,8 @@ import urllib.request
import uuid
from pathlib import Path
from lab7_http import BASE_URL, CA_FILE, open_url, grafana_password
# The lab tools always target loopback; ignore ambient corporate proxies.
for _proxy_key in ('HTTP_PROXY', 'HTTPS_PROXY', 'ALL_PROXY', 'http_proxy', 'https_proxy', 'all_proxy'):
os.environ.pop(_proxy_key, None)
@@ -36,7 +38,7 @@ def request(url, auth=None, timeout=10):
if auth:
headers['Authorization'] = 'Basic ' + base64.b64encode(auth.encode()).decode()
req = urllib.request.Request(url, headers=headers)
with urllib.request.urlopen(req, timeout=timeout) as response:
with open_url(req, timeout=timeout, operator=True) as response:
return response.status, response.read()
@@ -58,14 +60,6 @@ def loki_query(base, query, start_ns, end_ns, limit=20):
return json.loads(raw).get('data', {}).get('result', [])
def grafana_password():
path = ROOT / 'secrets/grafana.env'
if not path.exists():
return None
for line in path.read_text().splitlines():
if '=' in line and line.split('=', 1)[0].strip() == 'GF_SECURITY_ADMIN_PASSWORD':
return line.split('=', 1)[1].strip()
return None
def wait_for(fn, attempts=30, delay=2):
@@ -85,11 +79,12 @@ def wait_for(fn, attempts=30, delay=2):
def main():
parser = argparse.ArgumentParser(description='Strict lab6 telemetry gate')
parser.add_argument('--base-url', default='http://localhost:8080')
parser.add_argument('--prometheus', default='http://localhost:9090')
parser.add_argument('--loki', default='http://localhost:3100')
parser.add_argument('--tempo', default='http://localhost:3200')
parser.add_argument('--grafana', default='http://localhost:3000')
parser.add_argument('--base-url', default=BASE_URL)
parser.add_argument('--ca-file', default=CA_FILE)
parser.add_argument('--prometheus', default='https://localhost:9090')
parser.add_argument('--loki', default='https://localhost:3100')
parser.add_argument('--tempo', default='https://localhost:3200')
parser.add_argument('--grafana', default='https://localhost:3000')
parser.add_argument('--wait-seconds', type=int, default=60)
args = parser.parse_args()
failures = []
@@ -98,7 +93,7 @@ def main():
# 1. Generate a controlled request, a message and a job.
sys.path.insert(0, str(ROOT / 'tests'))
from client import Client
client = Client(args.base_url, timeout=15)
client = Client(args.base_url, args.ca_file, timeout=15)
alice, _, _, chat = client.bootstrap()
request_id = 'lab6-verify-' + uuid.uuid4().hex
sentinel = 'SENTINEL-TELEMETRY-' + uuid.uuid4().hex
@@ -274,7 +269,7 @@ def main():
try:
password = grafana_password()
if not password:
failures.append('Grafana admin secret is missing (secrets/grafana.env)')
failures.append('Grafana operator secret is missing (secrets/lab7/backends/credentials.json)')
else:
_, raw = request(args.grafana.rstrip('/') + '/api/health')
if json.loads(raw).get('database') != 'ok':