Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
8 changes: 8 additions & 0 deletions .github/workflows/mysql-integration.yml
Original file line number Diff line number Diff line change
Expand Up @@ -36,7 +36,9 @@ jobs:
- 33060:3306
env:
MYSQL_ROOT_PASSWORD: password
MYSQL_DATABASE: testdb
options: >-
--volume /tmp/tabularis-mysql-socket:/var/run/mysqld
--health-cmd "mysqladmin ping -h 127.0.0.1 --silent"
--health-interval 10s
--health-timeout 5s
Expand Down Expand Up @@ -78,3 +80,9 @@ jobs:
TABULARIS_TEST_MYSQL_USER: root
TABULARIS_TEST_MYSQL_PASSWORD: password
run: cargo test --test mysql_foreign_keys --test mysql_routines --test mysql_columns --test mysql_indexes --test mysql_read_only --test mysql_float_precision --test mysql_table_transfer -- --include-ignored

- name: Verify MySQL socket and TCP authentication
working-directory: src-tauri
env:
MYSQL_UNIX_SOCKET: /tmp/tabularis-mysql-socket/mysqld.sock
run: cargo test --test socket_integration mysql_socket_auth_and_tcp_regression -- --ignored --exact
7 changes: 7 additions & 0 deletions .github/workflows/pg-integration.yml
Original file line number Diff line number Diff line change
Expand Up @@ -38,6 +38,7 @@ jobs:
POSTGRES_PASSWORD: password
POSTGRES_DB: testdb
options: >-
--volume /tmp/tabularis-pg-socket:/var/run/postgresql
--health-cmd pg_isready
--health-interval 10s
--health-timeout 5s
Expand Down Expand Up @@ -82,6 +83,12 @@ jobs:
REGENERATE_GOLDEN: ${{ (github.event_name == 'workflow_dispatch' && inputs.regenerate_golden) && '1' || '' }}
run: cargo test --test postgres_integration -- --include-ignored

- name: Verify PostgreSQL socket and TCP TLS settings
working-directory: src-tauri
env:
PG_UNIX_SOCKET: /tmp/tabularis-pg-socket/.s.PGSQL.5432
run: cargo test --test socket_integration postgres_socket_tls_and_tcp_regression -- --ignored --exact

- name: Upload golden files
if: github.event_name == 'workflow_dispatch' && inputs.regenerate_golden
uses: actions/upload-artifact@v7
Expand Down
2 changes: 0 additions & 2 deletions src-tauri/Cargo.lock

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

5 changes: 5 additions & 0 deletions src-tauri/Cargo.toml
Original file line number Diff line number Diff line change
Expand Up @@ -179,3 +179,8 @@ tauri-plugin-updater = { version = "2", optional = true }
tauri = { version = "2.10.2", features = ["test"] }
filetime = "0.2"
tokio-tungstenite = "0.24.0"

# SQLx 0.8.6 must recognize Unix sockets as secure during MySQL SHA-2 auth.
# See vendor/sqlx-mysql/README.tabularis.md for the exact patch and removal criteria.
[patch.crates-io]
sqlx-mysql = { path = "vendor/sqlx-mysql" }
10 changes: 7 additions & 3 deletions src-tauri/src/pool_manager.rs
Original file line number Diff line number Diff line change
Expand Up @@ -761,9 +761,13 @@ pub(crate) fn build_postgres_tls_connector(
params: &ConnectionParams,
) -> Result<PostgresTlsConnector, String> {
ensure_rustls_crypto_provider();
let ssl_mode = parse_postgres_ssl_mode(
non_empty_ssl_mode(params.ssl_mode.as_deref()).unwrap_or("prefer"),
)?;
let ssl_mode = if params.local_unix_socket_path().is_some() {
// Match the PostgreSQL config: local sockets do not use TLS, so stale
// certificate paths and TLS modes from a TCP connection are inactive.
PostgresSslChoice::Disable
} else {
parse_postgres_ssl_mode(non_empty_ssl_mode(params.ssl_mode.as_deref()).unwrap_or("prefer"))?
};
let user_ca = params.ssl_ca.as_deref().filter(|s| !s.trim().is_empty());
let user_cert = params.ssl_cert.as_deref().filter(|s| !s.trim().is_empty());
let user_key = params.ssl_key.as_deref().filter(|s| !s.trim().is_empty());
Expand Down
49 changes: 49 additions & 0 deletions src-tauri/src/pool_manager_tests.rs
Original file line number Diff line number Diff line change
Expand Up @@ -1589,6 +1589,55 @@ mod postgres_tls_connector_tests {
}
}

