Compare commits

...

5 Commits

Author SHA1 Message Date
Diego Imbert
f73457b54b avoid code duplication 2025-11-14 11:41:22 +01:00
Stephan Fitzpatrick
731fdf8092 fix: refactor TLS connection handling to avoid type mismatch
- Separate TLS and non-TLS branches to handle different connection types
- Each branch now fully handles client creation, query execution, and cleanup
- Follows the same pattern used in pg_executor.rs
2025-11-14 06:55:48 +00:00
Stephan Fitzpatrick
ddb703e2a8 fix: add postgres-native-tls dependency to windmill-api
The TLS connector fix requires postgres-native-tls to be available as
a dependency in windmill-api. This was already in the workspace but
not explicitly added to the windmill-api crate dependencies.
2025-11-14 06:05:26 +00:00
Stephan Fitzpatrick
86e02f4655 refactor: simplify ssl_mode check per bot review
The ssl_mode values verify-ca and verify-full are already normalized
to 'require' earlier in the function (line 689), so we only need to
check for 'require' in the conditional.
2025-11-14 05:43:26 +00:00
Stephan Fitzpatrick
d82ffd664d fix: use proper TLS connector for DuckLake instance catalog setup
The setup_ducklake_catalog_db_inner function was using NoTls even when
sslmode=require was set in the connection string, causing TLS handshake
failures with AWS RDS PostgreSQL.

This fix adds conditional TLS connector logic similar to pg_executor.rs:
- Uses native_tls::TlsConnector with MakeTlsConnector when sslmode requires SSL
- Accepts invalid certs/hostnames for compatibility with managed DB services
- Falls back to NoTls for non-SSL connections

Fixes the 'error performing TLS handshake: no TLS implementation configured'
error when setting up DuckLake instance catalogs with RDS PostgreSQL.
2025-11-14 05:38:47 +00:00
3 changed files with 39 additions and 12 deletions

1
backend/Cargo.lock generated
View File

@@ -15269,6 +15269,7 @@ dependencies = [
"pg_escape",
"pin-project",
"postgres-native-tls 0.5.0",
"postgres-native-tls 0.5.1",
"prometheus",
"quick_cache",
"rand 0.9.0",

View File

@@ -94,6 +94,7 @@ tempfile.workspace = true
tokio-util.workspace = true
tokio-tar.workspace = true
tokio-postgres.workspace = true
postgres-native-tls.workspace = true
hmac.workspace = true
cookie.workspace = true
sha2.workspace = true

View File

@@ -700,24 +700,49 @@ async fn setup_ducklake_catalog_db_inner(
dbname = dbname,
sslmode = ssl_mode
);
let (client, join_handle) = if ssl_mode == "require" {
use native_tls::TlsConnector;
use postgres_native_tls::MakeTlsConnector;
let mut connector = TlsConnector::builder();
connector.danger_accept_invalid_certs(true);
connector.danger_accept_invalid_hostnames(true);
let (client, connection) = tokio::time::timeout(
std::time::Duration::from_secs(20),
tokio_postgres::connect(
&conn_str,
MakeTlsConnector::new(connector.build().map_err(to_anyhow)?),
),
)
.await
.map_err(|e| error::Error::ExecutionErr(format!("timeout: {}", e.to_string())))?
.map_err(|e| error::Error::ExecutionErr(format!("error: {}", e.to_string())))?;
let join_handle = tokio::spawn(async move { connection.await });
(client, join_handle)
} else {
let (client, connection) = tokio::time::timeout(
std::time::Duration::from_secs(20),
tokio_postgres::connect(&conn_str, tokio_postgres::NoTls),
)
.await
.map_err(|e| error::Error::ExecutionErr(format!("timeout: {}", e.to_string())))?
.map_err(|e| error::Error::ExecutionErr(format!("error: {}", e.to_string())))?;
let join_handle = tokio::spawn(async move { connection.await });
(client, join_handle)
};
let (client, connection) = tokio::time::timeout(
std::time::Duration::from_secs(20),
tokio_postgres::connect(&conn_str, tokio_postgres::NoTls),
)
.await
.map_err(|e| error::Error::ExecutionErr(format!("timeout: {}", e.to_string())))?
.map_err(|e| error::Error::ExecutionErr(format!("error: {}", e.to_string())))?;
let join_handle = tokio::spawn(async move { connection.await });
logs.db_connect = "OK".to_string();
client
.batch_execute(&format!(
"GRANT CONNECT ON DATABASE \"{dbname}\" TO ducklake_user;
GRANT USAGE ON SCHEMA public TO ducklake_user;
GRANT CREATE ON SCHEMA public TO ducklake_user;
ALTER DEFAULT PRIVILEGES IN SCHEMA public
GRANT SELECT, INSERT, UPDATE, DELETE ON TABLES TO ducklake_user;"
GRANT USAGE ON SCHEMA public TO ducklake_user;
GRANT CREATE ON SCHEMA public TO ducklake_user;
ALTER DEFAULT PRIVILEGES IN SCHEMA public
GRANT SELECT, INSERT, UPDATE, DELETE ON TABLES TO ducklake_user;"
))
.await
.map_err(|e| {