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

https socks http connector and rustls now working #1236

Open
Masber opened this issue Jul 2, 2023 · 3 comments
Open

https socks http connector and rustls now working #1236

Masber opened this issue Jul 2, 2023 · 3 comments
Labels
bug Something isn't working

Comments

@Masber
Copy link

Masber commented Jul 2, 2023

Current and expected behavior

Background.:

I am trying to upgrade my kube-rs crate to latest version, for this I need to update from native-tls to rustls

Current behavior:

I am getting an error when trying to build a client based on https<socks> connector, I am not sure why, but I got this working with native tls.

This works:

        let connector = {
            let mut http = hyper::client::HttpConnector::new();
            http.enforce_http(false);
            let proxy = hyper_socks2::SocksConnector {
                proxy_addr: std::env::var("SOCKS5").unwrap().parse::<Uri>().unwrap(),
                auth: None,
                connector: http,
            };
            let mut native_tls_builder = native_tls::TlsConnector::builder();
            native_tls_builder.danger_accept_invalid_certs(true);
            native_tls_builder.danger_accept_invalid_hostnames(true);
            native_tls_builder.use_sni(false);

            let tls = tokio_native_tls::TlsConnector::from(config.native_tls_connector()?);
            hyper_tls::HttpsConnector::from((proxy, tls))
        };

        let service = tower::ServiceBuilder::new()
            .layer(config.base_uri_layer())
            .option_layer(config.auth_layer()?)
            .service(hyper::Client::builder().build(connector));

        kube::Client::new(service, config.default_namespace)

This does not work:

        let rustls_config = std::sync::Arc::new(config.rustls_client_config()?);
        let mut http_connector = hyper::client::HttpConnector::new();
        http_connector.enforce_http(false);
        let socks_http_connector = SocksConnector {
            proxy_addr: std::env::var("SOCKS5").unwrap().parse::<Uri>().unwrap(), // scheme is required by HttpConnector
            auth: None,
            connector: http_connector.clone(),
        };
        let https_socks_http_connector = hyper_rustls::HttpsConnector::from((socks_http_connector.clone(), rustls_config.clone()));
        let service = tower::ServiceBuilder::new()
            .layer(config.base_uri_layer())
            .service(hyper::Client::builder().build(https_socks_http_connector));
        kube::Client::new(service, config.default_namespace)

Expected behavior:

I would expect the code above to work and successfully create a connection to a kubeAPI through socks and https

Possible solution

I don't know of a possible solution, I am writing this because I am adopting one of your examples https://github.com/kube-rs/kube/blob/main/examples/custom_client_tls.rs and so far I have been unsuccessful

Additional context

No response

Environment

I build the kubeconfig dynamically/programatically
I am using vanilla k8s

Configuration and features

k8s-openapi v0.15.0
├── kube v0.74.0
│   └── mesa v0.6.15 (/home/msopena/polybox/Documents/tests/rust/mesa)
├── kube-client v0.74.0
│   ├── kube v0.74.0 (*)
│   └── kube-runtime v0.74.0
│       └── kube v0.74.0 (*)
├── kube-core v0.74.0
│   ├── kube v0.74.0 (*)
│   └── kube-client v0.74.0 (*)
├── kube-runtime v0.74.0 (*)
└── mesa v0.6.15 (/home/msopena/polybox/Documents/tests/rust/mesa)

and

❯ cat Cargo.toml | grep hyper-rustls
hyper-rustls = "0.23.0"

Affected crates

kube-client

Would you like to work on fixing this bug?

maybe

@Masber Masber added the bug Something isn't working label Jul 2, 2023
@clux
Copy link
Member

clux commented Jul 2, 2023

for clarification, the problem here is that it works with native-tls but not rustls, right?

some things that might get you on track);

@Masber
Copy link
Author

Masber commented Jul 2, 2023

  • he problem here is that it works with native-tls but not rustls, right? Correct
  • have you tried using the helpers from ConfigExt like rustls_https_connector_with_connector? My understanding is I need to create a HttpsConnector<SocksConnector<HttpConnector>> and rustls_https_connector_with_connector return a HttpsConnector<HttpConnector> ... I just tried creating a SocksConnector<HttpsConnector<HttpConnector>> like:
        log::debug!("SOCKS5 enabled");
        let https_http_connector = config.rustls_https_connector()?;
        let mut http_connector = hyper::client::HttpConnector::new();
        http_connector.enforce_http(false);
        let socks_https_http_connector = SocksConnector {
            proxy_addr: std::env::var("SOCKS5").unwrap().parse::<Uri>().unwrap(), // scheme is required by HttpConnector
            auth: None,
            connector: https_http_connector.clone(),
        };

        let https_socks_http_connector_2 = socks_https_http_connector.clone().with_tls()?;

        let service = tower::ServiceBuilder::new()
            .layer(config.base_uri_layer())
            .service(hyper::Client::builder().build(https_socks_http_connector_2));
        kube::Client::new(service, config.default_namespace)

but still does not work, it complains about:

Err(
    HyperError(
        hyper::Error(
            Connect,
            Connector(
                Custom {
                    kind: Other,
                    error: "Unsupported scheme socks5h",
                },
            ),
        ),
    ),
)
  • is it intentional you're not using the auth_layer for rustls? I was hoping this let https_socks_http_connector = hyper_rustls::HttpsConnector::from((socks_http_connector.clone(), rustls_config.clone())); would configure the certificates part on my behalf using the information injected from kubeconfig...

@Masber
Copy link
Author

Masber commented Jul 3, 2023

The reason I need a socks5 connector is that my k8s is too old and does not support the proxy settings...

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
bug Something isn't working
Projects
None yet
Development

No branches or pull requests

2 participants