- Notifications
You must be signed in to change notification settings - Fork928
feat: Add support for VS Code and JetBrains Gateway via SSH#956
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 ourterms of service andprivacy statement. We’ll occasionally send you account related emails.
Already on GitHub?Sign in to your account
Uh oh!
There was an error while loading.Please reload this page.
Merged
Changes fromall commits
Commits
Show all changes
18 commits Select commitHold shift + click to select a range
85745ab
Improve CLI documentation
kylecarbse8258ea
feat: Allow workspace resources to attach multiple agents
kylecarbs6abc4a4
Merge branch 'updatetfprovider' into clihelp
kylecarbsb0cb66d
Add tree view
kylecarbs6ed0bc0
Improve table UI
kylecarbs3ad0766
feat: Allow workspace resources to attach multiple agents
kylecarbs9cbadef
Merge branch 'updatetfprovider' into clihelp
kylecarbs4496f36
Rename `tunnel` to `skip-tunnel`
kylecarbs65c19bd
Add disclaimer about editing templates
kylecarbsc50d170
Add help to template create
kylecarbs326f2d5
Improve workspace create flow
kylecarbs008ba69
Add end-to-end test for config-ssh
kylecarbs71e4544
Improve testing of config-ssh
kylecarbs8fecb67
Fix workspace list
kylecarbsc625594
feat: Add support for VS Code and JetBrains Gateway via SSH
kylecarbs34e7eb5
Fix config-ssh command with socat
kylecarbsff10b9c
Merge branch 'clihelp' into ides
kylecarbs81f3849
Merge branch 'main' into ides
kylecarbsFile filter
Filter by extension
Conversations
Failed to load comments.
Loading
Uh oh!
There was an error while loading.Please reload this page.
Jump to
Jump to file
Failed to load files.
Loading
Uh oh!
There was an error while loading.Please reload this page.
Diff view
Diff view
There are no files selected for viewing
4 changes: 4 additions & 0 deletions.github/workflows/coder.yaml
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.Learn more about bidirectional Unicode characters
73 changes: 35 additions & 38 deletionsagent/agent.go
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -21,6 +21,8 @@ import ( | ||
"github.com/coder/coder/pty" | ||
"github.com/coder/retry" | ||
"github.com/pkg/sftp" | ||
"github.com/gliderlabs/ssh" | ||
gossh "golang.org/x/crypto/ssh" | ||
"golang.org/x/xerrors" | ||
@@ -121,7 +123,7 @@ func (a *agent) handlePeerConn(ctx context.Context, conn *peer.Conn) { | ||
switch channel.Protocol() { | ||
case "ssh": | ||
goa.sshServer.HandleConn(channel.NetConn()) | ||
default: | ||
a.options.Logger.Warn(ctx, "unhandled protocol from channel", | ||
slog.F("protocol", channel.Protocol()), | ||
@@ -146,7 +148,10 @@ func (a *agent) init(ctx context.Context) { | ||
sshLogger := a.options.Logger.Named("ssh-server") | ||
forwardHandler := &ssh.ForwardedTCPHandler{} | ||
a.sshServer = &ssh.Server{ | ||
ChannelHandlers: map[string]ssh.ChannelHandler{ | ||
"direct-tcpip": ssh.DirectTCPIPHandler, | ||
"session": ssh.DefaultSessionHandler, | ||
}, | ||
ConnectionFailedCallback: func(conn net.Conn, err error) { | ||
sshLogger.Info(ctx, "ssh connection ended", slog.Error(err)) | ||
}, | ||
@@ -185,61 +190,54 @@ func (a *agent) init(ctx context.Context) { | ||
NoClientAuth: true, | ||
} | ||
}, | ||
SubsystemHandlers: map[string]ssh.SubsystemHandler{ | ||
"sftp": func(session ssh.Session) { | ||
kylecarbs marked this conversation as resolved. Show resolvedHide resolvedUh oh!There was an error while loading.Please reload this page. | ||
server, err := sftp.NewServer(session) | ||
if err != nil { | ||
a.options.Logger.Debug(session.Context(), "initialize sftp server", slog.Error(err)) | ||
return | ||
} | ||
defer server.Close() | ||
err = server.Serve() | ||
if errors.Is(err, io.EOF) { | ||
return | ||
} | ||
a.options.Logger.Debug(session.Context(), "sftp server exited with error", slog.Error(err)) | ||
}, | ||
}, | ||
} | ||
go a.run(ctx) | ||
} | ||
func (a *agent) handleSSHSession(session ssh.Session) error { | ||
currentUser, err := user.Current() | ||
if err != nil { | ||
return xerrors.Errorf("get current user: %w", err) | ||
} | ||
username := currentUser.Username | ||
shell, err := usershell.Get(username) | ||
if err != nil { | ||
return xerrors.Errorf("get user shell: %w", err) | ||
} | ||
// gliderlabs/ssh returns a command slice of zero | ||
// when a shell is requested. | ||
command := session.RawCommand() | ||
if len(session.Command()) == 0 { | ||
command = shell | ||
} | ||
// OpenSSH executes all commands with the users current shell. | ||
// We replicate that behavior for IDE support. | ||
cmd := exec.CommandContext(session.Context(), shell, "-c", command) | ||
cmd.Env = append(os.Environ(), session.Environ()...) | ||
executablePath, err := os.Executable() | ||
if err != nil { | ||
return xerrors.Errorf("getting os executable: %w", err) | ||
} | ||
cmd.Env = append(cmd.Env, fmt.Sprintf(`GIT_SSH_COMMAND="%s gitssh --"`, executablePath)) | ||
sshPty, windowSize, isPty := session.Pty() | ||
if isPty { | ||
@@ -268,7 +266,7 @@ func (a *agent) handleSSHSession(session ssh.Session) error { | ||
} | ||
cmd.Stdout = session | ||
cmd.Stderr = session.Stderr() | ||
// This blocks forever until stdin is received if we don't | ||
// use StdinPipe. It's unknown what causes this. | ||
stdinPipe, err := cmd.StdinPipe() | ||
@@ -282,8 +280,7 @@ func (a *agent) handleSSHSession(session ssh.Session) error { | ||
if err != nil { | ||
return xerrors.Errorf("start: %w", err) | ||
} | ||
return cmd.Wait() | ||
} | ||
// isClosed returns whether the API is closed or not. | ||
19 changes: 19 additions & 0 deletionsagent/agent_test.go
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.Learn more about bidirectional Unicode characters
3 changes: 2 additions & 1 deletioncli/cliui/resources_test.go
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.Learn more about bidirectional Unicode characters
16 changes: 8 additions & 8 deletionsgo.mod
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.Learn more about bidirectional Unicode characters
3 changes: 3 additions & 0 deletionsgo.sum
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.Learn more about bidirectional Unicode characters
6 changes: 4 additions & 2 deletionspeer/channel.go
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -21,7 +21,7 @@ const ( | ||
// For some reason messages larger just don't work... | ||
// This shouldn't be a huge deal for real-world usage. | ||
// See: https://github.com/pion/datachannel/issues/59 | ||
kylecarbs marked this conversation as resolved. Show resolvedHide resolvedUh oh!There was an error while loading.Please reload this page. | ||
maxMessageLength =64 * 1024 //64 KB | ||
) | ||
// newChannel creates a new channel and initializes it. | ||
@@ -145,7 +145,9 @@ func (c *Channel) init() { | ||
if c.opts.Unordered { | ||
c.reader = c.rwc | ||
} else { | ||
// This must be the max message length otherwise a short | ||
// buffer error can occur. | ||
c.reader = bufio.NewReaderSize(c.rwc, maxMessageLength) | ||
} | ||
close(c.opened) | ||
}) | ||
Add this suggestion to a batch that can be applied as a single commit.This suggestion is invalid because no changes were made to the code.Suggestions cannot be applied while the pull request is closed.Suggestions cannot be applied while viewing a subset of changes.Only one suggestion per line can be applied in a batch.Add this suggestion to a batch that can be applied as a single commit.Applying suggestions on deleted lines is not supported.You must change the existing code in this line in order to create a valid suggestion.Outdated suggestions cannot be applied.This suggestion has been applied or marked resolved.Suggestions cannot be applied from pending reviews.Suggestions cannot be applied on multi-line comments.Suggestions cannot be applied while the pull request is queued to merge.Suggestion cannot be applied right now. Please check back later.