Skip to content

Commit a6c7644

Browse files
committed
fix: Check SSH_AUTH_SOCK file existence before agent connection in jump host auth
When SSH_AUTH_SOCK environment variable points to a non-existent socket file, the jump host authentication would fail instead of falling back to key file authentication. This fix adds a file existence check before attempting to connect to the SSH agent, matching the behavior in ssh/auth.rs. This resolves an issue where cluster mode commands with jump_host configuration would fail when SSH_AUTH_SOCK was set but the socket file didn't exist.
1 parent 524ce6b commit a6c7644

1 file changed

Lines changed: 18 additions & 4 deletions

File tree

src/jump/chain/auth.rs

Lines changed: 18 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -81,11 +81,25 @@ pub(super) async fn determine_auth_method(
8181

8282
// Cache agent availability check to avoid querying the agent multiple times
8383
// (each query involves socket connection and protocol handshake)
84+
// IMPORTANT: First verify the socket file exists before attempting connection
85+
// to avoid hangs or delays when SSH_AUTH_SOCK points to a non-existent path
8486
#[cfg(not(target_os = "windows"))]
85-
let agent_available = if std::env::var("SSH_AUTH_SOCK").is_ok() {
86-
agent_has_identities().await
87-
} else {
88-
false
87+
let agent_available = {
88+
if let Ok(socket_path) = std::env::var("SSH_AUTH_SOCK") {
89+
// Verify the socket actually exists before attempting connection
90+
let path = std::path::Path::new(&socket_path);
91+
if path.exists() {
92+
agent_has_identities().await
93+
} else {
94+
debug!(
95+
"SSH_AUTH_SOCK points to non-existent socket: {}, falling back to key files",
96+
socket_path
97+
);
98+
false
99+
}
100+
} else {
101+
false
102+
}
89103
};
90104
#[cfg(target_os = "windows")]
91105
let agent_available = false;

0 commit comments

Comments
 (0)