Skip to content

Commit 6705bdd

Browse files
authored
fix(auth): Vector does not put the Proxy-Authorization header on the wire (#17353) (#17363)
fix(auth): Vector does not put the Proxy-Authorization header on the wire (#17353) closes: #17353
1 parent 9cd5404 commit 6705bdd

File tree

2 files changed

+38
-18
lines changed

2 files changed

+38
-18
lines changed

lib/vector-core/src/config/proxy.rs

+15-14
Original file line numberDiff line numberDiff line change
@@ -201,7 +201,12 @@ impl ProxyConfig {
201201
mod tests {
202202
use base64::prelude::{Engine as _, BASE64_STANDARD};
203203
use env_test_util::TempEnvVar;
204-
use http::{HeaderValue, Uri};
204+
use http::{
205+
header::{AUTHORIZATION, PROXY_AUTHORIZATION},
206+
HeaderName, HeaderValue, Uri,
207+
};
208+
209+
const PROXY_HEADERS: [HeaderName; 2] = [AUTHORIZATION, PROXY_AUTHORIZATION];
205210

206211
use super::*;
207212

@@ -341,20 +346,18 @@ mod tests {
341346
Some(first.uri()),
342347
Uri::try_from("http://user:pass@1.2.3.4:5678").as_ref().ok()
343348
);
344-
assert_eq!(
345-
first.headers().get("authorization"),
346-
expected_header_value.as_ref().ok()
347-
);
349+
for h in &PROXY_HEADERS {
350+
assert_eq!(first.headers().get(h), expected_header_value.as_ref().ok());
351+
}
348352
assert_eq!(
349353
Some(second.uri()),
350354
Uri::try_from("https://user:pass@2.3.4.5:9876")
351355
.as_ref()
352356
.ok()
353357
);
354-
assert_eq!(
355-
second.headers().get("authorization"),
356-
expected_header_value.as_ref().ok()
357-
);
358+
for h in &PROXY_HEADERS {
359+
assert_eq!(second.headers().get(h), expected_header_value.as_ref().ok());
360+
}
358361
}
359362

360363
#[ignore]
@@ -371,10 +374,8 @@ mod tests {
371374
.expect("should not be None");
372375
let encoded_header = format!("Basic {}", BASE64_STANDARD.encode("user:P@ssw0rd"));
373376
let expected_header_value = HeaderValue::from_str(encoded_header.as_str());
374-
375-
assert_eq!(
376-
first.headers().get("authorization"),
377-
expected_header_value.as_ref().ok()
378-
);
377+
for h in &PROXY_HEADERS {
378+
assert_eq!(first.headers().get(h), expected_header_value.as_ref().ok());
379+
}
379380
}
380381
}

src/http.rs

+23-4
Original file line numberDiff line numberDiff line change
@@ -53,10 +53,12 @@ impl HttpError {
5353
}
5454

5555
pub type HttpClientFuture = <HttpClient as Service<http::Request<Body>>>::Future;
56+
type HttpProxyConnector = ProxyConnector<HttpsConnector<HttpConnector>>;
5657

5758
pub struct HttpClient<B = Body> {
58-
client: Client<ProxyConnector<HttpsConnector<HttpConnector>>, B>,
59+
client: Client<HttpProxyConnector, B>,
5960
user_agent: HeaderValue,
61+
proxy_connector: HttpProxyConnector,
6062
}
6163

6264
impl<B> HttpClient<B>
@@ -77,14 +79,18 @@ where
7779
proxy_config: &ProxyConfig,
7880
client_builder: &mut client::Builder,
7981
) -> Result<HttpClient<B>, HttpError> {
80-
let proxy = build_proxy_connector(tls_settings.into(), proxy_config)?;
81-
let client = client_builder.build(proxy);
82+
let proxy_connector = build_proxy_connector(tls_settings.into(), proxy_config)?;
83+
let client = client_builder.build(proxy_connector.clone());
8284

8385
let version = crate::get_version();
8486
let user_agent = HeaderValue::from_str(&format!("Vector/{}", version))
8587
.expect("Invalid header value for version!");
8688

87-
Ok(HttpClient { client, user_agent })
89+
Ok(HttpClient {
90+
client,
91+
user_agent,
92+
proxy_connector,
93+
})
8894
}
8995

9096
pub fn send(
@@ -95,6 +101,7 @@ where
95101
let _enter = span.enter();
96102

97103
default_request_headers(&mut request, &self.user_agent);
104+
self.maybe_add_proxy_headers(&mut request);
98105

99106
emit!(http_client::AboutToSendHttpRequest { request: &request });
100107

@@ -135,6 +142,17 @@ where
135142

136143
Box::pin(fut)
137144
}
145+
146+
fn maybe_add_proxy_headers(&self, request: &mut Request<B>) {
147+
if let Some(proxy_headers) = self.proxy_connector.http_headers(request.uri()) {
148+
for (k, v) in proxy_headers {
149+
let request_headers = request.headers_mut();
150+
if !request_headers.contains_key(k) {
151+
request_headers.insert(k, v.into());
152+
}
153+
}
154+
}
155+
}
138156
}
139157

140158
pub fn build_proxy_connector(
@@ -216,6 +234,7 @@ impl<B> Clone for HttpClient<B> {
216234
Self {
217235
client: self.client.clone(),
218236
user_agent: self.user_agent.clone(),
237+
proxy_connector: self.proxy_connector.clone(),
219238
}
220239
}
221240
}

0 commit comments

Comments
 (0)