Skip to content

Commit b61b6e6

Browse files
committed
Implement configurable PgWire authentication
- Add PGWIRE_USER and PGWIRE_PASSWORD config options with defaults - Replace NoopStartupHandler with CleartextPasswordAuthStartupHandler - Remove unused auth_manager parameters from handler constructors - Extract classify_query() and sanitize_query() helpers to reduce duplication - Update all .env files with postgres/postgres credentials for backward compatibility
1 parent f6e6e68 commit b61b6e6

File tree

9 files changed

+132
-134
lines changed

9 files changed

+132
-134
lines changed

.env.example

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -11,6 +11,8 @@ AWS_S3_BUCKET=
1111
AWS_ACCESS_KEY_ID=
1212
AWS_SECRET_ACCESS_KEY=
1313
PGWIRE_PORT=5432
14+
PGWIRE_USER=postgres
15+
PGWIRE_PASSWORD=postgres
1416
TIMEFUSION_TABLE_PREFIX=timefusion
1517

1618
# Delta Lake DynamoDB Locking Configuration (optional but recommended for multi-writer scenarios)

.env.minio

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -8,6 +8,8 @@ AWS_ALLOW_HTTP=true
88
AWS_ACCESS_KEY_ID=minioadmin
99
AWS_SECRET_ACCESS_KEY=minioadmin
1010
PGWIRE_PORT=12345
11+
PGWIRE_USER=postgres
12+
PGWIRE_PASSWORD=postgres
1113
PORT=80
1214

1315
TIMEFUSION_TABLE_PREFIX=timefusion-minio-test

.env.test

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -13,6 +13,8 @@ AWS_SDK_LOAD_CONFIG=false
1313

1414
# PostgreSQL Wire Protocol Configuration
1515
PGWIRE_PORT=12345
16+
PGWIRE_USER=postgres
17+
PGWIRE_PASSWORD=postgres
1618
TIMEFUSION_TABLE_PREFIX=test
1719

1820
# No DynamoDB locking for tests (uses local file-based locking)

src/config.rs

Lines changed: 5 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -93,6 +93,7 @@ const_default!(d_wal_dir: PathBuf = "/var/lib/timefusion/wal");
9393
const_default!(d_pgwire_port: u16 = 5432);
9494
const_default!(d_table_prefix: String = "timefusion");
9595
const_default!(d_batch_queue_capacity: usize = 100_000_000);
96+
const_default!(d_pgwire_user: String = "postgres");
9697
const_default!(d_flush_interval: u64 = 600);
9798
const_default!(d_retention_mins: u64 = 70);
9899
const_default!(d_eviction_interval: u64 = 60);
@@ -230,6 +231,10 @@ pub struct CoreConfig {
230231
pub enable_batch_queue: bool,
231232
#[serde(default = "d_batch_queue_capacity")]
232233
pub timefusion_batch_queue_capacity: usize,
234+
#[serde(default = "d_pgwire_user")]
235+
pub pgwire_user: String,
236+
#[serde(default)]
237+
pub pgwire_password: Option<String>,
233238
}
234239

235240
#[derive(Debug, Clone, Deserialize)]

src/main.rs

Lines changed: 7 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -1,7 +1,7 @@
11
// main.rs
22
#![recursion_limit = "512"]
33

4-
use datafusion_postgres::{ServerOptions, auth::AuthManager};
4+
use datafusion_postgres::ServerOptions;
55
use dotenv::dotenv;
66
use std::sync::Arc;
77
use timefusion::buffered_write_layer::BufferedWriteLayer;
@@ -85,12 +85,15 @@ async fn async_main(cfg: &'static AppConfig) -> anyhow::Result<()> {
8585
let pg_port = cfg.core.pgwire_port;
8686
info!("Starting PGWire server on port: {}", pg_port);
8787

88+
let auth_config = timefusion::pgwire_handlers::AuthConfig {
89+
username: cfg.core.pgwire_user.clone(),
90+
password: cfg.core.pgwire_password.clone(),
91+
};
92+
8893
let pg_task = tokio::spawn(async move {
8994
let opts = ServerOptions::new().with_port(pg_port).with_host("0.0.0.0".to_string());
90-
let auth_manager = Arc::new(AuthManager::new());
9195

92-
// Use our custom handlers that log UPDATE queries
93-
if let Err(e) = timefusion::pgwire_handlers::serve_with_logging(Arc::new(session_context), &opts, auth_manager).await {
96+
if let Err(e) = timefusion::pgwire_handlers::serve_with_logging(Arc::new(session_context), &opts, auth_config).await {
9497
error!("PGWire server error: {}", e);
9598
}
9699
});

0 commit comments

Comments
 (0)