Skip to content

Commit

Permalink
Merge pull request #1626 from nightkr/bugfix/warn-on-unsupported-proxy
Browse files Browse the repository at this point in the history
Warn when trying to use an unsupported proxy protocol
  • Loading branch information
nightkr authored Nov 7, 2024
2 parents 179936a + e81e3ac commit 9c402a6
Show file tree
Hide file tree
Showing 2 changed files with 50 additions and 14 deletions.
48 changes: 34 additions & 14 deletions kube-client/src/client/builder.rs
Original file line number Diff line number Diff line change
Expand Up @@ -92,26 +92,46 @@ impl TryFrom<Config> for ClientBuilder<GenericService> {
}

match config.proxy_url.as_ref() {
#[cfg(feature = "socks5")]
Some(proxy_url) if proxy_url.scheme_str() == Some("socks5") => {
let connector = hyper_socks2::SocksConnector {
proxy_addr: proxy_url.clone(),
auth: None,
connector,
};

make_generic_builder(connector, config)
#[cfg(feature = "socks5")]
{
let connector = hyper_socks2::SocksConnector {
proxy_addr: proxy_url.clone(),
auth: None,
connector,
};
make_generic_builder(connector, config)
}

#[cfg(not(feature = "socks5"))]
Err(Error::ProxyProtocolDisabled {
proxy_url: proxy_url.clone(),
protocol_feature: "kube/socks5",
})
}

#[cfg(feature = "http-proxy")]
Some(proxy_url) if proxy_url.scheme_str() == Some("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)
#[cfg(feature = "http-proxy")]
{
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)
}

#[cfg(not(feature = "http-proxy"))]
Err(Error::ProxyProtocolDisabled {
proxy_url: proxy_url.clone(),
protocol_feature: "kube/http-proxy",
})
}

_ => make_generic_builder(connector, config),
Some(proxy_url) => Err(Error::ProxyProtocolUnsupported {
proxy_url: proxy_url.clone(),
}),

None => make_generic_builder(connector, config),
}
}
}
Expand Down
16 changes: 16 additions & 0 deletions kube-client/src/error.rs
Original file line number Diff line number Diff line change
@@ -1,4 +1,5 @@
//! Error handling and error types
use http::Uri;
use thiserror::Error;

pub use kube_core::ErrorResponse;
Expand All @@ -25,6 +26,21 @@ pub enum Error {
#[error("ServiceError: {0}")]
Service(#[source] tower::BoxError),

/// Returned when the configured proxy uses an unsupported protocol.
#[error("configured proxy {proxy_url:?} uses an unsupported protocol")]
ProxyProtocolUnsupported {
/// The URL of the proxy.
proxy_url: Uri,
},
/// Returned when the configured proxy uses a protocol that requires a Cargo feature that is currently disabled
#[error("configured proxy {proxy_url:?} requires the disabled feature {protocol_feature:?}")]
ProxyProtocolDisabled {
/// The URL of the proxy.
proxy_url: Uri,
/// The Cargo feature that the proxy protocol requires.
protocol_feature: &'static str,
},

/// UTF-8 Error
#[error("UTF-8 Error: {0}")]
FromUtf8(#[source] std::string::FromUtf8Error),
Expand Down

0 comments on commit 9c402a6

Please sign in to comment.