#[test]
fn postgres_socket_ignores_inactive_tls_settings() {
let missing = tempfile::tempdir().expect("temporary TLS directory");
for mode in ["require", "verify-ca", "verify-full", "obsolete-mode"] {
for (cert, key) in [(true, true), (true, false), (false, true), (false, false)] {
let mut params = params_with_ssl(mode);
params.unix_socket_path = Some("/tmp/.s.PGSQL.5432".to_string());
params.ssl_ca = Some(missing.path().join("ca.pem").display().to_string());
params.ssl_cert =
cert.then(|| missing.path().join("client.pem").display().to_string());
params.ssl_key = key.then(|| missing.path().join("key.pem").display().to_string());
assert!(
build_postgres_tls_connector(&params).is_ok(),
"socket must ignore inactive TLS settings: mode={mode}, cert={cert}, key={key}"
);
}
}
}

#[test]
fn postgres_tcp_and_tunnels_still_validate_tls_settings() {
let missing = tempfile::tempdir().expect("temporary TLS directory");
for tunnel in ["tcp", "ssh", "k8s", "blank-socket"] {
let mut params = params_with_ssl("verify-full");
params.ssl_ca = Some(missing.path().join("ca.pem").display().to_string());
match tunnel {
"ssh" => {
params.unix_socket_path = Some("/tmp/.s.PGSQL.5432".to_string());
params.ssh_enabled = Some(true);
}
"k8s" => {
params.unix_socket_path = Some("/tmp/.s.PGSQL.5432".to_string());
params.k8s_enabled = Some(true);
}
"blank-socket" => params.unix_socket_path = Some(" ".to_string()),
_ => {}
}
let err = build_postgres_tls_connector(&params)
.err()
.expect("missing CA must fail");
assert!(err.contains("ca.pem"), "{tunnel}: {err}");
params.ssl_mode = Some("obsolete-mode".to_string());
assert!(
build_postgres_tls_connector(&params).is_err(),
"{tunnel}: unknown TLS mode must fail"
);
}
}

