Skip to content

Commit 7a44e51

Browse files
committed
fix: [#428] restore SSH private key permission normalization (confirmed root cause)
The SSH connectivity timeout in GitHub runners was caused by files checked out with world/group-readable permissions. OpenSSH silently rejects private keys that aren't exactly mode 0600. The CI test failure when permissions normalization was disabled confirms this is the actual root cause, not a flaky test. Normalizing to 0600 ensures SSH keys work regardless of git checkout permissions.
1 parent f081976 commit 7a44e51

1 file changed

Lines changed: 16 additions & 3 deletions

File tree

tests/ssh_client/mod.rs

Lines changed: 16 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -134,9 +134,22 @@ impl Default for SshTestBuilder {
134134
}
135135

136136
#[cfg(unix)]
137-
fn normalize_private_key_permissions(_private_key_path: &std::path::Path) {
138-
// TEMPORARY (CI diagnosis): disabled to verify whether key permission
139-
// normalization is the root cause of the flaky GitHub runner failure.
137+
fn normalize_private_key_permissions(private_key_path: &std::path::Path) {
138+
use std::fs;
139+
use std::os::unix::fs::PermissionsExt;
140+
141+
if let Ok(metadata) = fs::metadata(private_key_path) {
142+
let perms = metadata.permissions();
143+
let mode = perms.mode();
144+
145+
// SSH requires private keys to be mode 0600 (owner read/write only).
146+
// GitHub runners checkout files with permissive permissions (e.g., 0644),
147+
// causing OpenSSH to silently reject the key. Normalize to 0600.
148+
if mode & 0o077 != 0 {
149+
let restricted = fs::Permissions::from_mode(0o600);
150+
drop(fs::set_permissions(private_key_path, restricted));
151+
}
152+
}
140153
}
141154

142155
#[cfg(not(unix))]

0 commit comments

Comments
 (0)