"""Full declared matrix, actual negative identities and no plaintext bypass.""" import json import socket import sys from security_helpers import * from botocore.exceptions import ClientError report={'matrix':[],'api_replicas':[],'plaintext_rejected':[],'policies':{}} # Each replica is resolved and tested, not merely the first load-balanced response. addresses=sorted({x[4][0] for x in socket.getaddrinfo('api',8080,type=socket.SOCK_STREAM)}) assert len(addresses)==2 for ip in addresses: assert b'200 OK' in probe('api',8080,'lb','/health/ready',address=ip) errors={} for role in [None,'foreign-client','outsider','expired-lb','wrong-lb','worker']: # A response must NOT reach the business HTTP handler. try:raw=probe('api',8080,role,'/health/ready',address=ip) except (ssl.SSLError,ConnectionResetError,ConnectionAbortedError) as error:errors[str(role)]=type(error).__name__;continue assert not raw,role errors[str(role)]='identity connection closed' report['api_replicas'].append({'address_alias':'replica'+str(len(report['api_replicas'])+1),'allowed_lb':True,'negative_cases':list(errors)}) cases=[ ('s3',8443,'api','/messenger-attachments','HEAD'), ('redis',8443,'api','/','GET'), ('broker',8443,'worker','/','GET'), ('otel-collector',8443,'api','/v1/traces','GET'), ('otel-collector',8443,'worker','/v1/traces','GET'), ('otel-collector',8443,'dispatcher','/v1/traces','GET'), ('otel-collector',8444,'prometheus','/metrics','GET'), ('otel-collector',8445,'prometheus','/metrics','GET'), ('loki',8443,'collector','/ready','GET'), ('loki',8443,'grafana','/ready','GET'), ('tempo',8443,'grafana','/ready','GET'), ('tempo',8444,'collector','/v1/traces','GET'), ('prometheus',8443,'grafana','/-/ready','GET'), ('bao',8200,'api','/v1/sys/seal-status','GET')] for host,port,role,path,method in cases: raw=probe(host,port,role,path,method) assert raw,(host,role) bad={} for invalid in [None,'foreign-client','outsider','expired-'+role]+(['api'] if host=='broker' else []): try:answer=probe(host,port,invalid,path,method) except (ssl.SSLError,ConnectionResetError,ConnectionAbortedError) as error:bad[str(invalid)]=type(error).__name__;continue if host=='bao' and invalid=='outsider': # TLS trusts the issuer; exact-leaf cert auth below provides role authorization. assert b'200' in answer;bad[invalid]='TLS CA accepted; service-auth denied separately';continue assert not answer,(host,invalid,answer[:50]) bad[str(invalid)]='identity connection closed' report['matrix'].append({'endpoint':host+':'+str(port),'allowed_identity':role,'positive_connection':True,'negative_cases':bad}) for role in ['api','worker','dispatcher']: auth=login(role);token=auth['client_token'] assert 0