48 lines
2.6 KiB
Python
48 lines
2.6 KiB
Python
"""Verify live encrypted telemetry paths and inspect content without printing it."""
|
|
import json
|
|
import time
|
|
from pathlib import Path
|
|
from internal import http, config, S
|
|
|
|
|
|
def check(needles=()):
|
|
deadline=time.monotonic()+30
|
|
while True:
|
|
bodies=[]
|
|
for url,params in [
|
|
('https://prometheus:19090/api/v1/query',{'query':'http_requests_total'}),
|
|
('https://loki:13100/loki/api/v1/query_range',{'query':'{service_name=~"messenger-.*"}','limit':1000}),
|
|
('https://tempo:13200/api/search',{'limit':100})]:
|
|
r=http('GET',url,'operator',params=params)
|
|
assert r.status_code==200, f'{url}: HTTP {r.status_code}'
|
|
bodies.append(r.text)
|
|
metrics=json.loads(bodies[0])['data']['result']
|
|
logs=json.loads(bodies[1])['data']['result']
|
|
traces=json.loads(bodies[2]).get('traces',[])
|
|
if (metrics and logs and traces) or time.monotonic()>=deadline: break
|
|
time.sleep(1)
|
|
assert metrics and logs and traces, f'Signal counts: metrics={len(metrics)}, logs={len(logs)}, traces={len(traces)}'
|
|
for trace in traces[:20]:
|
|
r=http('GET','https://tempo:13200/api/traces/'+trace['traceID'],'operator')
|
|
assert r.status_code==200
|
|
bodies.append(r.text)
|
|
values=list(needles)+[v for role in config.values() for v in role.values()]
|
|
assert not any(value in body for value in values for body in bodies),'Telemetry credential/private-message leak'
|
|
for host,port,path in [('loki',13100,'/otlp/v1/logs'),('prometheus',19090,'/api/v1/write'),('tempo',13200,'/anything')]:
|
|
assert http('POST',f'https://{host}:{port}{path}','grafana',json={}).status_code==403
|
|
password=(S/'grafana-admin/password').read_text()
|
|
for name in ['prometheus','loki','tempo']:
|
|
path=(f'/api/datasources/uid/{name}/health' if name!='tempo'
|
|
else '/api/datasources/proxy/uid/tempo/api/search?limit=1')
|
|
response=http('GET','https://grafana:3443'+path,
|
|
auth=('admin',password))
|
|
assert response.status_code==200, f'Grafana datasource {name}: HTTP {response.status_code}'
|
|
result={'metric_series':len(metrics),'log_streams':len(logs),'trace_results':len(traces),
|
|
'checked_trace_bodies':min(20,len(traces)),'credential_canaries_absent':True,
|
|
'grafana_write_denied':True,'grafana_datasource_health':True}
|
|
Path('/evidence/telemetry.json').write_text(json.dumps(result,indent=2))
|
|
print('PASS: live metrics/logs/traces; no credential/message leaks; Grafana read-only TLS sources')
|
|
|
|
|
|
if __name__=='__main__':check()
|