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

Change default TLS stack to rustls-tls #1261

Merged
merged 10 commits into from
Sep 8, 2023
12 changes: 1 addition & 11 deletions .github/workflows/ci.yml
Original file line number Diff line number Diff line change
Expand Up @@ -37,19 +37,9 @@ jobs:
# echo "OPENSSL_LIB_DIR=C:/Program Files/OpenSSL-Win64/lib" >> $env:GITHUB_ENV
# echo "OPENSSL_DIR=C:/Program Files/OpenSSL-Win64/" >> $env:GITHUB_ENV
# echo "OPENSSL_INCLUDE_DIR=C:/Program Files/OpenSSL-Win64/include" >> $env:GITHUB_ENV
# Only test Rustls on Windows instead due to #1191
- name: "Interim Hacky Windows Test for #1191"
if: matrix.os == 'windows-latest'
run: |
sed -i '0,/openssl/s//rustls/' kube/Cargo.toml
cat kube/Cargo.toml
cargo build
cargo test --workspace --lib --exclude kube-examples --exclude e2e -j6


# Real CI work starts here
- name: Build workspace
if: matrix.os != 'windows-latest'
run: cargo build

# Workspace unit tests with various feature sets
Expand All @@ -58,7 +48,7 @@ jobs:
if: matrix.os == 'ubuntu-latest' # only linux tests all feature combinations
- name: Run workspace unit tests (default features)
run: cargo test --workspace --lib --exclude kube-examples --exclude e2e -j6
if: matrix.os == 'ubuntu-latest'
if: matrix.os != 'macos-latest'
- name: Run workspace unit tests (all features)
if: matrix.os != 'windows-latest'
run: cargo test --workspace --lib --all-features --exclude kube-examples --exclude e2e -j6
Expand Down
12 changes: 6 additions & 6 deletions kube-client/src/client/auth/oauth.rs
Original file line number Diff line number Diff line change
Expand Up @@ -108,17 +108,17 @@ impl Gcp {
"At least one of rustls-tls or openssl-tls feature must be enabled to use oauth feature"
);
// Current TLS feature precedence when more than one are set:
// 1. openssl-tls
// 2. rustls-tls
#[cfg(feature = "openssl-tls")]
let https =
hyper_openssl::HttpsConnector::new().map_err(Error::CreateOpensslHttpsConnector)?;
#[cfg(all(not(feature = "openssl-tls"), feature = "rustls-tls"))]
// 1. rustls-tls
// 2. openssl-tls
#[cfg(feature = "rustls-tls")]
let https = hyper_rustls::HttpsConnectorBuilder::new()
.with_native_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)?;

let client = hyper::Client::builder().build::<_, hyper::Body>(https);

Expand Down
17 changes: 8 additions & 9 deletions kube-client/src/client/auth/oidc.rs
Original file line number Diff line number Diff line change
Expand Up @@ -251,12 +251,12 @@ compile_error!(
"At least one of rustls-tls or openssl-tls feature must be enabled to use refresh-oidc feature"
);
// Current TLS feature precedence when more than one are set:
// 1. openssl-tls
// 2. rustls-tls
#[cfg(feature = "openssl-tls")]
type HttpsConnector = hyper_openssl::HttpsConnector<HttpConnector>;
#[cfg(all(not(feature = "openssl-tls"), feature = "rustls-tls"))]
// 1. rustls-tls
// 2. openssl-tls
#[cfg(feature = "rustls-tls")]
type HttpsConnector = hyper_rustls::HttpsConnector<HttpConnector>;
#[cfg(all(not(feature = "rustls-tls"), feature = "openssl-tls"))]
type HttpsConnector = hyper_openssl::HttpsConnector<HttpConnector>;

/// Struct for refreshing the ID token with the refresh token.
#[derive(Debug)]
Expand Down Expand Up @@ -300,15 +300,14 @@ impl Refresher {
let client_id = get_field(Self::CONFIG_CLIENT_ID)?.into();
let client_secret = get_field(Self::CONFIG_CLIENT_SECRET)?.into();


#[cfg(feature = "openssl-tls")]
let https = hyper_openssl::HttpsConnector::new()?;
#[cfg(all(not(feature = "openssl-tls"), feature = "rustls-tls"))]
#[cfg(feature = "rustls-tls")]
let https = hyper_rustls::HttpsConnectorBuilder::new()
.with_native_roots()
.https_only()
.enable_http1()
.build();
#[cfg(all(not(feature = "rustls-tls"), feature = "openssl-tls"))]
let https = hyper_openssl::HttpsConnector::new()?;

let https_client = hyper::Client::builder().build(https);

Expand Down
10 changes: 5 additions & 5 deletions kube-client/src/client/builder.rs
Original file line number Diff line number Diff line change
Expand Up @@ -78,14 +78,14 @@ impl TryFrom<Config> for ClientBuilder<BoxService<Request<hyper::Body>, Response
connector.enforce_http(false);

// Current TLS feature precedence when more than one are set:
// 1. openssl-tls
// 2. rustls-tls
// 1. rustls-tls
// 2. openssl-tls
// Create a custom client to use something else.
// If TLS features are not enabled, http connector will be used.
#[cfg(feature = "openssl-tls")]
let connector = config.openssl_https_connector_with_connector(connector)?;
#[cfg(all(not(feature = "openssl-tls"), feature = "rustls-tls"))]
#[cfg(feature = "rustls-tls")]
let connector = config.rustls_https_connector_with_connector(connector)?;
#[cfg(all(not(feature = "rustls-tls"), feature = "openssl-tls"))]
let connector = config.openssl_https_connector_with_connector(connector)?;

let mut connector = TimeoutConnector::new(connector);

Expand Down
12 changes: 9 additions & 3 deletions kube/Cargo.toml
Original file line number Diff line number Diff line change
Expand Up @@ -16,18 +16,24 @@ rust-version = "1.64.0"
edition = "2021"

[features]
default = ["client", "openssl-tls"]
default = ["client", "rustls-tls"]

# default features
client = ["kube-client/client", "config"]
config = ["kube-client/config"]
rustls-tls = ["kube-client/rustls-tls"]

# alternative features
openssl-tls = ["kube-client/openssl-tls"]

# auxiliary features
ws = ["kube-client/ws", "kube-core/ws"]
oauth = ["kube-client/oauth"]
oidc = ["kube-client/oidc"]
gzip = ["kube-client/gzip"]
client = ["kube-client/client", "config"]
jsonpatch = ["kube-core/jsonpatch"]
admission = ["kube-core/admission"]
derive = ["kube-derive", "kube-core/schema"]
config = ["kube-client/config"]
runtime = ["kube-runtime"]
unstable-runtime = ["kube-runtime/unstable-runtime"]

Expand Down