lab7: mTLS-границы, OpenBao raft, TLS-телеметрия, evidence уровней 3-4

This commit is contained in:
2026-11-27 23:05:20 +03:00
parent 6b44b067c4
commit cf6b78f899
31 changed files with 572 additions and 116 deletions
+18 -6
View File
@@ -69,17 +69,22 @@ def http(method, path, body=None, headers=None, token=None, base=None, ca=None,
for key, value in (headers or {}).items():
request.add_header(key, value)
context = ssl.create_default_context(cafile=ca or CA_PUBLIC)
# h11/uvicorn отдают имена заголовков в нижнем регистре; dict() сделал бы
# поиск регистрозависимым, поэтому нормализуем ключи сами.
def _headers(message):
return {key.lower(): value for key, value in message.items()}
try:
with urllib.request.urlopen(request, timeout=timeout, context=context) as resp:
raw = resp.read()
return resp.status, dict(resp.headers), json.loads(raw) if raw else None
return resp.status, _headers(resp.headers), json.loads(raw) if raw else None
except urllib.error.HTTPError as exc:
raw = exc.read()
try:
parsed = json.loads(raw) if raw else None
except ValueError:
parsed = None
return exc.code, dict(exc.headers), parsed
return exc.code, _headers(exc.headers), parsed
def new_user(prefix="probe"):
@@ -145,6 +150,9 @@ def hostname_probe():
except ssl.SSLCertVerificationError as exc:
return "cert_error:" + (exc.verify_message or type(exc).__name__)
except urllib.error.URLError as exc:
# urlopen оборачивает ошибку проверки сертификата в URLError.
if isinstance(exc.reason, ssl.SSLCertVerificationError):
return "cert_error:" + (exc.reason.verify_message or type(exc.reason).__name__)
return "url_error:" + type(exc.reason).__name__
@@ -268,8 +276,12 @@ def main():
check("OTLP ingress: same-CA foreign identity rejected",
otlp_rogue.get("result") == "http" and otlp_rogue.get("status") == 403, str(otlp_rogue))
otlp_none = probe("otlp")
# nginx с `ssl_verify_client on` на отсутствие сертификата отвечает 400
# (внутренний 496), а не рвёт TLS-рукопожатие — отказ всё равно есть.
check("OTLP ingress: no client certificate rejected",
otlp_none.get("result") == "tls_error", str(otlp_none))
otlp_none.get("result") == "tls_error"
or (otlp_none.get("result") == "http" and otlp_none.get("status") in (400, 403)),
str(otlp_none))
# 6. S3: TLS + раздельные scoped credentials.
api_key = (ROOT / "secrets/s3_api_access_key").read_text().strip()
@@ -448,10 +460,10 @@ def main():
for _ in range(40):
status, headers, _ = login(lim_name, "wrong-password-" + uuid.uuid4().hex)
statuses.append(status)
if headers.get("X-Instance-Id"):
instances.add(headers["X-Instance-Id"])
if headers.get("x-instance-id"):
instances.add(headers["x-instance-id"])
if status == 429:
retry_after = headers.get("Retry-After")
retry_after = headers.get("retry-after")
break
check("rate limit: 429 returned", 429 in statuses,
"statuses=" + ",".join(map(str, statuses[-5:])))