@@ -58,8 +58,8 @@ def setupTS(self, name, enable_cp):
5858 {
5959 "proxy.config.http.proxy_protocol_allowlist" : "127.0.0.1" ,
6060 "proxy.config.http.insert_forwarded" : "for|by=ip|proto" ,
61- "proxy.config.ssl.server.cert.path" : f" { self .ts .Variables .SSLDir } " ,
62- "proxy.config.ssl.server.private_key.path" : f" { self .ts .Variables .SSLDir } " ,
61+ "proxy.config.ssl.server.cert.path" : self .ts .Variables .SSLDir ,
62+ "proxy.config.ssl.server.private_key.path" : self .ts .Variables .SSLDir ,
6363 "proxy.config.diags.debug.enabled" : 1 ,
6464 "proxy.config.diags.debug.tags" : "proxyprotocol" ,
6565 })
@@ -106,6 +106,79 @@ def run(self):
106106 self .checkAccessLog ()
107107
108108
109+ class ProxyProtocolAllowlistTest :
110+ """Test that the PROXY Protocol allowlist applies only to PP-prefaced traffic."""
111+
112+ replay_file = "replay/proxy_protocol_allowlist.replay.yaml"
113+
114+ def __init__ (self ):
115+ self .setupOriginServer ()
116+ self .setupTS ()
117+
118+ def setupOriginServer (self ):
119+ self .server = Test .MakeVerifierServerProcess ("pp-allowlist-server" , self .replay_file )
120+
121+ def setupTS (self ):
122+ self .ts = Test .MakeATSProcess ("ts_pp_allowlist" , enable_tls = True , enable_cache = False , enable_proxy_protocol = True )
123+
124+ self .ts .addDefaultSSLFiles ()
125+ self .ts .Disk .ssl_multicert_yaml .AddLines (
126+ """
127+ ssl_multicert:
128+ - dest_ip: "*"
129+ ssl_cert_name: server.pem
130+ ssl_key_name: server.key
131+ """ .split ("\n " ))
132+
133+ self .ts .Disk .remap_config .AddLine (f"map / http://127.0.0.1:{ self .server .Variables .http_port } /" )
134+
135+ self .ts .Disk .records_config .update (
136+ {
137+ "proxy.config.http.proxy_protocol_allowlist" : "192.0.2.1" ,
138+ "proxy.config.ssl.server.cert.path" : self .ts .Variables .SSLDir ,
139+ "proxy.config.ssl.server.private_key.path" : self .ts .Variables .SSLDir ,
140+ "proxy.config.diags.debug.enabled" : 1 ,
141+ "proxy.config.diags.debug.tags" : "proxyprotocol" ,
142+ })
143+
144+ def addCurlRun (self , name , args , return_code = 0 , expect_status = None , start_processes = False ):
145+ tr = Test .AddTestRun (name )
146+ tr .TimeOut = 10
147+ tr .MakeCurlCommand (args , ts = self .ts )
148+ tr .Processes .Default .ReturnCode = return_code
149+
150+ if expect_status is not None :
151+ tr .Processes .Default .Streams .stdout = Testers .ContainsExpression (expect_status , f"Expected HTTP { expect_status } " )
152+
153+ if start_processes :
154+ tr .Processes .Default .StartBefore (self .server )
155+ tr .Processes .Default .StartBefore (self .ts )
156+
157+ tr .StillRunningAfter = self .server
158+ tr .StillRunningAfter = self .ts
159+
160+ def run (self ):
161+ self .addCurlRun (
162+ "Non-PP HTTP traffic bypasses proxy_protocol_allowlist" ,
163+ f'-sS -o /dev/null -w "%{{http_code}}" -H "uuid: 1" http://127.0.0.1:{ self .ts .Variables .proxy_protocol_port } /get' ,
164+ expect_status = "200" ,
165+ start_processes = True )
166+ self .addCurlRun (
167+ "Non-PP TLS traffic bypasses proxy_protocol_allowlist" , f'-k -sS -o /dev/null -w "%{{http_code}}" -H "uuid: 2" '
168+ f'https://127.0.0.1:{ self .ts .Variables .proxy_protocol_ssl_port } /get' ,
169+ expect_status = "200" )
170+ self .addCurlRun (
171+ "PP-prefaced HTTP traffic is rejected when peer is not allowlisted" ,
172+ f'-sS -o /dev/null --max-time 5 --haproxy-protocol '
173+ f'http://127.0.0.1:{ self .ts .Variables .proxy_protocol_port } /get' ,
174+ return_code = Any (52 , 56 ))
175+ self .addCurlRun (
176+ "PP-prefaced TLS traffic is rejected when peer is not allowlisted" ,
177+ f'-k -sS -o /dev/null --max-time 5 --haproxy-protocol '
178+ f'https://127.0.0.1:{ self .ts .Variables .proxy_protocol_ssl_port } /get' ,
179+ return_code = Any (35 , 52 , 56 ))
180+
181+
109182class ProxyProtocolOutTest :
110183 """Test that ATS can send Proxy Protocol."""
111184
@@ -164,8 +237,8 @@ def setupTS(self, tr: 'TestRun') -> None:
164237
165238 self ._ts .Disk .records_config .update (
166239 {
167- "proxy.config.ssl.server.cert.path" : f" { self ._ts .Variables .SSLDir } " ,
168- "proxy.config.ssl.server.private_key.path" : f" { self ._ts .Variables .SSLDir } " ,
240+ "proxy.config.ssl.server.cert.path" : self ._ts .Variables .SSLDir ,
241+ "proxy.config.ssl.server.private_key.path" : self ._ts .Variables .SSLDir ,
169242 "proxy.config.diags.debug.enabled" : 1 ,
170243 "proxy.config.diags.debug.tags" : "http|proxyprotocol" ,
171244 "proxy.config.http.proxy_protocol_out" : self ._pp_version ,
@@ -238,6 +311,7 @@ def run(self) -> None:
238311
239312ProxyProtocolInTest ("nocp" , False ).run ()
240313ProxyProtocolInTest ("cp" , True ).run ()
314+ ProxyProtocolAllowlistTest ().run ()
241315
242316# non-tunnling HTTP to origin
243317ProxyProtocolOutTest (pp_version = - 1 , is_tunnel = False , is_tls_to_origin = False ).run ()
0 commit comments