Skip to content

Commit

Permalink
feat(pgwire): expose SSL functionality via RW_SSL_CERT and RW_SSL_KEY (
Browse files Browse the repository at this point in the history
  • Loading branch information
chenzl25 authored Dec 19, 2023
1 parent 9a4b1b0 commit 4c8d94e
Show file tree
Hide file tree
Showing 4 changed files with 8 additions and 64 deletions.
2 changes: 1 addition & 1 deletion src/frontend/src/lib.rs
Original file line number Diff line number Diff line change
Expand Up @@ -158,7 +158,7 @@ pub fn start(opts: FrontendOpts) -> Pin<Box<dyn Future<Output = ()> + Send>> {
Box::pin(async move {
let listen_addr = opts.listen_addr.clone();
let session_mgr = Arc::new(SessionManagerImpl::new(opts).await.unwrap());
pg_serve(&listen_addr, session_mgr, Some(TlsConfig::new_default()))
pg_serve(&listen_addr, session_mgr, TlsConfig::new_default())
.await
.unwrap();
})
Expand Down
22 changes: 7 additions & 15 deletions src/utils/pgwire/src/pg_protocol.rs
Original file line number Diff line number Diff line change
Expand Up @@ -15,7 +15,6 @@
use std::any::Any;
use std::collections::HashMap;
use std::panic::AssertUnwindSafe;
use std::path::PathBuf;
use std::pin::Pin;
use std::str::Utf8Error;
use std::sync::{Arc, LazyLock, Weak};
Expand Down Expand Up @@ -107,24 +106,17 @@ where
#[derive(Debug, Clone)]
pub struct TlsConfig {
/// The path to the TLS certificate.
pub cert: PathBuf,
pub cert: String,
/// The path to the TLS key.
pub key: PathBuf,
pub key: String,
}

impl TlsConfig {
pub fn new_default() -> Self {
let cert = PathBuf::new().join("tests/ssl/demo.crt");
let key = PathBuf::new().join("tests/ssl/demo.key");
let path_to_cur_proj = PathBuf::new().join("src/utils/pgwire");

Self {
// Now the demo crt and key are hard code generated via simple self-signed CA.
// In future it should change to configure by user.
// The path is mounted from project root.
cert: path_to_cur_proj.join(cert),
key: path_to_cur_proj.join(key),
}
pub fn new_default() -> Option<Self> {
let cert = std::env::var("RW_SSL_CERT").ok()?;
let key = std::env::var("RW_SSL_KEY").ok()?;
tracing::info!("RW_SSL_CERT={}, RW_SSL_KEY={}", cert, key);
Some(Self { cert, key })
}
}

Expand Down
20 changes: 0 additions & 20 deletions src/utils/pgwire/tests/ssl/demo.crt

This file was deleted.

28 changes: 0 additions & 28 deletions src/utils/pgwire/tests/ssl/demo.key

This file was deleted.

0 comments on commit 4c8d94e

Please sign in to comment.