Movatterモバイル変換


[0]ホーム

URL:


Skip to content

Navigation Menu

Sign in
Appearance settings

Search code, repositories, users, issues, pull requests...

Provide feedback

We read every piece of feedback, and take your input very seriously.

Saved searches

Use saved searches to filter your results more quickly

Sign up
Appearance settings

Commit80f9cda

Browse files
committed
Track connections for SSH sessions to prevent leaks
1 parentbe62f41 commit80f9cda

File tree

3 files changed

+21
-16
lines changed

3 files changed

+21
-16
lines changed

‎agent/agent.go

Lines changed: 17 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -645,15 +645,24 @@ func (a *agent) init(ctx context.Context) {
645645
sshLogger.Info(ctx,"ssh connection ended",slog.Error(err))
646646
},
647647
Handler:func(session ssh.Session) {
648-
err:=a.handleSSHSession(session)
649-
varexitError*exec.ExitError
650-
ifxerrors.As(err,&exitError) {
651-
a.logger.Debug(ctx,"ssh session returned",slog.Error(exitError))
652-
_=session.Exit(exitError.ExitCode())
653-
return
654-
}
648+
err:=a.trackConnGoroutine(func() {
649+
err:=a.handleSSHSession(session)
650+
varexitError*exec.ExitError
651+
ifxerrors.As(err,&exitError) {
652+
a.logger.Debug(ctx,"ssh session returned",slog.Error(exitError))
653+
_=session.Exit(exitError.ExitCode())
654+
return
655+
}
656+
iferr!=nil {
657+
a.logger.Warn(ctx,"ssh session failed",slog.Error(err))
658+
// This exit code is designed to be unlikely to be confused for a legit exit code
659+
// from the process.
660+
_=session.Exit(MagicSessionErrorCode)
661+
return
662+
}
663+
})
655664
iferr!=nil {
656-
a.logger.Warn(ctx,"ssh session failed",slog.Error(err))
665+
a.logger.Warn(ctx,"trackssh session failed",slog.Error(err))
657666
// This exit code is designed to be unlikely to be confused for a legit exit code
658667
// from the process.
659668
_=session.Exit(MagicSessionErrorCode)

‎agent/agent_test.go

Lines changed: 4 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -305,7 +305,7 @@ func TestAgent_TCPLocalForwarding(t *testing.T) {
305305
}
306306
}()
307307

308-
cmd:=setupSSHCommand(t, []string{"-L",fmt.Sprintf("%d:127.0.0.1:%d",randomPort,remotePort)}, []string{"sleep","10"})
308+
cmd:=setupSSHCommand(t, []string{"-L",fmt.Sprintf("%d:127.0.0.1:%d",randomPort,remotePort)}, []string{"sleep","5"})
309309
err=cmd.Start()
310310
require.NoError(t,err)
311311

@@ -372,7 +372,7 @@ func TestAgent_TCPRemoteForwarding(t *testing.T) {
372372
}
373373
}()
374374

375-
cmd:=setupSSHCommand(t, []string{"-R",fmt.Sprintf("127.0.0.1:%d:127.0.0.1:%d",randomPort,localPort)}, []string{"sleep","10"})
375+
cmd:=setupSSHCommand(t, []string{"-R",fmt.Sprintf("127.0.0.1:%d:127.0.0.1:%d",randomPort,localPort)}, []string{"sleep","5"})
376376
err=cmd.Start()
377377
require.NoError(t,err)
378378

@@ -437,7 +437,7 @@ func TestAgent_UnixLocalForwarding(t *testing.T) {
437437
}
438438
}()
439439

440-
cmd:=setupSSHCommand(t, []string{"-L",fmt.Sprintf("%s:%s",localSocketPath,remoteSocketPath)}, []string{"sleep","10"})
440+
cmd:=setupSSHCommand(t, []string{"-L",fmt.Sprintf("%s:%s",localSocketPath,remoteSocketPath)}, []string{"sleep","5"})
441441
err=cmd.Start()
442442
require.NoError(t,err)
443443

@@ -495,7 +495,7 @@ func TestAgent_UnixRemoteForwarding(t *testing.T) {
495495
}
496496
}()
497497

498-
cmd:=setupSSHCommand(t, []string{"-R",fmt.Sprintf("%s:%s",remoteSocketPath,localSocketPath)}, []string{"sleep","10"})
498+
cmd:=setupSSHCommand(t, []string{"-R",fmt.Sprintf("%s:%s",remoteSocketPath,localSocketPath)}, []string{"sleep","5"})
499499
err=cmd.Start()
500500
require.NoError(t,err)
501501

‎cli/root_test.go

Lines changed: 0 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -24,10 +24,6 @@ import (
2424
"github.com/coder/coder/testutil"
2525
)
2626

27-
funcinit() {
28-
// os.Setenv("NO_COLOR", "1")
29-
}
30-
3127
// To update the golden files:
3228
// make update-golden-files
3329
varupdateGoldenFiles=flag.Bool("update",false,"update .golden files")

0 commit comments

Comments
 (0)

[8]ページ先頭

©2009-2025 Movatter.jp