Skip to content

Commit a07b33d

Browse files
authored
ingress: Restore original dst address routing (#1016)
In f8cc918, we started requiring the `l5d-dst-override` header. As described in linkerd/linkerd2#6157, this breaks some ingress configurations, especially those that may route to out-of-cluster resources. This change restores original-dst-addr routing for requests that do not include the `l5d-dst-override` header. Internally, this change centralizes the `DST_OVERRIDE_HEADER` and related utilities to the ingress module, as no other modules should have to know anything about it.
1 parent 4ab0eaf commit a07b33d

File tree

8 files changed

+186
-193
lines changed

8 files changed

+186
-193
lines changed

linkerd/app/core/src/lib.rs

Lines changed: 0 additions & 12 deletions
Original file line numberDiff line numberDiff line change
@@ -52,7 +52,6 @@ pub mod transport;
5252
pub use self::addr_match::{AddrMatch, IpMatch, NameMatch};
5353

5454
pub const CANONICAL_DST_HEADER: &str = "l5d-dst-canonical";
55-
pub const DST_OVERRIDE_HEADER: &str = "l5d-dst-override";
5655

5756
const DEFAULT_PORT: u16 = 80;
5857

@@ -65,17 +64,6 @@ pub struct ProxyRuntime {
6564
pub drain: drain::Watch,
6665
}
6766

68-
pub fn http_request_l5d_override_dst_name_addr<B>(
69-
req: &http::Request<B>,
70-
) -> Result<NameAddr, addr::Error> {
71-
proxy::http::authority_from_header(req, DST_OVERRIDE_HEADER)
72-
.ok_or_else(|| {
73-
tracing::trace!("{} not in request headers", DST_OVERRIDE_HEADER);
74-
addr::Error::InvalidHost
75-
})
76-
.and_then(|a| NameAddr::from_authority_with_default_port(&a, DEFAULT_PORT))
77-
}
78-
7967
pub fn http_request_authority_addr<B>(req: &http::Request<B>) -> Result<Addr, addr::Error> {
8068
req.uri()
8169
.authority()

linkerd/app/core/src/svc.rs

Lines changed: 5 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -28,6 +28,11 @@ pub use tower::{
2828

2929
pub type Buffer<Req, Rsp, E> = TowerBuffer<BoxService<Req, Rsp, E>, Req>;
3030

31+
pub type BoxHttp<B = http::BoxBody> =
32+
BoxService<http::Request<B>, http::Response<http::BoxBody>, Error>;
33+
34+
pub type BoxNewHttp<T, B = http::BoxBody> = BoxNewService<T, BoxHttp<B>>;
35+
3136
#[derive(Clone, Debug)]
3237
pub struct Layers<L>(L);
3338

linkerd/app/inbound/src/http/mod.rs

Lines changed: 1 addition & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -19,7 +19,7 @@ use linkerd_app_core::{
1919
proxy::{http, tap},
2020
reconnect,
2121
svc::{self, Param},
22-
Error, DST_OVERRIDE_HEADER,
22+
Error,
2323
};
2424
use tracing::debug_span;
2525

@@ -227,9 +227,6 @@ where
227227
.push(http::BoxResponse::layer()),
228228
)
229229
.check_new_service::<Target, http::Request<http::BoxBody>>()
230-
// Removes the override header after it has been used to
231-
// determine a request target.
232-
.push_on_response(strip_header::request::layer(DST_OVERRIDE_HEADER))
233230
// Routes each request to a target, obtains a service for that
234231
// target, and dispatches the request.
235232
.instrument_from_target()

linkerd/app/outbound/src/http/endpoint.rs

Lines changed: 1 addition & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -8,14 +8,7 @@ use linkerd_app_core::{
88
use tokio::io;
99

1010
impl<C> Outbound<C> {
11-
pub fn push_http_endpoint<T, B>(
12-
self,
13-
) -> Outbound<
14-
svc::BoxNewService<
15-
T,
16-
svc::BoxService<http::Request<B>, http::Response<http::BoxBody>, Error>,
17-
>,
18-
>
11+
pub fn push_http_endpoint<T, B>(self) -> Outbound<svc::BoxNewHttp<T, B>>
1912
where
2013
T: Clone + Send + Sync + 'static,
2114
T: svc::Param<http::client::Settings>

linkerd/app/outbound/src/http/logical.rs

Lines changed: 3 additions & 15 deletions
Original file line numberDiff line numberDiff line change
@@ -8,20 +8,12 @@ use linkerd_app_core::{
88
http,
99
resolve::map_endpoint,
1010
},
11-
retry, svc, Error, Never, DST_OVERRIDE_HEADER,
11+
retry, svc, Error, Never,
1212
};
1313
use tracing::debug_span;
1414

1515
impl<E> Outbound<E> {
16-
pub fn push_http_logical<B, ESvc, R>(
17-
self,
18-
resolve: R,
19-
) -> Outbound<
20-
svc::BoxNewService<
21-
Logical,
22-
svc::BoxService<http::Request<B>, http::Response<http::BoxBody>, Error>,
23-
>,
24-
>
16+
pub fn push_http_logical<B, ESvc, R>(self, resolve: R) -> Outbound<svc::BoxNewHttp<Logical, B>>
2517
where
2618
B: http::HttpBody<Error = Error> + std::fmt::Debug + Default + Send + 'static,
2719
B::Data: Send + 'static,
@@ -144,11 +136,7 @@ impl<E> Outbound<E> {
144136
// canonical-dst-header. The response body is boxed unify the profile
145137
// stack's response type. withthat of to endpoint stack.
146138
.push(http::NewHeaderFromTarget::<CanonicalDstHeader, _>::layer())
147-
.push_on_response(
148-
svc::layers()
149-
.push(http::strip_header::request::layer(DST_OVERRIDE_HEADER))
150-
.push(http::BoxResponse::layer()),
151-
)
139+
.push_on_response(svc::layers().push(http::BoxResponse::layer()))
152140
.instrument(|l: &Logical| debug_span!("logical", dst = %l.logical_addr))
153141
.push_on_response(svc::BoxService::layer())
154142
.push(svc::BoxNewService::layer());

0 commit comments

Comments
 (0)