feat(ssh): support custom SSH agent socket path
This commit is contained in:
1 parent
c4c427fb67
commit
00541291e3
13 files changed
+56
-5
No files matched your search
@@ -65,6 +65,7 @@ async fn connect_and_authenticate(
|
||||
ssh_key_path: &str,
|
||||
ssh_key_passphrase: &str,
|
||||
use_ssh_agent: bool,
|
||||
ssh_agent_sock_path: &str,
|
||||
connect_timeout_secs: u64,
|
||||
) -> Result<Handle<SshClient>, String> {
|
||||
let config = Arc::new(ssh_client_config());
|
||||
@@ -108,7 +109,7 @@ async fn connect_and_authenticate(
|
||||
return Err("SSH password authentication failed".to_string());
|
||||
}
|
||||
} else if use_ssh_agent {
|
||||
match try_authenticate_with_agent(&mut session, ssh_user, &connect_timeout).await {
|
||||
match try_authenticate_with_agent(&mut session, ssh_user, ssh_agent_sock_path, &connect_timeout).await {
|
||||
Ok(()) => {}
|
||||
Err(agent_err) => return Err(agent_err),
|
||||
}
|
||||
@@ -124,13 +125,26 @@ async fn connect_and_authenticate(
|
||||
async fn try_authenticate_with_agent(
|
||||
session: &mut Handle<SshClient>,
|
||||
ssh_user: &str,
|
||||
ssh_agent_sock_path: &str,
|
||||
connect_timeout: &Duration,
|
||||
) -> Result<(), String> {
|
||||
#[cfg(unix)]
|
||||
let mut agent = match AgentClient::connect_env().await {
|
||||
Ok(a) => a,
|
||||
Err(e) => {
|
||||
return Err(format!("No SSH password or key provided, and ssh-agent is unavailable: {e}"));
|
||||
let mut agent = if ssh_agent_sock_path.is_empty() {
|
||||
match AgentClient::connect_env().await {
|
||||
Ok(a) => a,
|
||||
Err(e) => {
|
||||
return Err(format!("No SSH password or key provided, and ssh-agent is unavailable: {e}"));
|
||||
}
|
||||
}
|
||||
} else {
|
||||
match AgentClient::connect_uds(ssh_agent_sock_path).await {
|
||||
Ok(a) => a,
|
||||
Err(e) => {
|
||||
return Err(format!(
|
||||
"No SSH password or key provided, and ssh-agent at '{}' is unavailable: {e}",
|
||||
ssh_agent_sock_path
|
||||
));
|
||||
}
|
||||
}
|
||||
};
|
||||
|
||||
@@ -430,6 +444,7 @@ async fn tunnel_reconnect_loop(
|
||||
ssh_key_path: String,
|
||||
ssh_key_passphrase: String,
|
||||
use_ssh_agent: bool,
|
||||
ssh_agent_sock_path: String,
|
||||
connect_timeout_secs: u64,
|
||||
listener: TcpListener,
|
||||
remote_host: String,
|
||||
@@ -464,6 +479,7 @@ async fn tunnel_reconnect_loop(
|
||||
&ssh_key_path,
|
||||
&ssh_key_passphrase,
|
||||
use_ssh_agent,
|
||||
&ssh_agent_sock_path,
|
||||
connect_timeout_secs,
|
||||
)
|
||||
.await
|
||||
@@ -533,6 +549,7 @@ impl TunnelManager {
|
||||
ssh_key_path: &str,
|
||||
ssh_key_passphrase: &str,
|
||||
use_ssh_agent: bool,
|
||||
ssh_agent_sock_path: &str,
|
||||
connect_timeout_secs: u64,
|
||||
remote_host: &str,
|
||||
remote_port: u16,
|
||||
@@ -555,6 +572,7 @@ impl TunnelManager {
|
||||
ssh_key_path,
|
||||
ssh_key_passphrase,
|
||||
use_ssh_agent,
|
||||
ssh_agent_sock_path,
|
||||
connect_timeout_secs,
|
||||
remote_host,
|
||||
remote_port,
|
||||
@@ -624,6 +642,7 @@ impl TunnelManager {
|
||||
&hop.key_path,
|
||||
&hop.key_passphrase,
|
||||
hop.use_ssh_agent,
|
||||
&hop.ssh_agent_sock_path,
|
||||
effective_hop_timeout(hop),
|
||||
&target_host,
|
||||
target_port,
|
||||
@@ -671,6 +690,7 @@ async fn spawn_tunnel(
|
||||
ssh_key_path: &str,
|
||||
ssh_key_passphrase: &str,
|
||||
use_ssh_agent: bool,
|
||||
ssh_agent_sock_path: &str,
|
||||
connect_timeout_secs: u64,
|
||||
remote_host: &str,
|
||||
remote_port: u16,
|
||||
@@ -691,6 +711,7 @@ async fn spawn_tunnel(
|
||||
ssh_key_path,
|
||||
ssh_key_passphrase,
|
||||
use_ssh_agent,
|
||||
ssh_agent_sock_path,
|
||||
connect_timeout_secs,
|
||||
)
|
||||
.await?;
|
||||
@@ -704,6 +725,7 @@ async fn spawn_tunnel(
|
||||
ssh_key_path.to_string(),
|
||||
ssh_key_passphrase.to_string(),
|
||||
use_ssh_agent,
|
||||
ssh_agent_sock_path.to_string(),
|
||||
connect_timeout_secs,
|
||||
listener,
|
||||
remote_host.to_string(),
|
||||
|
||||
@@ -59,6 +59,7 @@ pub async fn start_transport_layers(
|
||||
&ssh.key_path,
|
||||
&ssh.key_passphrase,
|
||||
ssh.use_ssh_agent,
|
||||
&ssh.ssh_agent_sock_path,
|
||||
effective_ssh_connect_timeout_secs(ssh.connect_timeout_secs),
|
||||
&target_endpoint.host,
|
||||
target_endpoint.port,
|
||||
|
||||
@@ -148,6 +148,11 @@ pub struct SshTunnelConfig {
|
||||
pub expose_lan: bool,
|
||||
#[serde(default)]
|
||||
pub use_ssh_agent: bool,
|
||||
/// Custom SSH agent socket path (e.g. `~/.ssh/agent.sock`).
|
||||
/// When set and `use_ssh_agent` is true, this path is used instead of
|
||||
/// the `SSH_AUTH_SOCK` environment variable.
|
||||
#[serde(default)]
|
||||
pub ssh_agent_sock_path: String,
|
||||
}
|
||||
|
||||
#[derive(Debug, Clone, Serialize, Deserialize, PartialEq, Eq)]
|
||||
|
||||
Reference in new issue
Block a user