Skip to content

feat(agent): Add SSH max timeout option for coder agent #6596

New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Merged
merged 2 commits into from
Mar 15, 2023
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
10 changes: 7 additions & 3 deletions agent/agent.go
Original file line number Diff line number Diff line change
Expand Up @@ -78,6 +78,7 @@ type Options struct {
EnvironmentVariables map[string]string
Logger slog.Logger
AgentPorts map[int]string
SSHMaxTimeout time.Duration
}

type Client interface {
Expand Down Expand Up @@ -126,6 +127,7 @@ func New(options Options) io.Closer {
lifecycleReported: make(chan codersdk.WorkspaceAgentLifecycle, 1),
ignorePorts: options.AgentPorts,
connStatsChan: make(chan *agentsdk.Stats, 1),
sshMaxTimeout: options.SSHMaxTimeout,
}
a.init(ctx)
return a
Expand Down Expand Up @@ -153,9 +155,10 @@ type agent struct {

envVars map[string]string
// metadata is atomic because values can change after reconnection.
metadata atomic.Value
sessionToken atomic.Pointer[string]
sshServer *ssh.Server
metadata atomic.Value
sessionToken atomic.Pointer[string]
sshServer *ssh.Server
sshMaxTimeout time.Duration

lifecycleUpdate chan struct{}
lifecycleReported chan codersdk.WorkspaceAgentLifecycle
Expand Down Expand Up @@ -780,6 +783,7 @@ func (a *agent) init(ctx context.Context) {
_ = session.Exit(1)
},
},
MaxTimeout: a.sshMaxTimeout,
}

go a.runLoop(ctx)
Expand Down
13 changes: 8 additions & 5 deletions cli/agent.go
Original file line number Diff line number Diff line change
Expand Up @@ -31,10 +31,11 @@ import (

func workspaceAgent() *cobra.Command {
var (
auth string
logDir string
pprofAddress string
noReap bool
auth string
logDir string
pprofAddress string
noReap bool
sshMaxTimeout time.Duration
)
cmd := &cobra.Command{
Use: "agent",
Expand Down Expand Up @@ -208,7 +209,8 @@ func workspaceAgent() *cobra.Command {
EnvironmentVariables: map[string]string{
"GIT_ASKPASS": executablePath,
},
AgentPorts: agentPorts,
AgentPorts: agentPorts,
SSHMaxTimeout: sshMaxTimeout,
})
<-ctx.Done()
return closer.Close()
Expand All @@ -219,6 +221,7 @@ func workspaceAgent() *cobra.Command {
cliflag.StringVarP(cmd.Flags(), &logDir, "log-dir", "", "CODER_AGENT_LOG_DIR", os.TempDir(), "Specify the location for the agent log files")
cliflag.StringVarP(cmd.Flags(), &pprofAddress, "pprof-address", "", "CODER_AGENT_PPROF_ADDRESS", "127.0.0.1:6060", "The address to serve pprof.")
cliflag.BoolVarP(cmd.Flags(), &noReap, "no-reap", "", "", false, "Do not start a process reaper.")
cliflag.DurationVarP(cmd.Flags(), &sshMaxTimeout, "ssh-max-timeout", "", "CODER_AGENT_SSH_MAX_TIMEOUT", time.Duration(0), "Specify the max timeout for a SSH connection")
return cmd
}

Expand Down
18 changes: 10 additions & 8 deletions cli/testdata/coder_agent_--help.golden
Original file line number Diff line number Diff line change
Expand Up @@ -2,14 +2,16 @@ Usage:
coder agent [flags]

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

Global Flags:
--global-config coder Path to the global coder config directory.
Expand Down