ЛР 7: TLS, mTLS, OpenBao и безопасность — на 3
Skeleton contracts / contracts (pull_request) Canceled after 0s
Skeleton contracts / contracts (pull_request) Canceled after 0s
This commit is contained in:
@@ -0,0 +1,62 @@
|
||||
"""Probe the actual telemetry gateways with distinct ingest and query credentials."""
|
||||
import base64
|
||||
import json
|
||||
import socket
|
||||
from pathlib import Path
|
||||
|
||||
import requests
|
||||
|
||||
CA = "/run/ca/server.crt"
|
||||
FOREIGN = "/run/ca/unrelated.crt"
|
||||
|
||||
|
||||
def report(case, **details):
|
||||
print(json.dumps({"case": case, "status": "PASS", **details}), flush=True)
|
||||
|
||||
|
||||
def main():
|
||||
values = Path("/run/check")
|
||||
collector = json.loads((values / "collector.json").read_bytes())
|
||||
exporters = collector["exporters"]
|
||||
config = json.loads((values / "datasources.json").read_bytes())
|
||||
with requests.Session() as client:
|
||||
client.trust_env = False
|
||||
client.verify = CA
|
||||
for source, exporter, raw in zip(config["datasources"], exporters.values(), (19090, 13100, 13200)):
|
||||
url = source["url"]
|
||||
service = source["type"]
|
||||
write_headers = exporter["headers"]
|
||||
encoded = base64.b64encode(
|
||||
("grafana:" + source["secureJsonData"]["basicAuthPassword"]).encode()
|
||||
).decode()
|
||||
read_headers = {"Authorization": "Basic " + encoded}
|
||||
read = url + ("/-/ready" if service == "prometheus" else "/ready")
|
||||
write = exporter["endpoint"] + {
|
||||
"prometheus": "", "loki": "/v1/logs", "tempo": "/v1/traces",
|
||||
}[service]
|
||||
assert client.get(read, headers=read_headers, timeout=4).status_code == 200
|
||||
assert client.get(read, headers=write_headers, timeout=4).status_code == 403
|
||||
assert client.post(write, headers=read_headers, timeout=4).status_code == 403
|
||||
assert client.post(write, timeout=4).status_code == 403
|
||||
try:
|
||||
client.get(read, headers=read_headers, verify=FOREIGN, timeout=4)
|
||||
except requests.exceptions.SSLError as exc:
|
||||
assert "CERTIFICATE_VERIFY_FAILED" in str(exc)
|
||||
else:
|
||||
raise AssertionError("Backend accepted an unrelated CA")
|
||||
try:
|
||||
with socket.create_connection((service, raw), timeout=3):
|
||||
raise AssertionError("Plaintext application listener is reachable")
|
||||
except ConnectionRefusedError:
|
||||
pass
|
||||
report(service + " restricted TLS gateway", reader=200, wrong_role=403, anonymous_write=403,
|
||||
bad_ca="CERTIFICATE_VERIFY_FAILED", localhost_only_port=raw)
|
||||
try:
|
||||
with socket.create_connection(("otel-collector", 14318), timeout=3):
|
||||
raise AssertionError("Plaintext Collector reachable")
|
||||
except ConnectionRefusedError:
|
||||
report("Collector plaintext receiver isolated", localhost_only_port=14318)
|
||||
|
||||
|
||||
if __name__ == "__main__":
|
||||
main()
|
||||
Reference in New Issue
Block a user