feat: route every console session through the agent relay
This commit is contained in:
@@ -77,20 +77,37 @@ type GuacParams struct {
|
||||
Params map[string]string
|
||||
}
|
||||
|
||||
func portOr(v, def int) string {
|
||||
func portOr(v, def int) int {
|
||||
if v == 0 {
|
||||
v = def
|
||||
return def
|
||||
}
|
||||
return strconv.Itoa(v)
|
||||
return v
|
||||
}
|
||||
|
||||
func BuildGuacParams(srv *models.Server, protocol, sshUser, privateKey, passphrase, rdpUser, rdpPass string) (*GuacParams, error) {
|
||||
host := srv.IPAddress
|
||||
// TargetPort is the port on the managed server that the agent will dial on its
|
||||
// own loopback address.
|
||||
func TargetPort(srv *models.Server, protocol string) (int, error) {
|
||||
switch protocol {
|
||||
case "ssh":
|
||||
return portOr(srv.SSHPort, 22), nil
|
||||
case "rdp":
|
||||
return portOr(srv.RDPPort, 3389), nil
|
||||
case "vnc":
|
||||
return 5900, nil
|
||||
default:
|
||||
return 0, fmt.Errorf("unsupported protocol %q", protocol)
|
||||
}
|
||||
}
|
||||
|
||||
// BuildGuacParams points guacd at the relay listener, never at the managed
|
||||
// server: on a cloud deployment the server's address is not routable from here.
|
||||
func BuildGuacParams(protocol, sshUser, privateKey, passphrase, rdpUser, rdpPass, relayHost string, relayPort int) (*GuacParams, error) {
|
||||
port := strconv.Itoa(relayPort)
|
||||
switch protocol {
|
||||
case "ssh":
|
||||
p := map[string]string{
|
||||
"hostname": host,
|
||||
"port": portOr(srv.SSHPort, 22),
|
||||
"hostname": relayHost,
|
||||
"port": port,
|
||||
}
|
||||
if sshUser == "" {
|
||||
sshUser = "root"
|
||||
@@ -105,8 +122,8 @@ func BuildGuacParams(srv *models.Server, protocol, sshUser, privateKey, passphra
|
||||
return &GuacParams{Protocol: "ssh", Params: p}, nil
|
||||
case "rdp":
|
||||
return &GuacParams{Protocol: "rdp", Params: map[string]string{
|
||||
"hostname": host,
|
||||
"port": portOr(srv.RDPPort, 3389),
|
||||
"hostname": relayHost,
|
||||
"port": port,
|
||||
"username": rdpUser,
|
||||
"password": rdpPass,
|
||||
"security": "any",
|
||||
@@ -114,8 +131,8 @@ func BuildGuacParams(srv *models.Server, protocol, sshUser, privateKey, passphra
|
||||
}}, nil
|
||||
case "vnc":
|
||||
return &GuacParams{Protocol: "vnc", Params: map[string]string{
|
||||
"hostname": host,
|
||||
"port": "5900",
|
||||
"hostname": relayHost,
|
||||
"port": port,
|
||||
"password": rdpPass,
|
||||
}}, nil
|
||||
default:
|
||||
|
||||
Reference in New Issue
Block a user