Skip to content

Commit

Permalink
Warn when trying to use an unsupported proxy protocol
Browse files Browse the repository at this point in the history
Signed-off-by: Natalie Klestrup Röijezon <nat@nullable.se>
  • Loading branch information
nightkr committed Nov 5, 2024
1 parent 179936a commit 05809f2
Showing 1 changed file with 28 additions and 3 deletions.
31 changes: 28 additions & 3 deletions kube-client/src/client/builder.rs
Original file line number Diff line number Diff line change
Expand Up @@ -91,9 +91,12 @@ impl TryFrom<Config> for ClientBuilder<GenericService> {
}
}

const PROXY_SCHEME_SOCKS5: &str = "socks5";
const PROXY_SCHEME_HTTP: &str = "http";

match config.proxy_url.as_ref() {
#[cfg(feature = "socks5")]
Some(proxy_url) if proxy_url.scheme_str() == Some("socks5") => {
Some(proxy_url) if proxy_url.scheme_str() == Some(PROXY_SCHEME_SOCKS5) => {
let connector = hyper_socks2::SocksConnector {
proxy_addr: proxy_url.clone(),
auth: None,
Expand All @@ -104,14 +107,36 @@ impl TryFrom<Config> for ClientBuilder<GenericService> {
}

#[cfg(feature = "http-proxy")]
Some(proxy_url) if proxy_url.scheme_str() == Some("http") => {
Some(proxy_url) if proxy_url.scheme_str() == Some(PROXY_SCHEME_HTTP) => {
let proxy = hyper_http_proxy::Proxy::new(hyper_http_proxy::Intercept::All, proxy_url.clone());
let connector = hyper_http_proxy::ProxyConnector::from_proxy_unsecured(connector, proxy);

make_generic_builder(connector, config)
}

_ => make_generic_builder(connector, config),
proxy_url => {
if let Some(proxy_url) = proxy_url {
let missing_proxy_feature = match proxy_url.scheme_str() {
Some(PROXY_SCHEME_SOCKS5) => Some("kube/socks5"),
Some(PROXY_SCHEME_HTTP) => Some("kube/http-proxy"),
_ => None,
};
if let Some(missing_proxy_feature) = missing_proxy_feature {
tracing::warn!(
?proxy_url,
missing_proxy_feature,
"proxy URL is set but kube was built without support for that protocol, ignoring..."
);
} else {
tracing::warn!(
?proxy_url,
"proxy URL is set but kube does not support that protocol, ignoring..."
);
}
}

make_generic_builder(connector, config)
}
}
}
}
Expand Down

0 comments on commit 05809f2

Please sign in to comment.