3030# Standard proxy address inside the sandbox network namespace
3131_PROXY_HOST = "10.200.0.1"
3232_PROXY_PORT = 3128
33+ # sslip.io keeps the wildcard test on deterministic public DNS. Vendor-owned
34+ # telemetry subdomains can be NXDOMAIN or resolve to private ranges in CI.
35+ _PUBLIC_WILDCARD_SUFFIX = "1.1.1.1.sslip.io"
36+ _PUBLIC_WILDCARD_PATTERN = f"*.{ _PUBLIC_WILDCARD_SUFFIX } "
3337
3438
3539def _base_policy (
@@ -1835,79 +1839,89 @@ def test_single_port_backwards_compat(
18351839# Host wildcard tests
18361840# =============================================================================
18371841#
1838- # HW-1: Wildcard *.anthropic.com matches subdomains
1839- # HW-2: Wildcard *.anthropic.com does NOT match anthropic.com ( bare domain)
1840- # HW-3: Wildcard *.anthropic.com does NOT match deep.sub.anthropic.com
1842+ # HW-1: Wildcard host pattern matches subdomains
1843+ # HW-2: Wildcard host pattern does NOT match the bare domain
1844+ # HW-3: Wildcard host pattern does NOT match deep subdomains
18411845# =============================================================================
18421846
18431847
18441848def test_host_wildcard_matches_subdomain (
18451849 sandbox : Callable [..., Sandbox ],
18461850) -> None :
1847- """HW-1: *.anthropic.com matches api.anthropic.com ."""
1851+ """HW-1: host wildcard matches single-label subdomains ."""
18481852 policy = _base_policy (
18491853 network_policies = {
18501854 "wildcard" : sandbox_pb2 .NetworkPolicyRule (
18511855 name = "wildcard" ,
18521856 endpoints = [
1853- sandbox_pb2 .NetworkEndpoint (host = "*.anthropic.com" , port = 443 ),
1857+ sandbox_pb2 .NetworkEndpoint (
1858+ host = _PUBLIC_WILDCARD_PATTERN ,
1859+ port = 443 ,
1860+ ),
18541861 ],
18551862 binaries = [sandbox_pb2 .NetworkBinary (path = "/**" )],
18561863 ),
18571864 },
18581865 )
18591866 spec = datamodel_pb2 .SandboxSpec (policy = policy )
18601867 with sandbox (spec = spec , delete_on_exit = True ) as sb :
1861- # api.anthropic.com -> matches *.anthropic.com
1862- result = sb .exec_python (_proxy_connect (), args = ("api.anthropic.com" , 443 ))
1868+ first_subdomain = f"alpha. { _PUBLIC_WILDCARD_SUFFIX } "
1869+ result = sb .exec_python (_proxy_connect (), args = (first_subdomain , 443 ))
18631870 assert result .exit_code == 0 , result .stderr
18641871 assert "200" in result .stdout , (
1865- f"*.anthropic.com should match api.anthropic.com: { result .stdout } "
1872+ f"{ _PUBLIC_WILDCARD_PATTERN } should match { first_subdomain } : "
1873+ f"{ result .stdout } "
18661874 )
18671875
1868- # statsig.anthropic.com -> also matches *.anthropic.com
1869- result = sb .exec_python (_proxy_connect (), args = ("statsig.anthropic.com" , 443 ))
1876+ second_subdomain = f"beta. { _PUBLIC_WILDCARD_SUFFIX } "
1877+ result = sb .exec_python (_proxy_connect (), args = (second_subdomain , 443 ))
18701878 assert result .exit_code == 0 , result .stderr
18711879 assert "200" in result .stdout , (
1872- f"*.anthropic.com should match statsig.anthropic.com: { result .stdout } "
1880+ f"{ _PUBLIC_WILDCARD_PATTERN } should match { second_subdomain } : "
1881+ f"{ result .stdout } "
18731882 )
18741883
1875- # example.com -> does NOT match *.anthropic.com
1884+ # example.com -> does NOT match the wildcard pattern
18761885 result = sb .exec_python (_proxy_connect (), args = ("example.com" , 443 ))
18771886 assert result .exit_code == 0 , result .stderr
18781887 assert "403" in result .stdout , (
1879- f"*.anthropic.com should NOT match example.com: { result .stdout } "
1888+ f"{ _PUBLIC_WILDCARD_PATTERN } should NOT match example.com: "
1889+ f"{ result .stdout } "
18801890 )
18811891
18821892
18831893def test_host_wildcard_rejects_bare_domain (
18841894 sandbox : Callable [..., Sandbox ],
18851895) -> None :
1886- """HW-2: *.anthropic.com does NOT match anthropic.com (requires a subdomain) ."""
1896+ """HW-2: host wildcard does NOT match the bare domain ."""
18871897 policy = _base_policy (
18881898 network_policies = {
18891899 "wildcard" : sandbox_pb2 .NetworkPolicyRule (
18901900 name = "wildcard" ,
18911901 endpoints = [
1892- sandbox_pb2 .NetworkEndpoint (host = "*.anthropic.com" , port = 443 ),
1902+ sandbox_pb2 .NetworkEndpoint (
1903+ host = _PUBLIC_WILDCARD_PATTERN ,
1904+ port = 443 ,
1905+ ),
18931906 ],
18941907 binaries = [sandbox_pb2 .NetworkBinary (path = "/**" )],
18951908 ),
18961909 },
18971910 )
18981911 spec = datamodel_pb2 .SandboxSpec (policy = policy )
18991912 with sandbox (spec = spec , delete_on_exit = True ) as sb :
1900- result = sb .exec_python (_proxy_connect (), args = ("anthropic.com" , 443 ))
1913+ result = sb .exec_python (_proxy_connect (), args = (_PUBLIC_WILDCARD_SUFFIX , 443 ))
19011914 assert result .exit_code == 0 , result .stderr
19021915 assert "403" in result .stdout , (
1903- f"*.anthropic.com should NOT match bare anthropic.com: { result .stdout } "
1916+ f"{ _PUBLIC_WILDCARD_PATTERN } should NOT match bare "
1917+ f"{ _PUBLIC_WILDCARD_SUFFIX } : { result .stdout } "
19041918 )
19051919
19061920
19071921def test_host_wildcard_rejects_deep_subdomain (
19081922 sandbox : Callable [..., Sandbox ],
19091923) -> None :
1910- """HW-3: *.anthropic.com does NOT match deep.sub.anthropic.com .
1924+ """HW-3: host wildcard does NOT match a deep subdomain .
19111925
19121926 Single * matches one DNS label only (does not cross . boundaries).
19131927 """
@@ -1916,18 +1930,23 @@ def test_host_wildcard_rejects_deep_subdomain(
19161930 "wildcard" : sandbox_pb2 .NetworkPolicyRule (
19171931 name = "wildcard" ,
19181932 endpoints = [
1919- sandbox_pb2 .NetworkEndpoint (host = "*.anthropic.com" , port = 443 ),
1933+ sandbox_pb2 .NetworkEndpoint (
1934+ host = _PUBLIC_WILDCARD_PATTERN ,
1935+ port = 443 ,
1936+ ),
19201937 ],
19211938 binaries = [sandbox_pb2 .NetworkBinary (path = "/**" )],
19221939 ),
19231940 },
19241941 )
19251942 spec = datamodel_pb2 .SandboxSpec (policy = policy )
19261943 with sandbox (spec = spec , delete_on_exit = True ) as sb :
1927- result = sb .exec_python (_proxy_connect (), args = ("deep.sub.anthropic.com" , 443 ))
1944+ deep_subdomain = f"deep.sub.{ _PUBLIC_WILDCARD_SUFFIX } "
1945+ result = sb .exec_python (_proxy_connect (), args = (deep_subdomain , 443 ))
19281946 assert result .exit_code == 0 , result .stderr
19291947 assert "403" in result .stdout , (
1930- f"*.anthropic.com should NOT match deep.sub.anthropic.com: { result .stdout } "
1948+ f"{ _PUBLIC_WILDCARD_PATTERN } should NOT match { deep_subdomain } : "
1949+ f"{ result .stdout } "
19311950 )
19321951
19331952
0 commit comments