Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

rustls: optionally use WebPKI roots to avoid panicking on Android & iOS #1323

Merged
merged 3 commits into from
Sep 29, 2024
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
3 changes: 3 additions & 0 deletions deny.toml
Original file line number Diff line number Diff line change
Expand Up @@ -40,6 +40,9 @@ exceptions = [
# this is not a problem for us. See https://github.com/dtolnay/unicode-ident/pull/9/files
# for more details.
{ allow = ["Unicode-DFS-2016"], name = "unicode-ident" },
# Pulled in via hyper-rustls when using the webpki-roots feature,
# which is off by default.
{ allow = ["MPL-2.0"], name = "webpki-roots" },
]

[[licenses.clarify]]
Expand Down
1 change: 1 addition & 0 deletions kube-client/Cargo.toml
Original file line number Diff line number Diff line change
Expand Up @@ -14,6 +14,7 @@ categories = ["web-programming::http-client", "network-programming", "api-bindin
[features]
default = ["client"]
rustls-tls = ["rustls", "rustls-pemfile", "hyper-rustls", "hyper-http-proxy?/rustls-tls-native-roots"]
webpki-roots = ["hyper-rustls/webpki-roots"]
aws-lc-rs = ["rustls?/aws-lc-rs"]
openssl-tls = ["openssl", "hyper-openssl"]
ws = ["client", "tokio-tungstenite", "rand", "kube-core/ws", "tokio/macros"]
Expand Down
8 changes: 7 additions & 1 deletion kube-client/src/client/auth/oauth.rs
Original file line number Diff line number Diff line change
Expand Up @@ -118,13 +118,19 @@
// Current TLS feature precedence when more than one are set:
// 1. rustls-tls
// 2. openssl-tls
#[cfg(feature = "rustls-tls")]
#[cfg(all(feature = "rustls-tls", not(feature = "webpki-roots")))]
let https = hyper_rustls::HttpsConnectorBuilder::new()
.with_native_roots()
.map_err(Error::NoValidNativeRootCA)?
.https_only()
.enable_http1()
.build();
#[cfg(all(feature = "rustls-tls", feature = "webpki-roots"))]
let https = hyper_rustls::HttpsConnectorBuilder::new()

Check warning on line 129 in kube-client/src/client/auth/oauth.rs

View check run for this annotation

Codecov / codecov/patch

kube-client/src/client/auth/oauth.rs#L129

Added line #L129 was not covered by tests
.with_webpki_roots()
.https_only()
.enable_http1()
.build();
#[cfg(all(not(feature = "rustls-tls"), feature = "openssl-tls"))]
let https =
hyper_openssl::HttpsConnector::new().map_err(Error::CreateOpensslHttpsConnector)?;
Expand Down
8 changes: 7 additions & 1 deletion kube-client/src/client/auth/oidc.rs
Original file line number Diff line number Diff line change
Expand Up @@ -313,13 +313,19 @@ impl Refresher {
.install_default()
.unwrap();

#[cfg(feature = "rustls-tls")]
#[cfg(all(feature = "rustls-tls", not(feature = "webpki-roots")))]
let https = hyper_rustls::HttpsConnectorBuilder::new()
.with_native_roots()
.map_err(|_| errors::RefreshInitError::NoValidNativeRootCA)?
.https_only()
.enable_http1()
.build();
#[cfg(all(feature = "rustls-tls", feature = "webpki-roots"))]
let https = hyper_rustls::HttpsConnectorBuilder::new()
.with_webpki_roots()
.https_only()
.enable_http1()
.build();
#[cfg(all(not(feature = "rustls-tls"), feature = "openssl-tls"))]
let https = hyper_openssl::HttpsConnector::new()?;

Expand Down
15 changes: 12 additions & 3 deletions kube-client/src/client/tls.rs
Original file line number Diff line number Diff line change
Expand Up @@ -55,9 +55,18 @@
let config_builder = if let Some(certs) = root_certs {
ClientConfig::builder().with_root_certificates(root_store(certs)?)
} else {
ClientConfig::builder()
.with_native_roots()
.map_err(Error::NoValidNativeRootCA)?
#[cfg(feature = "webpki-roots")]
{
// Use WebPKI roots.
ClientConfig::builder().with_webpki_roots()

Check warning on line 61 in kube-client/src/client/tls.rs

View check run for this annotation

Codecov / codecov/patch

kube-client/src/client/tls.rs#L61

Added line #L61 was not covered by tests
}
#[cfg(not(feature = "webpki-roots"))]
{
// Use native roots. This will panic on Android and iOS.
ClientConfig::builder()

Check warning on line 66 in kube-client/src/client/tls.rs

View check run for this annotation

Codecov / codecov/patch

kube-client/src/client/tls.rs#L66

Added line #L66 was not covered by tests
.with_native_roots()
clux marked this conversation as resolved.
Show resolved Hide resolved
.map_err(Error::NoValidNativeRootCA)?

Check warning on line 68 in kube-client/src/client/tls.rs

View check run for this annotation

Codecov / codecov/patch

kube-client/src/client/tls.rs#L68

Added line #L68 was not covered by tests
}
};

let mut client_config = if let Some((chain, pkey)) = identity_pem.map(client_auth).transpose()? {
Expand Down
1 change: 1 addition & 0 deletions kube/Cargo.toml
Original file line number Diff line number Diff line change
Expand Up @@ -37,6 +37,7 @@ unstable-runtime = ["kube-runtime/unstable-runtime", "runtime"]
unstable-client = ["kube-client/unstable-client", "client"]
socks5 = ["kube-client/socks5", "client"]
http-proxy = ["kube-client/http-proxy", "client"]
webpki-roots = ["kube-client/webpki-roots", "client"]

[package.metadata.docs.rs]
features = ["client", "rustls-tls", "openssl-tls", "derive", "ws", "oauth", "jsonpatch", "admission", "runtime", "k8s-openapi/latest", "unstable-runtime", "socks5", "http-proxy"]
Expand Down
Loading