L7-T4: TLS terminate with explicit path rules.
(
sandbox: Callable[..., Sandbox],
)
| 1025 | |
| 1026 | |
| 1027 | def test_l7_tls_explicit_path_rules( |
| 1028 | sandbox: Callable[..., Sandbox], |
| 1029 | ) -> None: |
| 1030 | """L7-T4: TLS terminate with explicit path rules.""" |
| 1031 | policy = _base_policy( |
| 1032 | network_policies={ |
| 1033 | "anthropic": sandbox_pb2.NetworkPolicyRule( |
| 1034 | name="anthropic", |
| 1035 | endpoints=[ |
| 1036 | sandbox_pb2.NetworkEndpoint( |
| 1037 | host="api.anthropic.com", |
| 1038 | port=443, |
| 1039 | protocol="rest", |
| 1040 | tls="terminate", |
| 1041 | enforcement="enforce", |
| 1042 | rules=[ |
| 1043 | sandbox_pb2.L7Rule( |
| 1044 | allow=sandbox_pb2.L7Allow(method="GET", path="/v1/**"), |
| 1045 | ), |
| 1046 | ], |
| 1047 | ), |
| 1048 | ], |
| 1049 | binaries=[sandbox_pb2.NetworkBinary(path="/**")], |
| 1050 | ), |
| 1051 | }, |
| 1052 | ) |
| 1053 | spec = datamodel_pb2.SandboxSpec(policy=policy) |
| 1054 | with sandbox(spec=spec, delete_on_exit=True) as sb: |
| 1055 | # GET /v1/models -> allowed (matches /v1/**) |
| 1056 | get_result = sb.exec_python( |
| 1057 | _proxy_connect_then_http(), |
| 1058 | args=("api.anthropic.com", 443, "GET", "/v1/models"), |
| 1059 | ) |
| 1060 | assert get_result.exit_code == 0, get_result.stderr |
| 1061 | get_resp = json.loads(get_result.stdout) |
| 1062 | assert get_resp["http_status"] != 403 |
| 1063 | |
| 1064 | # POST /v1/messages -> denied (no POST rule) |
| 1065 | post_result = sb.exec_python( |
| 1066 | _proxy_connect_then_http(), |
| 1067 | args=("api.anthropic.com", 443, "POST", "/v1/messages"), |
| 1068 | ) |
| 1069 | assert post_result.exit_code == 0, post_result.stderr |
| 1070 | post_resp = json.loads(post_result.stdout) |
| 1071 | assert post_resp["http_status"] == 403 |
| 1072 | |
| 1073 | # GET /v2/anything -> denied (path doesn't match /v1/**) |
| 1074 | v2_result = sb.exec_python( |
| 1075 | _proxy_connect_then_http(), |
| 1076 | args=("api.anthropic.com", 443, "GET", "/v2/anything"), |
| 1077 | ) |
| 1078 | assert v2_result.exit_code == 0, v2_result.stderr |
| 1079 | v2_resp = json.loads(v2_result.stdout) |
| 1080 | assert v2_resp["http_status"] == 403 |
| 1081 | |
| 1082 | |
| 1083 | def test_l7_tls_ca_trust_store_injected( |
nothing calls this directly
no test coverage detected