Skip to content

armgit / dbx

Public Imported from GitHub
0

25 MB lightweight cross-platform database client for 100+ databases, including MySQL, PostgreSQL, SQLite, Redis, MongoDB, DuckDB, SQL Server, and Dameng. Built-in AI, MCP Server, CLI, desktop and Docker. | 轻量级跨平台数据库管理工具,支持 MySQL、PostgreSQL、SQLite、Redis、MongoDB、达梦等 100+ 数据库,提供桌面端、Docker、CLI、内置 AI 助手和 MCP。

fix(redis): support insecure tls connections

t8y2a9e7f3946d39
diff --git a/apps/desktop/src/components/connection/ConnectionDialog.vue b/apps/desktop/src/components/connection/ConnectionDialog.vue
index 333e7d7a2b..fbf642094e 100644
--- a/apps/desktop/src/components/connection/ConnectionDialog.vue
+++ b/apps/desktop/src/components/connection/ConnectionDialog.vue
@@ -663,6 +663,12 @@ const postgresClientKeyPath = computed({
form.value.url_params = setUrlParam(form.value.url_params, "sslkey", value);
},
});
+const redisTlsInsecure = computed({
+ get: () => getUrlParam(form.value.url_params, "insecure").toLowerCase() === "true",
+ set: (value: boolean) => {
+ form.value.url_params = setUrlParam(form.value.url_params, "insecure", value ? "true" : "");
+ },
+});
const canUseSsh = computed(() => form.value.db_type !== "sqlite" && form.value.db_type !== "access");
const canUseProxy = computed(
() => form.value.db_type !== "sqlite" && form.value.db_type !== "duckdb" && form.value.db_type !== "access",
@@ -1982,11 +1988,13 @@ function openExternalUrl(url: string) {
? 'databaseName=TENANT_DB'
: form.db_type === 'clickhouse'
? 'secure=true'
- : form.db_type === 'bigquery'
- ? 'OAuthType=0;[email protected];OAuthPvtKeyPath=/path/key.json'
- : form.db_type === 'informix'
- ? 'INFORMIXSERVER=informix;CLIENT_LOCALE=en_US.utf8;DB_LOCALE=en_US.utf8'
- : 'sslmode=disable'
+ : form.db_type === 'redis'
+ ? 'insecure=true'
+ : form.db_type === 'bigquery'
+ ? 'OAuthType=0;[email protected];OAuthPvtKeyPath=/path/key.json'
+ : form.db_type === 'informix'
+ ? 'INFORMIXSERVER=informix;CLIENT_LOCALE=en_US.utf8;DB_LOCALE=en_US.utf8'
+ : 'sslmode=disable'
"
/>
</div>
@@ -2007,6 +2015,16 @@ function openExternalUrl(url: string) {
</label>
</div>
+ <div v-if="form.db_type === 'redis'" class="grid grid-cols-4 items-start gap-4">
+ <Label class="text-right text-xs">{{ t("connection.redisTlsInsecure") }}</Label>
+ <label class="col-span-3 flex items-start gap-2 cursor-pointer">
+ <input type="checkbox" v-model="redisTlsInsecure" class="mr-0 mt-0.5" :disabled="!form.ssl" />
+ <span class="text-xs leading-5 text-muted-foreground">
+ {{ t("connection.redisTlsInsecureHint") }}
+ </span>
+ </label>
+ </div>
+
<template v-if="supportsMysqlTlsOptions">
<div class="grid grid-cols-4 items-center gap-4">
<Label class="text-right text-xs">{{ t("connection.mysqlTlsMode") }}</Label>
diff --git a/apps/desktop/src/i18n/locales/en.ts b/apps/desktop/src/i18n/locales/en.ts
index e5cc0ccb05..f01355b8da 100644
--- a/apps/desktop/src/i18n/locales/en.ts
+++ b/apps/desktop/src/i18n/locales/en.ts
@@ -130,6 +130,8 @@ export default {
caCertPath: "CA Certificate",
caCertPathPlaceholder: "Optional, e.g. ~/.yandex/RootCA.crt",
caCertPathBrowse: "Browse certificate",
+ redisTlsInsecure: "Skip certificate verification",
+ redisTlsInsecureHint: "Equivalent to redis-cli --tls --insecure, for self-signed certificates or private CAs.",
mysqlTlsMode: "TLS Mode",
mysqlTlsModePreferred: "Preferred",
mysqlTlsModeDisabled: "Disabled",
diff --git a/apps/desktop/src/i18n/locales/es.ts b/apps/desktop/src/i18n/locales/es.ts
index 5b94d325de..9e4140065f 100644
--- a/apps/desktop/src/i18n/locales/es.ts
+++ b/apps/desktop/src/i18n/locales/es.ts
@@ -129,6 +129,8 @@ export default {
caCertPath: "Certificado CA",
caCertPathPlaceholder: "Opcional, p. ej. ~/.yandex/RootCA.crt",
caCertPathBrowse: "Buscar certificado",
+ redisTlsInsecure: "Omitir verificación del certificado",
+ redisTlsInsecureHint: "Equivale a redis-cli --tls --insecure, para certificados autofirmados o CA privadas.",
mysqlTlsMode: "Modo TLS",
mysqlTlsModePreferred: "Preferido",
mysqlTlsModeDisabled: "Deshabilitado",
diff --git a/apps/desktop/src/i18n/locales/zh-CN.ts b/apps/desktop/src/i18n/locales/zh-CN.ts
index 5b8ad8b8d6..cd9cdaf210 100644
--- a/apps/desktop/src/i18n/locales/zh-CN.ts
+++ b/apps/desktop/src/i18n/locales/zh-CN.ts
@@ -129,6 +129,8 @@ export default {
caCertPath: "CA 证书",
caCertPathPlaceholder: "可选,例如 ~/.yandex/RootCA.crt",
caCertPathBrowse: "选择证书",
+ redisTlsInsecure: "跳过证书验证",
+ redisTlsInsecureHint: "等价于 redis-cli --tls --insecure,适用于自签名证书或私有 CA。",
mysqlTlsMode: "TLS 模式",
mysqlTlsModePreferred: "优先使用",
mysqlTlsModeDisabled: "禁用",
diff --git a/apps/desktop/src/lib/connectionUrl.ts b/apps/desktop/src/lib/connectionUrl.ts
index 49bf19af26..e7fbfb794f 100644
--- a/apps/desktop/src/lib/connectionUrl.ts
+++ b/apps/desktop/src/lib/connectionUrl.ts
@@ -259,6 +259,11 @@ export function parseConnectionUrl(value: string, preferredProfile?: string): Pa
}
const urlParams = parsed.search.replace(/^\?/, "");
+ const normalizedFragment = decodeUrlPart(parsed.hash.replace(/^#/, "")).trim().toLowerCase();
+ const parsedUrlParams =
+ profile.type === "redis" && normalizedFragment === "insecure"
+ ? [urlParams, "insecure=true"].filter(Boolean).join("&")
+ : urlParams;
if (profile.type === "mongodb") {
return {
dbType: profile.type,
@@ -269,7 +274,7 @@ export function parseConnectionUrl(value: string, preferredProfile?: string): Pa
username: decodeUrlPart(parsed.username),
password: decodeUrlPart(parsed.password),
database: databaseFromPath(parsed.pathname),
- urlParams,
+ urlParams: parsedUrlParams,
ssl: scheme === "mongodb+srv",
connectionString: source,
useMongoUrl: true,
@@ -285,8 +290,8 @@ export function parseConnectionUrl(value: string, preferredProfile?: string): Pa
username: decodeUrlPart(parsed.username),
password: decodeUrlPart(parsed.password),
database: databaseFromPath(parsed.pathname),
- urlParams,
- ssl: scheme === "rediss" || scheme === "https" || urlParamsRequireTls(profile.type, urlParams),
+ urlParams: parsedUrlParams,
+ ssl: scheme === "rediss" || scheme === "https" || urlParamsRequireTls(profile.type, parsedUrlParams),
};
}
diff --git a/crates/dbx-core/src/db/redis_driver.rs b/crates/dbx-core/src/db/redis_driver.rs
index fc1c03b211..8117b61e64 100644
--- a/crates/dbx-core/src/db/redis_driver.rs
+++ b/crates/dbx-core/src/db/redis_driver.rs
@@ -77,6 +77,7 @@ pub struct RedisClusterPool {
pub connection: Mutex<ClusterConnection>,
pub seed_nodes: Vec<RedisNodeEndpoint>,
pub tls: bool,
+ pub tls_insecure: bool,
pub username: String,
pub password: String,
}
@@ -111,7 +112,7 @@ pub async fn connect_sentinel(config: &ConnectionConfig) -> Result<redis::aio::M
let nodes = redis_sentinel_nodes(config)?;
let mut sentinel = Sentinel::build(nodes).map_err(|e| format!("Redis Sentinel connection failed: {e}"))?;
let node_connection_info = SentinelNodeConnectionInfo {
- tls_mode: if config.ssl { Some(TlsMode::Secure) } else { None },
+ tls_mode: redis_tls_mode(config.ssl, config.redis_tls_insecure()),
redis_connection_info: Some(redis_connection_info(&config.username, &config.password, 0)),
};
let client = tokio::time::timeout(
@@ -130,7 +131,15 @@ pub async fn connect_cluster(config: &ConnectionConfig) -> Result<RedisClusterPo
let cluster_nodes: Vec<ConnectionInfo> = seed_nodes
.iter()
.map(|endpoint| {
- connection_info(&endpoint.host, endpoint.port, config.ssl, &config.username, &config.password, 0)
+ connection_info(
+ &endpoint.host,
+ endpoint.port,
+ config.ssl,
+ config.redis_tls_insecure(),
+ &config.username,
+ &config.password,
+ 0,
+ )
})
.collect();
let client = ClusterClient::new(cluster_nodes).map_err(|e| format!("Redis cluster connection failed: {e}"))?;
@@ -148,6 +157,7 @@ pub async fn connect_cluster(config: &ConnectionConfig) -> Result<RedisClusterPo
connection: Mutex::new(con),
seed_nodes,
tls: config.ssl,
+ tls_insecure: config.redis_tls_insecure(),
username: config.username.clone(),
password: config.password.clone(),
})
@@ -189,6 +199,7 @@ fn redis_sentinel_node_connection_info(config: &ConnectionConfig, endpoint: &str
&host,
port,
config.redis_sentinel_tls,
+ config.redis_tls_insecure(),
&config.redis_sentinel_username,
&config.redis_sentinel_password,
0,
@@ -226,15 +237,33 @@ fn redis_node_endpoints(
.collect()
}
-fn connection_info(host: &str, port: u16, tls: bool, username: &str, password: &str, db: i64) -> ConnectionInfo {
+fn connection_info(
+ host: &str,
+ port: u16,
+ tls: bool,
+ insecure: bool,
+ username: &str,
+ password: &str,
+ db: i64,
+) -> ConnectionInfo {
let addr = if tls {
- ConnectionAddr::TcpTls { host: host.to_string(), port, insecure: false, tls_params: None }
+ ConnectionAddr::TcpTls { host: host.to_string(), port, insecure, tls_params: None }
} else {
ConnectionAddr::Tcp(host.to_string(), port)
};
ConnectionInfo { addr, redis: redis_connection_info(username, password, db) }
}
+fn redis_tls_mode(tls: bool, insecure: bool) -> Option<TlsMode> {
+ if !tls {
+ None
+ } else if insecure {
+ Some(TlsMode::Insecure)
+ } else {
+ Some(TlsMode::Secure)
+ }
+}
+
fn redis_connection_info(username: &str, password: &str, db: i64) -> RedisConnectionInfo {
RedisConnectionInfo {
db,
@@ -300,11 +329,13 @@ async fn connect_client(client: redis::Client) -> Result<redis::aio::Multiplexed
pub async fn connect_direct_node(
endpoint: &RedisNodeEndpoint,
tls: bool,
+ insecure: bool,
username: &str,
password: &str,
) -> Result<redis::aio::MultiplexedConnection, String> {
- let client = redis::Client::open(connection_info(&endpoint.host, endpoint.port, tls, username, password, 0))
- .map_err(|e| format!("Redis connection failed: {e}"))?;
+ let client =
+ redis::Client::open(connection_info(&endpoint.host, endpoint.port, tls, insecure, username, password, 0))
+ .map_err(|e| format!("Redis connection failed: {e}"))?;
connect_client(client).await
}
@@ -427,7 +458,8 @@ pub async fn scan_cluster_keys_page(
let total_keys = cluster_total_keys(pool, &master_nodes).await;
for index in node_index..master_nodes.len() {
let endpoint = &master_nodes[index];
- let mut con = connect_direct_node(endpoint, pool.tls, &pool.username, &pool.password).await?;
+ let mut con =
+ connect_direct_node(endpoint, pool.tls, pool.tls_insecure, &pool.username, &pool.password).await?;
let current_cursor = if index == node_index { node_cursor } else { 0 };
let result = scan_keys_page(&mut con, current_cursor, pattern, count).await?;
if !result.keys.is_empty() {
@@ -472,7 +504,8 @@ pub async fn scan_cluster_values_page(
let total_keys = cluster_total_keys(pool, &master_nodes).await;
for index in node_index..master_nodes.len() {
let endpoint = &master_nodes[index];
- let mut con = connect_direct_node(endpoint, pool.tls, &pool.username, &pool.password).await?;
+ let mut con =
+ connect_direct_node(endpoint, pool.tls, pool.tls_insecure, &pool.username, &pool.password).await?;
let current_cursor = if index == node_index { node_cursor } else { 0 };
let result = scan_values_page(&mut con, current_cursor, pattern, query, count).await?;
if !result.keys.is_empty() {
@@ -498,13 +531,14 @@ pub async fn scan_cluster_values_page(
}
pub async fn cluster_master_nodes(pool: &RedisClusterPool) -> Result<Vec<RedisNodeEndpoint>, String> {
- cluster_master_nodes_from_seeds(&pool.seed_nodes, pool.tls, &pool.username, &pool.password).await
+ cluster_master_nodes_from_seeds(&pool.seed_nodes, pool.tls, pool.tls_insecure, &pool.username, &pool.password).await
}
pub async fn flush_cluster(pool: &RedisClusterPool) -> Result<(), String> {
let master_nodes = cluster_master_nodes(pool).await?;
for endpoint in master_nodes {
- let mut con = connect_direct_node(&endpoint, pool.tls, &pool.username, &pool.password).await?;
+ let mut con =
+ connect_direct_node(&endpoint, pool.tls, pool.tls_insecure, &pool.username, &pool.password).await?;
flush_db(&mut con).await?;
}
Ok(())
@@ -513,7 +547,9 @@ pub async fn flush_cluster(pool: &RedisClusterPool) -> Result<(), String> {
async fn cluster_total_keys(pool: &RedisClusterPool, master_nodes: &[RedisNodeEndpoint]) -> u64 {
let mut total = 0;
for endpoint in master_nodes {
- let Ok(mut con) = connect_direct_node(endpoint, pool.tls, &pool.username, &pool.password).await else {
+ let Ok(mut con) =
+ connect_direct_node(endpoint, pool.tls, pool.tls_insecure, &pool.username, &pool.password).await
+ else {
continue;
};
total += redis::cmd("DBSIZE").query_async::<u64>(&mut con).await.unwrap_or(0);
@@ -524,12 +560,13 @@ async fn cluster_total_keys(pool: &RedisClusterPool, master_nodes: &[RedisNodeEn
async fn cluster_master_nodes_from_seeds(
seed_nodes: &[RedisNodeEndpoint],
tls: bool,
+ insecure: bool,
username: &str,
password: &str,
) -> Result<Vec<RedisNodeEndpoint>, String> {
let mut last_error = None;
for endpoint in seed_nodes {
- let mut con = match connect_direct_node(endpoint, tls, username, password).await {
+ let mut con = match connect_direct_node(endpoint, tls, insecure, username, password).await {
Ok(con) => con,
Err(err) => {
last_error = Some(err);
@@ -1403,12 +1440,14 @@ fn parse_scan_members(raw: RedisRawValue) -> Result<(u64, Vec<serde_json::Value>
#[cfg(test)]
mod tests {
use super::{
- classify_command, decode_cluster_cursor, encode_cluster_cursor, is_redis_json_type, parse_cluster_slots,
- parse_command_argv, parse_database_count, parse_redis_endpoint, parse_scan_keys, parse_stream_entries,
- redis_command_raw_to_json, redis_json_raw_to_json, redis_json_value_preview, redis_key_bytes_to_display,
- redis_key_bytes_to_raw, redis_key_raw_to_bytes, redis_key_value_preview, redis_raw_to_json,
- redis_value_contains_binary, redis_value_matches_query, RedisCommandSafety, RedisNodeEndpoint, RedisRawValue,
+ classify_command, connection_info, decode_cluster_cursor, encode_cluster_cursor, is_redis_json_type,
+ parse_cluster_slots, parse_command_argv, parse_database_count, parse_redis_endpoint, parse_scan_keys,
+ parse_stream_entries, redis_command_raw_to_json, redis_json_raw_to_json, redis_json_value_preview,
+ redis_key_bytes_to_display, redis_key_bytes_to_raw, redis_key_raw_to_bytes, redis_key_value_preview,
+ redis_raw_to_json, redis_value_contains_binary, redis_value_matches_query, RedisCommandSafety,
+ RedisNodeEndpoint, RedisRawValue,
};
+ use redis::ConnectionAddr;
fn bulk(value: &str) -> RedisRawValue {
RedisRawValue::BulkString(value.as_bytes().to_vec())
@@ -1586,6 +1625,13 @@ mod tests {
assert_eq!(parse_redis_endpoint("::1", 26379).unwrap(), ("::1".to_string(), 26379));
}
+ #[test]
+ fn redis_connection_info_marks_tls_as_insecure_when_requested() {
+ let info = connection_info("cache.example.com", 6379, true, true, "default", "secret", 0);
+
+ assert!(matches!(info.addr, ConnectionAddr::TcpTls { insecure: true, .. }));
+ }
+
#[test]
fn encodes_and_decodes_cluster_scan_cursor() {
let encoded = encode_cluster_cursor(12, 3456).unwrap();
diff --git a/crates/dbx-core/src/models/connection.rs b/crates/dbx-core/src/models/connection.rs
index a34a0a318d..e90ae211e3 100644
--- a/crates/dbx-core/src/models/connection.rs
+++ b/crates/dbx-core/src/models/connection.rs
@@ -285,6 +285,10 @@ impl ConnectionConfig {
&& self.redis_connection_mode.as_deref().is_some_and(|mode| mode.eq_ignore_ascii_case("cluster"))
}
+ pub fn redis_tls_insecure(&self) -> bool {
+ self.db_type == DatabaseType::Redis && redis_url_params_enable_insecure(self.url_params.as_deref())
+ }
+
pub fn connection_url(&self) -> String {
self.connection_url_with_host(&self.host, self.port)
}
@@ -306,7 +310,8 @@ impl ConnectionConfig {
DatabaseType::Access => self.host.clone(),
DatabaseType::Redis => {
let scheme = if self.ssl { "rediss" } else { "redis" };
- format!("{scheme}://{host}:{port}/")
+ let fragment = self.redis_tls_insecure_fragment();
+ format!("{scheme}://{host}:{port}/{fragment}")
}
DatabaseType::Mysql | DatabaseType::Doris | DatabaseType::StarRocks => {
let suffix = if params.is_empty() { String::new() } else { format!("?{params}") };
@@ -399,12 +404,13 @@ impl ConnectionConfig {
DatabaseType::Access => self.host.clone(),
DatabaseType::Redis => {
let scheme = if self.ssl { "rediss" } else { "redis" };
+ let fragment = self.redis_tls_insecure_fragment();
if self.username.is_empty() && self.password.is_empty() {
- format!("{scheme}://{host}:{port}/")
+ format!("{scheme}://{host}:{port}/{fragment}")
} else if self.username.is_empty() {
- format!("{scheme}://:{password}@{host}:{port}/")
+ format!("{scheme}://:{password}@{host}:{port}/{fragment}")
} else {
- format!("{scheme}://{username}:{password}@{host}:{port}/")
+ format!("{scheme}://{username}:{password}@{host}:{port}/{fragment}")
}
}
DatabaseType::Mysql | DatabaseType::Doris | DatabaseType::StarRocks => {
@@ -569,6 +575,29 @@ impl ConnectionConfig {
pub fn clickhouse_uses_tls(&self) -> bool {
self.ssl || url_params_contains_flag(self.url_params.as_deref(), "secure", "true")
}
+
+ fn redis_tls_insecure_fragment(&self) -> &'static str {
+ if self.ssl && self.redis_tls_insecure() {
+ "#insecure"
+ } else {
+ ""
+ }
+ }
+}
+
+fn redis_url_params_enable_insecure(params: Option<&str>) -> bool {
+ params.unwrap_or("").trim().trim_start_matches('?').split(['&', ';']).any(|part| {
+ let part = part.trim();
+ if part.is_empty() {
+ return false;
+ }
+ let Some((key, value)) = part.split_once('=') else {
+ return part.eq_ignore_ascii_case("insecure");
+ };
+ let key = key.trim();
+ matches!(key.to_ascii_lowercase().as_str(), "insecure" | "tls_insecure" | "accept_invalid_certs")
+ && matches!(value.trim().to_ascii_lowercase().as_str(), "true" | "1" | "yes" | "insecure")
+ })
}
fn url_params_contains_flag(params: Option<&str>, key: &str, expected: &str) -> bool {
@@ -1425,6 +1454,26 @@ mod tests {
assert!(!url.contains("redis-secret"));
}
+ #[test]
+ fn redis_tls_insecure_url_params_append_insecure_fragment() {
+ let mut config = mysql_config("default", "secret", Some("0"));
+ config.db_type = DatabaseType::Redis;
+ config.ssl = true;
+ config.url_params = Some("insecure=true".to_string());
+
+ assert_eq!(config.connection_url(), "rediss://default:[email protected]:2883/#insecure");
+ assert_eq!(config.redacted_connection_url(), "rediss://10.1.2.3:2883/#insecure");
+ }
+
+ #[test]
+ fn redis_insecure_url_params_do_not_affect_plain_tcp() {
+ let mut config = mysql_config("default", "secret", Some("0"));
+ config.db_type = DatabaseType::Redis;
+ config.url_params = Some("insecure=true".to_string());
+
+ assert_eq!(config.connection_url(), "redis://default:[email protected]:2883/");
+ }
+
#[test]
fn redacted_mongodb_url_keeps_custom_params_without_credentials() {
let mut config = mongodb_config("root", "secret", Some("admin"));
diff --git a/packages/app-tests/connectionUrl.test.ts b/packages/app-tests/connectionUrl.test.ts
index 96af400a9b..f7b54b45cf 100644
--- a/packages/app-tests/connectionUrl.test.ts
+++ b/packages/app-tests/connectionUrl.test.ts
@@ -35,6 +35,19 @@ test("parses mysql TLS URL params into the SSL switch state", () => {
assert.equal(parseConnectionUrl("mysql://[email protected]:4000/test?require_ssl=true").ssl, true);
});
+test("parses Redis insecure TLS URL fragments into URL params", () => {
+ const parsed = parseConnectionUrl("rediss://default:[email protected]:6379/0#insecure");
+
+ assert.equal(parsed.dbType, "redis");
+ assert.equal(parsed.host, "redis.example.com");
+ assert.equal(parsed.port, 6379);
+ assert.equal(parsed.username, "default");
+ assert.equal(parsed.password, "secret");
+ assert.equal(parsed.database, "0");
+ assert.equal(parsed.urlParams, "insecure=true");
+ assert.equal(parsed.ssl, true);
+});
+
test("parses JDBC URLs by using the inner database URL", () => {
const postgres = parseConnectionUrl("jdbc:postgresql://alice:[email protected]:5433/app?sslmode=require");
assert.equal(postgres.dbType, "postgres");