forked from coder/coder
-
Notifications
You must be signed in to change notification settings - Fork 0
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
feat: Separate workspace agent for tests (coder#567)
This adds tests for Google Cloud authentication, and lays the ground-work for future agent auth types in the future.
- Loading branch information
Showing
11 changed files
with
333 additions
and
208 deletions.
There are no files selected for viewing
This file contains 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
This file contains 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
This file contains 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 |
---|---|---|
@@ -0,0 +1,50 @@ | ||
package agent | ||
|
||
import ( | ||
"context" | ||
"net" | ||
|
||
"golang.org/x/crypto/ssh" | ||
"golang.org/x/xerrors" | ||
|
||
"github.com/coder/coder/peer" | ||
) | ||
|
||
// Conn wraps a peer connection with helper functions to | ||
// communicate with the agent. | ||
type Conn struct { | ||
*peer.Conn | ||
} | ||
|
||
// SSH dials the built-in SSH server. | ||
func (c *Conn) SSH() (net.Conn, error) { | ||
channel, err := c.Dial(context.Background(), "ssh", &peer.ChannelOptions{ | ||
Protocol: "ssh", | ||
}) | ||
if err != nil { | ||
return nil, xerrors.Errorf("dial: %w", err) | ||
} | ||
return channel.NetConn(), nil | ||
} | ||
|
||
// SSHClient calls SSH to create a client that uses a weak cipher | ||
// for high throughput. | ||
func (c *Conn) SSHClient() (*ssh.Client, error) { | ||
netConn, err := c.SSH() | ||
if err != nil { | ||
return nil, xerrors.Errorf("ssh: %w", err) | ||
} | ||
sshConn, channels, requests, err := ssh.NewClientConn(netConn, "localhost:22", &ssh.ClientConfig{ | ||
Config: ssh.Config{ | ||
Ciphers: []string{"arcfour"}, | ||
}, | ||
// SSH host validation isn't helpful, because obtaining a peer | ||
// connection already signifies user-intent to dial a workspace. | ||
// #nosec | ||
HostKeyCallback: ssh.InsecureIgnoreHostKey(), | ||
}) | ||
if err != nil { | ||
return nil, xerrors.Errorf("ssh conn: %w", err) | ||
} | ||
return ssh.NewClient(sshConn, channels, requests), nil | ||
} |
This file contains 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
Oops, something went wrong.