Skip to content

Commit 7076dee

Browse files
authored
feat(agent): Add SSH max timeout option for coder agent (#6596)
* feat(agent): Add SSH max timeout option for coder agent * Fix lint and update test golden snapshot
1 parent 2f3848e commit 7076dee

File tree

3 files changed

+25
-16
lines changed

3 files changed

+25
-16
lines changed

agent/agent.go

Lines changed: 7 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -78,6 +78,7 @@ type Options struct {
7878
EnvironmentVariables map[string]string
7979
Logger slog.Logger
8080
AgentPorts map[int]string
81+
SSHMaxTimeout time.Duration
8182
}
8283

8384
type Client interface {
@@ -126,6 +127,7 @@ func New(options Options) io.Closer {
126127
lifecycleReported: make(chan codersdk.WorkspaceAgentLifecycle, 1),
127128
ignorePorts: options.AgentPorts,
128129
connStatsChan: make(chan *agentsdk.Stats, 1),
130+
sshMaxTimeout: options.SSHMaxTimeout,
129131
}
130132
a.init(ctx)
131133
return a
@@ -153,9 +155,10 @@ type agent struct {
153155

154156
envVars map[string]string
155157
// metadata is atomic because values can change after reconnection.
156-
metadata atomic.Value
157-
sessionToken atomic.Pointer[string]
158-
sshServer *ssh.Server
158+
metadata atomic.Value
159+
sessionToken atomic.Pointer[string]
160+
sshServer *ssh.Server
161+
sshMaxTimeout time.Duration
159162

160163
lifecycleUpdate chan struct{}
161164
lifecycleReported chan codersdk.WorkspaceAgentLifecycle
@@ -780,6 +783,7 @@ func (a *agent) init(ctx context.Context) {
780783
_ = session.Exit(1)
781784
},
782785
},
786+
MaxTimeout: a.sshMaxTimeout,
783787
}
784788

785789
go a.runLoop(ctx)

cli/agent.go

Lines changed: 8 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -31,10 +31,11 @@ import (
3131

3232
func workspaceAgent() *cobra.Command {
3333
var (
34-
auth string
35-
logDir string
36-
pprofAddress string
37-
noReap bool
34+
auth string
35+
logDir string
36+
pprofAddress string
37+
noReap bool
38+
sshMaxTimeout time.Duration
3839
)
3940
cmd := &cobra.Command{
4041
Use: "agent",
@@ -208,7 +209,8 @@ func workspaceAgent() *cobra.Command {
208209
EnvironmentVariables: map[string]string{
209210
"GIT_ASKPASS": executablePath,
210211
},
211-
AgentPorts: agentPorts,
212+
AgentPorts: agentPorts,
213+
SSHMaxTimeout: sshMaxTimeout,
212214
})
213215
<-ctx.Done()
214216
return closer.Close()
@@ -219,6 +221,7 @@ func workspaceAgent() *cobra.Command {
219221
cliflag.StringVarP(cmd.Flags(), &logDir, "log-dir", "", "CODER_AGENT_LOG_DIR", os.TempDir(), "Specify the location for the agent log files")
220222
cliflag.StringVarP(cmd.Flags(), &pprofAddress, "pprof-address", "", "CODER_AGENT_PPROF_ADDRESS", "127.0.0.1:6060", "The address to serve pprof.")
221223
cliflag.BoolVarP(cmd.Flags(), &noReap, "no-reap", "", "", false, "Do not start a process reaper.")
224+
cliflag.DurationVarP(cmd.Flags(), &sshMaxTimeout, "ssh-max-timeout", "", "CODER_AGENT_SSH_MAX_TIMEOUT", time.Duration(0), "Specify the max timeout for a SSH connection")
222225
return cmd
223226
}
224227

cli/testdata/coder_agent_--help.golden

Lines changed: 10 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -2,14 +2,16 @@ Usage:
22
coder agent [flags]
33

44
Flags:
5-
--auth string Specify the authentication type to use for the agent.
6-
Consumes $CODER_AGENT_AUTH (default "token")
7-
-h, --help help for agent
8-
--log-dir string Specify the location for the agent log files.
9-
Consumes $CODER_AGENT_LOG_DIR (default "/tmp")
10-
--no-reap Do not start a process reaper.
11-
--pprof-address string The address to serve pprof.
12-
Consumes $CODER_AGENT_PPROF_ADDRESS (default "127.0.0.1:6060")
5+
--auth string Specify the authentication type to use for the agent.
6+
Consumes $CODER_AGENT_AUTH (default "token")
7+
-h, --help help for agent
8+
--log-dir string Specify the location for the agent log files.
9+
Consumes $CODER_AGENT_LOG_DIR (default "/tmp")
10+
--no-reap Do not start a process reaper.
11+
--pprof-address string The address to serve pprof.
12+
Consumes $CODER_AGENT_PPROF_ADDRESS (default "127.0.0.1:6060")
13+
--ssh-max-timeout duration Specify the max timeout for a SSH connection.
14+
Consumes $CODER_AGENT_SSH_MAX_TIMEOUT
1315

1416
Global Flags:
1517
--global-config coder Path to the global coder config directory.

0 commit comments

Comments
 (0)