@@ -38,6 +38,7 @@ struct UnexpectedSni(tls::ServerId, Remote<ClientAddr>);
3838
3939#[ derive( Clone , Debug ) ]
4040struct Tcp {
41+ policy : inbound:: policy:: AllowPolicy ,
4142 addr : Local < ServerAddr > ,
4243 client : Remote < ClientAddr > ,
4344 tls : tls:: ConditionalServerTls ,
@@ -49,6 +50,12 @@ struct Http {
4950 version : http:: Version ,
5051}
5152
53+ #[ derive( Clone , Debug ) ]
54+ struct Permitted {
55+ permit : inbound:: policy:: Permit ,
56+ http : Http ,
57+ }
58+
5259#[ derive( Clone ) ]
5360struct TlsParams {
5461 identity : Option < LocalCrtKey > ,
@@ -63,27 +70,36 @@ impl Config {
6370 pub fn build < B , R > (
6471 self ,
6572 bind : B ,
73+ policy : impl inbound:: policy:: CheckPolicy ,
6674 identity : Option < LocalCrtKey > ,
6775 report : R ,
6876 metrics : inbound:: Metrics ,
6977 trace : trace:: Handle ,
7078 drain : drain:: Watch ,
7179 shutdown : mpsc:: UnboundedSender < ( ) > ,
72- ) -> Result < Task , Error >
80+ ) -> Result < Task >
7381 where
7482 R : FmtMetrics + Clone + Send + Sync + Unpin + ' static ,
7583 B : Bind < ServerConfig > ,
7684 B :: Addrs : svc:: Param < Remote < ClientAddr > > + svc:: Param < Local < ServerAddr > > ,
7785 {
7886 let ( listen_addr, listen) = bind. bind ( & self . server ) ?;
7987
88+ // Get the policy for the admin server.
89+ let policy = policy. check_policy ( OrigDstAddr ( listen_addr. into ( ) ) ) ?;
90+
8091 let ( ready, latch) = crate :: server:: Readiness :: new ( ) ;
8192 let admin = crate :: server:: Admin :: new ( report, ready, shutdown, trace) ;
8293 let admin = svc:: stack ( move |_| admin. clone ( ) )
83- . push ( metrics. proxy . http_endpoint . to_layer :: < classify:: Response , _ , Http > ( ) )
94+ . push ( metrics. proxy . http_endpoint . to_layer :: < classify:: Response , _ , Permitted > ( ) )
95+ . push_map_target ( |( permit, http) | Permitted { permit, http } )
96+ . push ( inbound:: policy:: NewAuthorizeHttp :: layer ( metrics. http_authz . clone ( ) ) )
8497 . push_on_service (
8598 svc:: layers ( )
8699 . push ( errors:: NewRespond :: layer ( |error : Error | -> Result < _ > {
100+ if error. is :: < inbound:: policy:: DeniedUnauthorized > ( ) {
101+ return Ok ( errors:: SyntheticHttpResponse :: permission_denied ( error) ) ;
102+ }
87103 tracing:: warn!( %error, "Unexpected error" ) ;
88104 Ok ( errors:: SyntheticHttpResponse :: unexpected_error ( ) )
89105 } ) )
@@ -135,12 +151,11 @@ impl Config {
135151 . push ( detect:: NewDetectService :: layer ( detect:: Config :: < http:: DetectHttp > :: from_timeout ( DETECT_TIMEOUT ) ) )
136152 . push ( transport:: metrics:: NewServer :: layer ( metrics. proxy . transport ) )
137153 . push_map_target ( move |( tls, addrs) : ( tls:: ConditionalServerTls , B :: Addrs ) | {
138- // TODO(ver): We should enforce policy here; but we need to permit liveness probes
139- // for destination pods to startup...
140154 Tcp {
141155 tls,
142156 client : addrs. param ( ) ,
143157 addr : addrs. param ( ) ,
158+ policy : policy. clone ( ) ,
144159 }
145160 } )
146161 . push ( svc:: BoxNewService :: layer ( ) )
@@ -165,8 +180,7 @@ impl Param<transport::labels::Key> for Tcp {
165180 transport:: labels:: Key :: inbound_server (
166181 self . tls . clone ( ) ,
167182 self . addr . into ( ) ,
168- // TODO(ver) enforce policies on the proxy's admin port.
169- metrics:: ServerLabel ( "default:admin" . to_string ( ) ) ,
183+ self . policy . server_label ( ) ,
170184 )
171185 }
172186}
@@ -185,22 +199,39 @@ impl Param<OrigDstAddr> for Http {
185199 }
186200}
187201
202+ impl Param < Remote < ClientAddr > > for Http {
203+ fn param ( & self ) -> Remote < ClientAddr > {
204+ self . tcp . client
205+ }
206+ }
207+
208+ impl Param < tls:: ConditionalServerTls > for Http {
209+ fn param ( & self ) -> tls:: ConditionalServerTls {
210+ self . tcp . tls . clone ( )
211+ }
212+ }
213+
214+ impl Param < inbound:: policy:: AllowPolicy > for Http {
215+ fn param ( & self ) -> inbound:: policy:: AllowPolicy {
216+ self . tcp . policy . clone ( )
217+ }
218+ }
219+
188220impl Param < metrics:: ServerLabel > for Http {
189221 fn param ( & self ) -> metrics:: ServerLabel {
190- metrics :: ServerLabel ( "default:admin" . to_string ( ) )
222+ self . tcp . policy . server_label ( )
191223 }
192224}
193225
194- impl Param < metrics:: EndpointLabels > for Http {
226+ // === impl Permitted ===
227+
228+ impl Param < metrics:: EndpointLabels > for Permitted {
195229 fn param ( & self ) -> metrics:: EndpointLabels {
196230 metrics:: InboundEndpointLabels {
197- tls : self . tcp . tls . clone ( ) ,
231+ tls : self . http . tcp . tls . clone ( ) ,
198232 authority : None ,
199- target_addr : self . tcp . addr . into ( ) ,
200- policy : metrics:: AuthzLabels {
201- server : self . param ( ) ,
202- authz : "default:all-unauthenticated" . to_string ( ) ,
203- } ,
233+ target_addr : self . http . tcp . addr . into ( ) ,
234+ policy : self . permit . labels . clone ( ) ,
204235 }
205236 . into ( )
206237 }
0 commit comments