#[test]
fn postgres_tls_connector_accepts_empty_hostname_for_unix_sockets() {
use tokio_postgres::tls::MakeTlsConnect;
Expand Down
142 changes: 142 additions & 0 deletions src-tauri/tests/socket_integration.rs
Original file line number Diff line number Diff line change
@@ -0,0 +1,142 @@
//! Run only against disposable local databases: the MySQL test clears its auth cache.
#![cfg(unix)]

use tabularis_lib::drivers::driver_trait::DatabaseDriver;
use tabularis_lib::drivers::{mysql::MysqlDriver, postgres::PostgresDriver};
use tabularis_lib::models::{ConnectionParams, DatabaseSelection};
use tabularis_lib::pool_manager::{
close_pool_with_id, get_mysql_pool_with_id, get_postgres_pool_with_id,
};

fn params(driver: &str, port: u16) -> ConnectionParams {
ConnectionParams {
driver: driver.to_string(),
host: Some("127.0.0.1".to_string()),
port: Some(port),
username: Some(
if driver == "mysql" {
"root"
} else {
"postgres"
}
.to_string(),
),
password: Some("password".to_string()),
database: DatabaseSelection::Single("testdb".to_string()),
..Default::default()
}
}

#[tokio::test]
#[ignore = "requires disposable MySQL on port 33060 and MYSQL_UNIX_SOCKET"]
async fn mysql_socket_auth_and_tcp_regression() {
let driver = MysqlDriver::new();
let tcp = params("mysql", 33060);
driver
.test_connection(&tcp)
.await
.expect("TCP authentication");
let admin = get_mysql_pool_with_id(&tcp, Some("socket-regression-admin"))
.await
.expect("TCP pool");
sqlx::query("FLUSH PRIVILEGES")
.execute(&admin)
.await
.expect("clear auth cache");

let mut socket = tcp.clone();
socket.unix_socket_path = Some(std::env::var("MYSQL_UNIX_SOCKET").expect("MYSQL_UNIX_SOCKET"));
socket.host = Some("ignored.invalid".to_string());
socket.port = Some(1);
socket.ssl_mode = Some("verify-full".to_string());
let missing = tempfile::tempdir().unwrap();
socket.ssl_ca = Some(missing.path().join("ca.pem").display().to_string());
socket.ssl_cert = Some(missing.path().join("cert.pem").display().to_string());
socket.ssl_key = Some(missing.path().join("key.pem").display().to_string());
socket.startup_script = Some("SET @socket_probe = 'started'".to_string());

let mut wrong = socket.clone();
wrong.password = Some("incorrect-password".to_string());
assert!(
driver.test_connection(&wrong).await.is_err(),
"socket must authenticate passwords"
);
driver
.test_connection(&socket)
.await
.expect("cold-cache socket authentication");
driver
.test_connection(&socket)
.await
.expect("repeat socket authentication");
for _ in 0..2 {
let pool = get_mysql_pool_with_id(&socket, Some("socket-regression"))
.await
.expect("socket pool");
let probe: String = sqlx::query_scalar("SELECT @socket_probe")
.fetch_one(&pool)
.await
.expect("startup script on socket pool");
assert_eq!(probe, "started");
close_pool_with_id(&socket, Some("socket-regression")).await;
}
// A local socket must not disable TLS checks when switching back to TCP.
socket.unix_socket_path = None;
socket.host = tcp.host.clone();
socket.port = tcp.port;
assert!(
driver.test_connection(&socket).await.is_err(),
"TCP must validate TLS files"
);
driver
.test_connection(&tcp)
.await
.expect("TCP still works after socket use");
close_pool_with_id(&tcp, Some("socket-regression-admin")).await;
}

#[tokio::test]
#[ignore = "requires disposable PostgreSQL on port 54320 and PG_UNIX_SOCKET"]
async fn postgres_socket_tls_and_tcp_regression() {
let driver = PostgresDriver::new();
let mut tcp = params("postgres", 54320);
driver
.test_connection(&tcp)
.await
.expect("TCP authentication");
let missing = tempfile::tempdir().unwrap();
tcp.ssl_mode = Some("verify-full".to_string());
tcp.ssl_ca = Some(missing.path().join("ca.pem").display().to_string());
tcp.ssl_cert = Some(missing.path().join("cert.pem").display().to_string());
tcp.ssl_key = Some(missing.path().join("key.pem").display().to_string());
assert!(
driver.test_connection(&tcp).await.is_err(),
"TCP must validate TLS files"
);
let mut socket = tcp.clone();
socket.unix_socket_path = Some(std::env::var("PG_UNIX_SOCKET").expect("PG_UNIX_SOCKET"));
socket.host = Some("ignored.invalid".to_string());
socket.port = Some(1);
socket.startup_script = Some("SET application_name = 'socket_probe'".to_string());
driver
.test_connection(&socket)
.await
.expect("socket ignores inactive TLS files");
for _ in 0..2 {
let pool = get_postgres_pool_with_id(&socket, Some("socket-regression"))
.await
.expect("socket pool");
let client = pool.get().await.expect("socket checkout");
let row = client
.query_one("SELECT current_setting('application_name')", &[])
.await
.expect("startup script on socket pool");
assert_eq!(row.get::<_, String>(0), "socket_probe");
drop(client);
close_pool_with_id(&socket, Some("socket-regression")).await;
}
driver
.test_connection(&params("postgres", 54320))
.await
.expect("TCP still works after socket use");
}
Loading