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。
TypeScript aicliclickhousedatabasedatabase-clientdatabase-managementdockerguimcpmongodbmysqlpostgresqlredisrustsql-serversqlitetaurivue
fix(ssh): support Windows OpenSSH agent pipes
t8y2de827a922edb
diff --git a/crates/dbx-drivers/src/db/ssh_tunnel.rs b/crates/dbx-drivers/src/db/ssh_tunnel.rsindex 93b315c7bc..2c270fec63 100644--- a/crates/dbx-drivers/src/db/ssh_tunnel.rs+++ b/crates/dbx-drivers/src/db/ssh_tunnel.rs@@ -9,6 +9,8 @@ use std::sync::Arc;use base64::engine::general_purpose::STANDARD as BASE64_STANDARD;use base64::Engine;use russh::client::{self, AuthResult, Config, GexParams, Handle, KeyboardInteractiveAuthResponse};+#[cfg(windows)]+use russh::keys::agent::client::AgentStream;use russh::keys::agent::{client::AgentClient, AgentIdentity};use russh::keys::ssh_key::HashAlg;use russh::keys::{decode_secret_key, key::PrivateKeyWithHashAlg, PrivateKey};@@ -669,6 +671,39 @@ enum AgentAuthenticationOutcome {KeyboardInteractiveRequired,}+#[cfg(any(windows, test))]+const WINDOWS_OPENSSH_AGENT_PIPE: &str = r"\\.\pipe\openssh-ssh-agent";++#[cfg(any(windows, test))]+#[derive(Debug, Clone, PartialEq, Eq)]+enum WindowsSshAgentEndpoint {+ NamedPipe(String),+ Pageant,+}++#[cfg(any(windows, test))]+fn windows_ssh_agent_endpoints(configured_path: &str) -> Vec<WindowsSshAgentEndpoint> {+ let configured_path = configured_path.trim();+ if configured_path.is_empty() {+ vec![+ WindowsSshAgentEndpoint::NamedPipe(WINDOWS_OPENSSH_AGENT_PIPE.to_string()),+ WindowsSshAgentEndpoint::Pageant,+ ]+ } else {+ vec![WindowsSshAgentEndpoint::NamedPipe(configured_path.to_string())]+ }+}++#[cfg(windows)]+impl WindowsSshAgentEndpoint {+ fn label(&self) -> String {+ match self {+ Self::NamedPipe(path) => format!("Windows named pipe '{path}'"),+ Self::Pageant => "Pageant".to_string(),+ }+ }+}+#[cfg(unix)]fn resolve_ssh_agent_socket_path(path: &str) -> String {expand_tilde(path)@@ -680,11 +715,11 @@ fn resolve_ssh_agent_socket_path(path: &str) -> String {async fn try_authenticate_with_agent(session: &mut Handle<SshClient>,ssh_user: &str,- #[cfg_attr(not(unix), allow(unused_variables))] ssh_agent_sock_path: &str,+ ssh_agent_sock_path: &str,connect_timeout: &Duration,) -> Result<AgentAuthenticationOutcome, String> {#[cfg(unix)]- let mut agent = if ssh_agent_sock_path.is_empty() {+ let agent = if ssh_agent_sock_path.is_empty() {match AgentClient::connect_env().await {Ok(a) => a,Err(e) => {@@ -704,14 +739,65 @@ async fn try_authenticate_with_agent(}};+ #[cfg(unix)]+ return authenticate_with_agent_client(session, ssh_user, agent, connect_timeout).await;+#[cfg(windows)]- let mut agent = {- let stream = pageant::PageantStream::new()- .await- .map_err(|e| format!("No SSH password or key provided, and ssh-agent (Pageant) is unavailable: {e}"))?;- AgentClient::connect(stream)- };+ {+ let mut failures = Vec::new();+ for endpoint in windows_ssh_agent_endpoints(ssh_agent_sock_path) {+ let label = endpoint.label();+ let agent: AgentClient<Box<dyn AgentStream + Send + Unpin + 'static>> = match endpoint {+ WindowsSshAgentEndpoint::NamedPipe(path) => {+ match tokio::time::timeout(*connect_timeout, AgentClient::connect_named_pipe(&path)).await {+ Ok(Ok(agent)) => agent.dynamic(),+ Ok(Err(error)) => {+ failures.push(format!("{label} is unavailable: {error}"));+ continue;+ }+ Err(_) => {+ failures.push(format!("{label} connection timed out"));+ continue;+ }+ }+ }+ WindowsSshAgentEndpoint::Pageant => {+ match tokio::time::timeout(*connect_timeout, AgentClient::connect_pageant()).await {+ Ok(Ok(agent)) => agent.dynamic(),+ Ok(Err(error)) => {+ failures.push(format!("{label} is unavailable: {error}"));+ continue;+ }+ Err(_) => {+ failures.push(format!("{label} connection timed out"));+ continue;+ }+ }+ }+ };+ match authenticate_with_agent_client(session, ssh_user, agent, connect_timeout).await {+ Ok(outcome) => return Ok(outcome),+ Err(error) => failures.push(format!("{label}: {error}")),+ }+ }++ return Err(format!(+ "No SSH password or key provided, and all configured Windows ssh-agent transports failed: {}",+ failures.join("; ")+ ));+ }+}++async fn authenticate_with_agent_client<S>(+ session: &mut Handle<SshClient>,+ ssh_user: &str,+ mut agent: AgentClient<S>,+ connect_timeout: &Duration,+) -> Result<AgentAuthenticationOutcome, String>+where+ S: russh::keys::agent::client::AgentStream + Send + Unpin + 'static,+{let identities = match agent.request_identities().await {Ok(ids) if ids.is_empty() => {return Err("No SSH password or key provided, and ssh-agent has no identities".to_string());@@ -1946,6 +2032,7 @@ mod tests {ssh_client_config, tofu_prompt_deadline, HostKeyState, HostKeyVerifier, PlannedTunnel, TunnelEntry, TunnelKind,TunnelManager, TunnelStatus, TOFU_PROMPT_TIMEOUT,};+ use super::{windows_ssh_agent_endpoints, WindowsSshAgentEndpoint, WINDOWS_OPENSSH_AGENT_PIPE};use crate::db::ssh_prompt;use crate::models::connection::{default_ssh_connect_timeout_secs, SshTunnelConfig};use russh::client;@@ -1993,6 +2080,25 @@ mod tests {);}+ #[test]+ fn windows_ssh_agent_defaults_to_openssh_then_pageant() {+ assert_eq!(+ windows_ssh_agent_endpoints(""),+ vec![+ WindowsSshAgentEndpoint::NamedPipe(WINDOWS_OPENSSH_AGENT_PIPE.to_string()),+ WindowsSshAgentEndpoint::Pageant,+ ]+ );+ }++ #[test]+ fn windows_ssh_agent_uses_only_the_configured_pipe() {+ assert_eq!(+ windows_ssh_agent_endpoints(r" \\.\pipe\custom-agent "),+ vec![WindowsSshAgentEndpoint::NamedPipe(r"\\.\pipe\custom-agent".to_string())]+ );+ }+#[test]fn tofu_prompt_deadline_uses_the_actual_prompt_start() {let now = Instant::now();