Skip to content

Commit 0823297

Browse files
acmoreclaude
andcommitted
feat: hardcode ServerAliveInterval 5 / ServerAliveCountMax 10 in SSH config
Co-Authored-By: Claude Opus 4.6 <noreply@anthropic.com>
1 parent fe954be commit 0823297

2 files changed

Lines changed: 45 additions & 2 deletions

File tree

internal/cli/ssh.go

Lines changed: 5 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -438,9 +438,12 @@ func ensureSSHConfigEntry(hostAlias, sessionName, namespace, user string, remote
438438
" UserKnownHostsFile /dev/null",
439439
" ProxyCommand " + proxyCmd,
440440
}
441+
// Hardcoded keepalive values for the proxy path — sshSpec values are
442+
// intentionally ignored here because the proxy needs tighter detection
443+
// than the general SSH config defaults provide.
441444
blockLines = append(blockLines,
442-
fmt.Sprintf(" ServerAliveInterval %d", sshSpec.KeepAliveInterval),
443-
fmt.Sprintf(" ServerAliveCountMax %d", sshSpec.KeepAliveCountMax),
445+
" ServerAliveInterval 5",
446+
" ServerAliveCountMax 10",
444447
" TCPKeepAlive yes",
445448
" LogLevel ERROR",
446449
end,

internal/cli/ssh_config_test.go

Lines changed: 40 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -50,3 +50,43 @@ func TestEnsureSSHConfigEntryIncludesNamespaceInProxyCommand(t *testing.T) {
5050
t.Fatalf("interactive ssh host entry must not include LocalForward directives: %s", text)
5151
}
5252
}
53+
54+
func TestEnsureSSHConfigEntryUsesProxyKeepaliveValues(t *testing.T) {
55+
home := t.TempDir()
56+
origHome := os.Getenv("HOME")
57+
if err := os.Setenv("HOME", home); err != nil {
58+
t.Fatalf("set HOME: %v", err)
59+
}
60+
defer func() {
61+
_ = os.Setenv("HOME", origHome)
62+
}()
63+
64+
// Pass config defaults (10/30) — the written config should still use 5/10
65+
_, err := ensureSSHConfigEntry(
66+
"okdev-test2",
67+
"test-session2",
68+
"dev-ns",
69+
"root",
70+
22,
71+
"/tmp/id_ed25519",
72+
"/tmp/.okdev.yaml",
73+
nil,
74+
config.SSHSpec{KeepAliveInterval: 10, KeepAliveCountMax: 30},
75+
)
76+
if err != nil {
77+
t.Fatalf("ensureSSHConfigEntry: %v", err)
78+
}
79+
80+
cfgPath := filepath.Join(home, ".ssh", "config")
81+
b, err := os.ReadFile(cfgPath)
82+
if err != nil {
83+
t.Fatalf("read ssh config: %v", err)
84+
}
85+
text := string(b)
86+
if !strings.Contains(text, "ServerAliveInterval 5") {
87+
t.Fatalf("expected ServerAliveInterval 5, got: %s", text)
88+
}
89+
if !strings.Contains(text, "ServerAliveCountMax 10") {
90+
t.Fatalf("expected ServerAliveCountMax 10, got: %s", text)
91+
}
92+
}

0 commit comments

Comments
 (0)