Trying to connect two services inside GCP, need help. Setting tls programmatically. #1285
-
So i am trying to connect two services running as Google Cloud Run. I have a valid connection NodeJS Server -> Rust Client, but cannot make a connection between Rust Server -> Rust Client. So e few thing i think may be related:
let request = Request::from_parts(
metadata.clone(),
Default::default(),
UserId {
user_id: note.user_id.to_owned(),
},
); Where metadata is:
|
Beta Was this translation helpful? Give feedback.
Replies: 5 comments 11 replies
-
I think i am missing tls/ssl setup, but what i did let channel = channel_users
.tls_config(tonic::transport::ClientTlsConfig::new())
.context("Failed to create tls config to users service")?
.connect()
.await
.context("Failed to connect to users service")?; Throw me an error
|
Beta Was this translation helpful? Give feedback.
-
So this is how gcp do is using go: func NewConn(host string, insecure bool) (*grpc.ClientConn, error) {
var opts []grpc.DialOption
if host != "" {
opts = append(opts, grpc.WithAuthority(host))
}
if insecure {
opts = append(opts, grpc.WithInsecure())
} else {
// Note: On the Windows platform, use of x509.SystemCertPool() requires
// go version 1.18 or higher.
systemRoots, err := x509.SystemCertPool()
if err != nil {
return nil, err
}
cred := credentials.NewTLS(&tls.Config{
RootCAs: systemRoots,
})
opts = append(opts, grpc.WithTransportCredentials(cred))
}
return grpc.Dial(host, opts...)
} And i will try do something similiar using https://github.com/est31/rcgen |
Beta Was this translation helpful? Give feedback.
-
Next step using rcgen, still not working :( Now i am getting: let subject_alt_names = vec![
"xxx".to_string(),
"localhost".to_string(),
];
let cert = generate_simple_self_signed(subject_alt_names)
.unwrap()
.serialize_pem()
.unwrap();
let server_cert = cert.as_bytes();
let tonic_cert = Certificate::from_pem(server_cert);
let tls = ClientTlsConfig::new()
.ca_certificate(tonic_cert)
.domain_name("xxxx");
let channel = channel_users
.tls_config(tls)
.context("Failed to create tls config to users service")?
.connect()
.await
.context("Failed to connect to users service")?; |
Beta Was this translation helpful? Give feedback.
-
This is a perfect example of what i am struggling with ;p |
Beta Was this translation helpful? Give feedback.
-
All i need to do was to add "tls-roots" to features........omg, such a simple solution...... |
Beta Was this translation helpful? Give feedback.
All i need to do was to add "tls-roots" to features........omg, such a simple solution......
And everything works with one simple line:
let users_conn = UsersServiceClient::connect("xxxx").await?;