lab7: mTLS-границы, OpenBao raft, TLS-телеметрия, evidence уровней 3-4
Skeleton contracts / contracts (pull_request) Canceled after 0s
Skeleton contracts / contracts (pull_request) Canceled after 0s
This commit is contained in:
@@ -52,13 +52,14 @@ def cmd_api(args):
|
||||
|
||||
def cmd_broker(args):
|
||||
import pika
|
||||
from pika.credentials import ExternalCredentials
|
||||
|
||||
try:
|
||||
params = pika.ConnectionParameters(
|
||||
host=args.host,
|
||||
port=args.port,
|
||||
virtual_host="/",
|
||||
credentials=pika.ExternalCredentials(),
|
||||
credentials=ExternalCredentials(),
|
||||
ssl_options=pika.SSLOptions(tls_context(args.ca, args.cert, args.key),
|
||||
server_hostname=args.host),
|
||||
connection_attempts=1,
|
||||
@@ -129,14 +130,19 @@ def cmd_s3(args):
|
||||
emit({"result": "ok", "key": key})
|
||||
except ClientError as exc:
|
||||
code = exc.response.get("Error", {}).get("Code", "")
|
||||
emit({"result": "denied" if code in ("AccessDenied", "403", "AllAccessDisabled") else "error",
|
||||
"code": code})
|
||||
# Отозванный/удалённый ключ MinIO отвергает как InvalidAccessKeyId —
|
||||
# это тоже отказ в доступе, а не сбой пробы.
|
||||
denied_codes = ("AccessDenied", "403", "AllAccessDisabled",
|
||||
"InvalidAccessKeyId", "SignatureDoesNotMatch", "InvalidToken")
|
||||
emit({"result": "denied" if code in denied_codes else "error", "code": code})
|
||||
except BotoCoreError as exc:
|
||||
emit({"result": "error", "error": type(exc).__name__})
|
||||
|
||||
|
||||
def cmd_leak(args):
|
||||
import re
|
||||
import time
|
||||
import urllib.parse
|
||||
import urllib.request
|
||||
|
||||
ctx = tls_context(args.ca)
|
||||
@@ -147,14 +153,35 @@ def cmd_leak(args):
|
||||
re.compile(r"(?i)-----BEGIN [A-Z ]*PRIVATE KEY-----"),
|
||||
]
|
||||
matches = []
|
||||
url = ('https://loki:3100/loki/api/v1/query_range?'
|
||||
'query=%7Bservice_name%3D%22messenger-api%22%7D&limit=500')
|
||||
# Ограниченное окно и backward-чтение: без start/end Loki сканирует весь
|
||||
# retention и на объёмных логах легко не укладывается в таймаут.
|
||||
end_ns = int(time.time() * 1e9)
|
||||
start_ns = end_ns - 30 * 60 * 10**9
|
||||
url = "https://loki:3100/loki/api/v1/query_range?" + urllib.parse.urlencode({
|
||||
"query": '{service_name="messenger-api"}',
|
||||
"start": str(start_ns),
|
||||
"end": str(end_ns),
|
||||
"limit": "200",
|
||||
"direction": "backward",
|
||||
})
|
||||
try:
|
||||
with urllib.request.urlopen(url, timeout=15, context=ctx) as resp:
|
||||
lines = [json.loads(item)[1] for stream in
|
||||
json.load(resp)["data"]["result"] for item in stream["values"]]
|
||||
with urllib.request.urlopen(url, timeout=45, context=ctx) as resp:
|
||||
raw = resp.read()
|
||||
except urllib.error.HTTPError as exc:
|
||||
body = exc.read()[:200].decode("utf-8", "replace")
|
||||
emit({"result": "error", "error": "loki_http_%d" % exc.code, "body": body})
|
||||
except Exception as exc: # noqa: BLE001
|
||||
emit({"result": "error", "error": type(exc).__name__})
|
||||
try:
|
||||
payload = json.loads(raw)
|
||||
# В query_range values — это [[ns_timestamp, line], ...], строки уже
|
||||
# разобраны (json.loads нужен только для push-формата).
|
||||
lines = [item[1]
|
||||
for stream in (payload.get("data", {}).get("result") or [])
|
||||
for item in stream["values"]]
|
||||
except Exception as exc: # noqa: BLE001
|
||||
emit({"result": "error", "error": "loki_payload_" + type(exc).__name__,
|
||||
"body": raw[:200].decode("utf-8", "replace")})
|
||||
|
||||
for line in lines:
|
||||
for pattern in patterns:
|
||||
@@ -165,7 +192,7 @@ def cmd_leak(args):
|
||||
labels = []
|
||||
try:
|
||||
with urllib.request.urlopen("https://prometheus:9090/api/v1/labels",
|
||||
timeout=10, context=ctx) as resp:
|
||||
timeout=20, context=ctx) as resp:
|
||||
labels = json.load(resp)["data"]
|
||||
except Exception as exc: # noqa: BLE001
|
||||
emit({"result": "error", "error": "prometheus:" + type(exc).__name__})
|
||||
|
||||
Reference in New Issue
Block a user