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

feat:add tls support fot memcached #5471

Open
wants to merge 1 commit into
base: main
Choose a base branch
from

Conversation

ozewr
Copy link

@ozewr ozewr commented Dec 27, 2024

Which issue does this PR close?

Closes #5419.

Rationale for this change

see #5419

What changes are included in this PR?

Modified the opendal::services::Memcached to support TLS connections.

Are there any user-facing changes?

Users can enable TLS using .tls() and provide the CA file using .cafile().
example:

let memcached = Memcached::default()
        .endpoint(r#"tcp://example.app.local:11211"#)
        .tls(true)
        .cafile(path);

@@ -82,6 +87,18 @@ impl MemcachedBuilder {
self.config.default_ttl = Some(ttl);
self
}

/// Set the tls connect on.
pub fn tls(mut self, tls: bool) -> Self {
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Let's use enable_tls to align with other config in opendal.

}

/// Set the tls connect on.
pub fn cafile(mut self, cafile: PathBuf) -> Self {
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I believe we should provide two options here:

  • We should load users' CA by default (via rustls_native_certs).
  • We should provide key and cert otpion for users to use their own cert.

/// default is false
pub tls: Option<bool>,
/// Path to the CA certificate for TLS verification.
pub cafile: Option<PathBuf>,
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Please don't use PathBuf in config, use String instead.

@@ -40,4 +41,8 @@ pub struct MemcachedConfig {
pub password: Option<String>,
/// The default ttl for put operations.
pub default_ttl: Option<Duration>,
/// default is false
pub tls: Option<bool>,
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Use bool is good enough that we make it default to false.

@@ -150,6 +175,9 @@ impl Builder for MemcachedBuilder {
endpoint,
username: self.config.username.clone(),
password: self.config.password.clone(),
tls: self.config.tls.clone(),
cafile: self.config.cafile.clone(),
host,
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Why we need a seperate host?

Copy link
Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Because ServerName requires it, I don't want to return an additional error.

}
}

pub async fn auth(&mut self, username: &str, password: &str) -> Result<()> {
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

It seems like we're repeating a significant amount of code. Perhaps we could work directly with AsyncWrite? I believe both TlsStream<TcpStream> and TcpStream have implemented it.

conn.auth(username, password).await?;
}
let config = rustls::ClientConfig::builder()
.with_root_certificates(root_cert_store)
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I suppose we don't need to manually install root certificates.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Projects
None yet
Development

Successfully merging this pull request may close these issues.

new feature: Memcached In Transit Encryption (TLS) support
2 participants