|
1 | 1 | use super::Gateway; |
2 | | -use inbound::{GatewayAddr, GatewayDomainInvalid}; |
| 2 | +use inbound::{policy::Permitted, GatewayAddr, GatewayDomainInvalid}; |
3 | 3 | use linkerd_app_core::{ |
4 | 4 | metrics::ServerLabel, |
5 | 5 | profiles, |
@@ -81,50 +81,57 @@ impl Gateway { |
81 | 81 | R: Resolve<ConcreteAddr, Endpoint = Metadata, Error = Error>, |
82 | 82 | R::Resolution: Unpin, |
83 | 83 | { |
84 | | - let http = self |
85 | | - .outbound |
86 | | - .clone() |
87 | | - .with_stack(inner) |
88 | | - .push_http_cached(resolve) |
89 | | - .into_stack() |
90 | | - // Discard `T` and its associated client-specific metadata. |
91 | | - .push_map_target(Target::discard_parent) |
92 | | - .push(svc::ArcNewService::layer()) |
93 | | - // Add headers to prevent loops. |
94 | | - .push(NewHttpGateway::layer( |
95 | | - self.inbound.identity().local_id().clone(), |
96 | | - )) |
97 | | - .push_on_service(svc::LoadShed::layer()) |
98 | | - .lift_new() |
99 | | - .push(svc::ArcNewService::layer()) |
100 | | - // After protocol-downgrade, we need to build an inner stack for |
101 | | - // each request-level HTTP version. |
102 | | - .push(svc::NewOneshotRoute::layer_via(|t: &Target<T>| { |
103 | | - ByRequestVersion(t.clone()) |
104 | | - })) |
105 | | - // Only permit gateway traffic to endpoints for which we have |
106 | | - // discovery information. |
107 | | - .push_filter(|(_, parent): (_, T)| -> Result<_, GatewayDomainInvalid> { |
108 | | - let routes = { |
109 | | - let mut profile = |
110 | | - svc::Param::<Option<watch::Receiver<profiles::Profile>>>::param(&parent) |
| 84 | + let http = |
| 85 | + self.outbound |
| 86 | + .clone() |
| 87 | + .with_stack(inner) |
| 88 | + .push_http_cached(resolve) |
| 89 | + .into_stack() |
| 90 | + // Discard `T` and its associated client-specific metadata. |
| 91 | + .push_map_target(Target::discard_parent) |
| 92 | + .push(svc::ArcNewService::layer()) |
| 93 | + // Add headers to prevent loops. |
| 94 | + .push(NewHttpGateway::layer( |
| 95 | + self.inbound.identity().local_id().clone(), |
| 96 | + )) |
| 97 | + .push_on_service(svc::LoadShed::layer()) |
| 98 | + .lift_new() |
| 99 | + .push(svc::ArcNewService::layer()) |
| 100 | + // After protocol-downgrade, we need to build an inner stack for |
| 101 | + // each request-level HTTP version. |
| 102 | + .push(svc::NewOneshotRoute::layer_via(|t: &Target<T>| { |
| 103 | + ByRequestVersion(t.clone()) |
| 104 | + })) |
| 105 | + // Only permit gateway traffic to endpoints for which we have |
| 106 | + // discovery information. |
| 107 | + .push_filter( |
| 108 | + |Permitted { |
| 109 | + permit: _, |
| 110 | + target: parent, |
| 111 | + }: Permitted<T>| |
| 112 | + -> Result<_, GatewayDomainInvalid> { |
| 113 | + let routes = { |
| 114 | + let mut profile = svc::Param::< |
| 115 | + Option<watch::Receiver<profiles::Profile>>, |
| 116 | + >::param(&parent) |
111 | 117 | .ok_or(GatewayDomainInvalid)?; |
112 | | - let init = |
113 | | - mk_routes(&profile.borrow_and_update()).ok_or(GatewayDomainInvalid)?; |
114 | | - outbound::http::spawn_routes(profile, init, mk_routes) |
115 | | - }; |
116 | | - |
117 | | - Ok(Target { |
118 | | - routes, |
119 | | - addr: parent.param(), |
120 | | - version: parent.param(), |
121 | | - parent, |
122 | | - }) |
123 | | - }) |
124 | | - .push(svc::ArcNewService::layer()) |
125 | | - // Authorize requests to the gateway. |
126 | | - .push(self.inbound.authorize_http()) |
127 | | - .arc_new_clone_http(); |
| 118 | + let init = mk_routes(&profile.borrow_and_update()) |
| 119 | + .ok_or(GatewayDomainInvalid)?; |
| 120 | + outbound::http::spawn_routes(profile, init, mk_routes) |
| 121 | + }; |
| 122 | + |
| 123 | + Ok(Target { |
| 124 | + routes, |
| 125 | + addr: parent.param(), |
| 126 | + version: parent.param(), |
| 127 | + parent, |
| 128 | + }) |
| 129 | + }, |
| 130 | + ) |
| 131 | + .push(svc::ArcNewService::layer()) |
| 132 | + // Authorize requests to the gateway. |
| 133 | + .push(self.inbound.authorize_http()) |
| 134 | + .arc_new_clone_http(); |
128 | 135 |
|
129 | 136 | self.inbound |
130 | 137 | .clone() |
|
0 commit comments