etcdv3 / etcd-client

An etcd v3 API client
Apache License 2.0
205 stars 50 forks source link

Etcd client connect return error when tls enabled #49

Open haojinming opened 1 year ago

haojinming commented 1 year ago

The following code panic with error TransportError(tonic::transport::Error(Transport, hyper::Error(Connect, InvalidDNSNameError)))'

The config file is like this:

[pd]
endpoints = ["172.16.5.32:2379"]

[security]
ca-path = "~/ca/ca.cert.pem"
cert-path = "~/ca/client.cert.pem"
key-path = "~/client.key.pem"
 let mut option = ConnectOptions::new();
    if !config.security.ca_path.is_empty() {
        let (ca, cert, key) = config.security.load_certs().unwrap();
        option = option.with_tls(
            TlsOptions::new()
                .ca_certificate(Certificate::from_pem(ca))
                .identity(Identity::from_pem(cert, key)),
        );
    }
    let mut etcd_client = etcd_client::Client::connect(&config.pd.endpoints, Some(option))
        .await
        .unwrap();
haojinming commented 1 year ago

Do I use the tls feature correctly? I don't see any example in the repo about tls usage.

davidli2010 commented 1 year ago

We just re-export TLS related structures and functions from tonic::transport. I think you'd better check your config according to the error InvalidDNSNameError.

haojinming commented 1 year ago

Seems that TLS package etcd_client using does not support IP address as the endpoint. See issue: https://github.com/hyperium/tonic/issues/279. The error is reported here