Files
mtusi2026lab7/checks/plaintext_isolation.py
T

16 lines
661 B
Python

import json
import socket
ports={'api1':[8080],'api2':[8080],'db':[5432],'s3':[8333,8888,9333,19333],
'cache':[6379],'broker':[6379],'otel-collector':[4318,9464,8888,13133],
'prometheus':[9090],'loki':[3100,9095],'tempo':[3200,4318,9095]}
results=[]
for host,values in ports.items():
for port in values:
with socket.socket() as s:
s.settimeout(2)
try:s.connect((host,port))
except ConnectionRefusedError:results.append({'host':host,'port':port,'refused':True})
else:raise AssertionError(f'Plaintext port reachable: {host}:{port}')
print(json.dumps({'passed':True,'probes':results},indent=2))