Skip to content

Commit 1e672a6

Browse files
authored
Merge branch 'main' into matifali/template-push-create
2 parents c9220af + 247f8a9 commit 1e672a6

File tree

7 files changed

+30
-13
lines changed

7 files changed

+30
-13
lines changed

agent/agentssh/agentssh.go

Lines changed: 12 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -105,7 +105,7 @@ func NewServer(ctx context.Context, logger slog.Logger, prometheusRegistry *prom
105105
metrics: metrics,
106106
}
107107

108-
s.srv = &ssh.Server{
108+
srv := &ssh.Server{
109109
ChannelHandlers: map[string]ssh.ChannelHandler{
110110
"direct-tcpip": ssh.DirectTCPIPHandler,
111111
"direct-streamlocal@openssh.com": directStreamLocalHandler,
@@ -149,9 +149,19 @@ func NewServer(ctx context.Context, logger slog.Logger, prometheusRegistry *prom
149149
SubsystemHandlers: map[string]ssh.SubsystemHandler{
150150
"sftp": s.sessionHandler,
151151
},
152-
MaxTimeout: maxTimeout,
153152
}
154153

154+
// The MaxTimeout functionality has been substituted with the introduction of the KeepAlive feature.
155+
// In cases where very short timeouts are set, the SSH server will automatically switch to the connection timeout for both read and write operations.
156+
if maxTimeout >= 3*time.Second {
157+
srv.ClientAliveCountMax = 3
158+
srv.ClientAliveInterval = maxTimeout / time.Duration(srv.ClientAliveCountMax)
159+
srv.MaxTimeout = 0
160+
} else {
161+
srv.MaxTimeout = maxTimeout
162+
}
163+
164+
s.srv = srv
155165
return s, nil
156166
}
157167

agent/agentssh/agentssh_internal_test.go

Lines changed: 4 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -191,3 +191,7 @@ func (testSSHContext) Permissions() *gliderssh.Permissions {
191191
func (testSSHContext) SetValue(_, _ interface{}) {
192192
panic("not implemented")
193193
}
194+
195+
func (testSSHContext) KeepAlive() *gliderssh.SessionKeepAlive {
196+
panic("not implemented")
197+
}

cli/agent.go

Lines changed: 4 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -323,10 +323,11 @@ func (r *RootCmd) workspaceAgent() *clibase.Cmd {
323323
Value: clibase.BoolOf(&noReap),
324324
},
325325
{
326-
Flag: "ssh-max-timeout",
327-
Default: "0",
326+
Flag: "ssh-max-timeout",
327+
// tcpip.KeepaliveIdleOption = 72h + 1min (forwardTCPSockOpts() in tailnet/conn.go)
328+
Default: "72h",
328329
Env: "CODER_AGENT_SSH_MAX_TIMEOUT",
329-
Description: "Specify the max timeout for a SSH connection.",
330+
Description: "Specify the max timeout for a SSH connection, it is advisable to set it to a minimum of 60s, but no more than 72h.",
330331
Value: clibase.DurationOf(&sshMaxTimeout),
331332
},
332333
{

cli/testdata/coder_agent_--help.golden

Lines changed: 3 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -30,8 +30,9 @@ Starts the Coder workspace agent.
3030
--prometheus-address string, $CODER_AGENT_PROMETHEUS_ADDRESS (default: 127.0.0.1:2112)
3131
The bind address to serve Prometheus metrics.
3232

33-
--ssh-max-timeout duration, $CODER_AGENT_SSH_MAX_TIMEOUT (default: 0)
34-
Specify the max timeout for a SSH connection.
33+
--ssh-max-timeout duration, $CODER_AGENT_SSH_MAX_TIMEOUT (default: 72h)
34+
Specify the max timeout for a SSH connection, it is advisable to set
35+
it to a minimum of 60s, but no more than 72h.
3536

3637
--tailnet-listen-port int, $CODER_AGENT_TAILNET_LISTEN_PORT (default: 0)
3738
Specify a static port for Tailscale to use for listening.

go.mod

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -45,7 +45,7 @@ replace tailscale.com => github.com/coder/tailscale v0.0.0-20230522123520-747122
4545
// repo as tailscale.com/tempfork/gliderlabs/ssh, however, we can't replace the
4646
// subpath and it includes changes to golang.org/x/crypto/ssh as well which
4747
// makes importing it directly a bit messy.
48-
replace github.com/gliderlabs/ssh => github.com/coder/ssh v0.0.0-20230421140225-04bb837133e1
48+
replace github.com/gliderlabs/ssh => github.com/coder/ssh v0.0.0-20230615124436-fc6e4b009688
4949

5050
// Waiting on https://github.com/imulab/go-scim/pull/95 to merge.
5151
replace github.com/imulab/go-scim/pkg/v2 => github.com/coder/go-scim/pkg/v2 v2.0.0-20230221055123-1d63c1222136
@@ -140,7 +140,7 @@ require (
140140
github.com/robfig/cron/v3 v3.0.1
141141
github.com/spf13/afero v1.9.3
142142
github.com/spf13/pflag v1.0.5
143-
github.com/stretchr/testify v1.8.3
143+
github.com/stretchr/testify v1.8.4
144144
github.com/swaggo/http-swagger/v2 v2.0.1
145145
github.com/swaggo/swag v1.8.6
146146
github.com/tabbed/pqtype v0.1.1

go.sum

Lines changed: 4 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -187,8 +187,8 @@ github.com/coder/go-scim/pkg/v2 v2.0.0-20230221055123-1d63c1222136 h1:0RgB61LcNs
187187
github.com/coder/go-scim/pkg/v2 v2.0.0-20230221055123-1d63c1222136/go.mod h1:VkD1P761nykiq75dz+4iFqIQIZka189tx1BQLOp0Skc=
188188
github.com/coder/retry v1.4.0 h1:g0fojHFxcdgM3sBULqgjFDxw1UIvaCqk4ngUDu0EWag=
189189
github.com/coder/retry v1.4.0/go.mod h1:blHMk9vs6LkoRT9ZHyuZo360cufXEhrxqvEzeMtRGoY=
190-
github.com/coder/ssh v0.0.0-20230421140225-04bb837133e1 h1:LBw76rEDuhNJyohve11mbvYv5CmCLmcuUQGiz7Guk50=
191-
github.com/coder/ssh v0.0.0-20230421140225-04bb837133e1/go.mod h1:ZSS+CUoKHDrqVakTfTWUlKSr9MtMFkC4UvtQKD7O914=
190+
github.com/coder/ssh v0.0.0-20230615124436-fc6e4b009688 h1:udcMVKmo37Jv6Nq+Z2gCsDcF5F6zDvwArRGgUdVFD8s=
191+
github.com/coder/ssh v0.0.0-20230615124436-fc6e4b009688/go.mod h1:aGQbuCLyhRLMzZF067xc84Lh7JDs1FKwCmF1Crl9dxQ=
192192
github.com/coder/tailscale v0.0.0-20230522123520-74712221d00f h1:F0Xr1d8h8dAHn7tab1HXuzYFkcjmCydnEfdMbkOhlVk=
193193
github.com/coder/tailscale v0.0.0-20230522123520-74712221d00f/go.mod h1:jpg+77g19FpXL43U1VoIqoSg1K/Vh5CVxycGldQ8KhA=
194194
github.com/coder/terraform-provider-coder v0.8.2 h1:EPhkdpsNd8fcg6eqpAQr+W1eRrEAMtugoqujoTK4O6o=
@@ -786,8 +786,9 @@ github.com/stretchr/testify v1.7.2/go.mod h1:R6va5+xMeoiuVRoj+gSkQ7d3FALtqAAGI1F
786786
github.com/stretchr/testify v1.7.4/go.mod h1:yNjHg4UonilssWZ8iaSj1OCr/vHnekPRkoO+kdMU+MU=
787787
github.com/stretchr/testify v1.8.0/go.mod h1:yNjHg4UonilssWZ8iaSj1OCr/vHnekPRkoO+kdMU+MU=
788788
github.com/stretchr/testify v1.8.2/go.mod h1:w2LPCIKwWwSfY2zedu0+kehJoqGctiVI29o6fzry7u4=
789-
github.com/stretchr/testify v1.8.3 h1:RP3t2pwF7cMEbC1dqtB6poj3niw/9gnV4Cjg5oW5gtY=
790789
github.com/stretchr/testify v1.8.3/go.mod h1:sz/lmYIOXD/1dqDmKjjqLyZ2RngseejIcXlSw2iwfAo=
790+
github.com/stretchr/testify v1.8.4 h1:CcVxjf3Q8PM0mHUKJCdn+eZZtm5yQwehR5yeSVQQcUk=
791+
github.com/stretchr/testify v1.8.4/go.mod h1:sz/lmYIOXD/1dqDmKjjqLyZ2RngseejIcXlSw2iwfAo=
791792
github.com/swaggest/assertjson v1.7.0 h1:SKw5Rn0LQs6UvmGrIdaKQbMR1R3ncXm5KNon+QJ7jtw=
792793
github.com/swaggo/files/v2 v2.0.0 h1:hmAt8Dkynw7Ssz46F6pn8ok6YmGZqHSVLZ+HQM7i0kw=
793794
github.com/swaggo/files/v2 v2.0.0/go.mod h1:24kk2Y9NYEJ5lHuCra6iVwkMjIekMCaFq/0JQj66kyM=

tailnet/conn.go

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -769,7 +769,7 @@ func (*Conn) forwardTCPSockOpts(port uint16) []tcpip.SettableSocketOption {
769769

770770
// See: https://github.com/tailscale/tailscale/blob/c7cea825aea39a00aca71ea02bab7266afc03e7c/wgengine/netstack/netstack.go#L888
771771
if port == WorkspaceAgentSSHPort || port == 22 {
772-
opt := tcpip.KeepaliveIdleOption(72 * time.Hour)
772+
opt := tcpip.KeepaliveIdleOption(72*time.Hour + time.Minute) // Default ssh-max-timeout is 72h, so let's add some extra time.
773773
opts = append(opts, &opt)
774774
}
775775

0 commit comments

Comments
 (0)