Skip to content
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 our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

[v13] Propagate proxy public addr in Web UI ssh session #27420

Merged
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Jump to
Jump to file
Failed to load files.
Diff view
Diff view
10 changes: 9 additions & 1 deletion lib/client/client.go
Expand Up @@ -92,6 +92,11 @@ type NodeClient struct {

mu sync.Mutex
closers []io.Closer

// ProxyPublicAddr is the web proxy public addr, as opposed to the local proxy
// addr set in TC.WebProxyAddr. This is needed to report the correct address
// to SSH_TELEPORT_WEBPROXY_ADDR used by some features like "teleport status".
ProxyPublicAddr string
}

// AddCloser adds an [io.Closer] that will be closed when the
Expand Down Expand Up @@ -1608,9 +1613,12 @@ func (c *NodeClient) RunInteractiveShell(ctx context.Context, mode types.Session
if err != nil {
return trace.Wrap(err)
}

env[teleport.EnvSSHSessionInvited] = string(encoded)

// Overwrite "SSH_SESSION_WEBPROXY_ADDR" with the public addr reported by the proxy. Otherwise,
// this would be set to the localhost addr (tc.WebProxyAddr) used for Web UI client connections.
env[teleport.SSHSessionWebproxyAddr] = c.ProxyPublicAddr

nodeSession, err := newSession(ctx, c, sessToJoin, env, c.TC.Stdin, c.TC.Stdout, c.TC.Stderr, c.TC.EnableEscapeSequences)
if err != nil {
return trace.Wrap(err)
Expand Down
1 change: 1 addition & 0 deletions lib/web/apiserver.go
Expand Up @@ -2679,6 +2679,7 @@ func (h *Handler) siteNodeConnect(
SessionData: sessionData,
KeepAliveInterval: netConfig.GetKeepAliveInterval(),
ProxyHostPort: h.ProxyHostPort(),
ProxyPublicAddr: h.PublicProxyAddr(),
InteractiveCommand: req.InteractiveCommand,
Router: h.cfg.Router,
TracerProvider: h.cfg.TracerProvider,
Expand Down
9 changes: 9 additions & 0 deletions lib/web/terminal.go
Expand Up @@ -121,6 +121,7 @@ func NewTerminal(ctx context.Context, cfg TerminalHandlerConfig) (*TerminalHandl
sessionData: cfg.SessionData,
keepAliveInterval: cfg.KeepAliveInterval,
proxyHostPort: cfg.ProxyHostPort,
proxyPublicAddr: cfg.ProxyPublicAddr,
interactiveCommand: cfg.InteractiveCommand,
router: cfg.Router,
tracer: cfg.tracer,
Expand Down Expand Up @@ -154,6 +155,8 @@ type TerminalHandlerConfig struct {
KeepAliveInterval time.Duration
// ProxyHostPort is the address of the server to connect to.
ProxyHostPort string
// ProxyPublicAddr is the public web proxy address.
ProxyPublicAddr string
// InteractiveCommand is a command to execute.
InteractiveCommand []string
// Router determines how connections to nodes are created
Expand Down Expand Up @@ -223,6 +226,8 @@ type sshBaseHandler struct {
authProvider AuthProvider
// proxyHostPort is the address of the server to connect to.
proxyHostPort string
// proxyPublicAddr is the public web proxy address.
proxyPublicAddr string
// keepAliveInterval is the interval for sending ping frames to a web client.
// This value is pulled from the cluster network config and
// guaranteed to be set to a nonzero value as it's enforced by the configuration.
Expand Down Expand Up @@ -776,6 +781,8 @@ func (t *sshBaseHandler) connectToNode(ctx context.Context, ws WSConn, tc *clien
return nil, trace.NewAggregate(err, conn.Close())
}

clt.ProxyPublicAddr = t.proxyPublicAddr

return clt, nil
}

Expand Down Expand Up @@ -814,6 +821,8 @@ func (t *sshBaseHandler) connectToNodeWithMFABase(ctx context.Context, ws WSConn
return nil, trace.NewAggregate(err, conn.Close())
}

nc.ProxyPublicAddr = t.proxyPublicAddr

return nc, nil
}

Expand Down