forked from mtusi2026/mtusi2026lab7
lab7: TLS ко всем зависимостям и телеметрии; раздельные роли PostgreSQL (GRANT по коду), ACL Valkey, AMQPS, HTTPS S3, mTLS Collector/Prometheus/Loki/Tempo/Grafana
This commit is contained in:
+5
-2
@@ -16,6 +16,7 @@ from __future__ import annotations
|
||||
import base64
|
||||
import json
|
||||
import os
|
||||
import ssl
|
||||
import sys
|
||||
import time
|
||||
import urllib.error
|
||||
@@ -24,7 +25,9 @@ import urllib.request
|
||||
from pathlib import Path
|
||||
|
||||
ROOT = Path(__file__).resolve().parents[1]
|
||||
GRAFANA = os.environ.get("GRAFANA_URL", "http://127.0.0.1:3000").rstrip("/")
|
||||
GRAFANA = os.environ.get("GRAFANA_URL", "https://localhost:3000").rstrip("/")
|
||||
# Lab 7: Grafana is HTTPS with a public-CA certificate (SAN localhost); verified, never skipped.
|
||||
TLS = ssl.create_default_context(cafile=os.environ.get("CA_FILE") or str(ROOT / "secrets" / "pki" / "public-ca.crt"))
|
||||
|
||||
|
||||
def _auth() -> str:
|
||||
@@ -38,7 +41,7 @@ def get(uid: str, path: str, params: dict | None = None, timeout: float = 30) ->
|
||||
if params:
|
||||
url += "?" + urllib.parse.urlencode(params)
|
||||
request = urllib.request.Request(url, headers={"Authorization": _auth(), "Accept": "application/json"})
|
||||
with urllib.request.urlopen(request, timeout=timeout) as response:
|
||||
with urllib.request.urlopen(request, timeout=timeout, context=TLS) as response:
|
||||
return json.loads(response.read())
|
||||
|
||||
|
||||
|
||||
Reference in New Issue
Block a user