import unittest from pathlib import Path import yaml ROOT=Path(__file__).resolve().parents[1] class SecureConfig(unittest.TestCase): def test_boundaries(self): d=yaml.safe_load((ROOT/'compose.yaml').read_text()) for name,s in d['services'].items(): self.assertTrue(s['read_only'],name) self.assertIn('no-new-privileges:true',s['security_opt'],name) self.assertEqual(s['cap_drop'],['ALL'],name) self.assertNotIn(str(s['user']).split(':')[0],['0','root'],name) self.assertIn('mem_limit',s,name) if name not in ['lb','openbao','grafana-tls']:self.assertNotIn('ports',s,name) for name in ['api','api2','worker']: s=d['services'][name] self.assertNotIn('secrets/operator',str(s)) self.assertNotIn('DATABASE_URL_FILE',str(s)) self.assertNotIn('S3_SECRET_ACCESS_KEY_FILE',str(s)) for name in ['api','api2']: self.assertEqual(d['services'][name]['environment']['APP_HOST'],'127.0.0.1') self.assertTrue(d['services'][name]['network_mode'].startswith('service:')) def test_identity_allowlists(self): for identity,expected in [('api',{'client-api'}),('otel-collector',{'api','worker','prometheus'})]: d=yaml.safe_load((ROOT/f'infra/envoy/{identity}.yaml').read_text()) actual=set() for listener in d['static_resources']['listeners']: for f in listener['filter_chains']: tls=f['transport_socket']['typed_config'] self.assertTrue(tls['require_client_certificate']) for san in tls['common_tls_context']['validation_context']['match_typed_subject_alt_names']: self.assertEqual(san['san_type'],'DNS');actual.add(san['matcher']['exact']) self.assertEqual(actual,expected) if __name__=='__main__':unittest.main()