Skip to content

Commit

Permalink
[v9] Add hostlogin to proxy config for windows desktop (#12781)
Browse files Browse the repository at this point in the history
* add hostlogin to proxy config for windows

* Set ProxyClient's HostLogin to the Windows username

Also convert a few TLS handshakes to a context-aware version
for better timeout/cancelation behavior.

Co-authored-by: Carson Anderson <[email protected]>
  • Loading branch information
zmb3 and rcanderson23 authored May 20, 2022
1 parent e4a2860 commit 443b7e1
Show file tree
Hide file tree
Showing 3 changed files with 11 additions and 5 deletions.
2 changes: 1 addition & 1 deletion lib/auth/middleware.go
Original file line number Diff line number Diff line change
Expand Up @@ -592,7 +592,7 @@ func (a *Middleware) WrapContextWithUser(ctx context.Context, conn *tls.Conn) (c
// Perform the handshake if it hasn't been already. Before the handshake we
// won't have client certs available.
if !conn.ConnectionState().HandshakeComplete {
if err := conn.Handshake(); err != nil {
if err := conn.HandshakeContext(ctx); err != nil {
return nil, trace.ConvertSystemError(err)
}
}
Expand Down
2 changes: 1 addition & 1 deletion lib/utils/tlsdial.go
Original file line number Diff line number Diff line change
Expand Up @@ -47,7 +47,7 @@ func TLSDial(ctx context.Context, dial DialWithContextFunc, network, addr string
conn := tls.Client(plainConn, tlsConfig)
errC := make(chan error, 1)
go func() {
err := conn.Handshake()
err := conn.HandshakeContext(ctx)
errC <- err
}()

Expand Down
12 changes: 9 additions & 3 deletions lib/web/desktop.go
Original file line number Diff line number Diff line change
Expand Up @@ -138,7 +138,7 @@ func (h *Handler) createDesktopConnection(
WriteBufferSize: 1024,
}

pc, err := proxyClient(r.Context(), ctx, h.ProxyHostPort())
pc, err := proxyClient(r.Context(), ctx, h.ProxyHostPort(), username)
if err != nil {
return trace.Wrap(err)
}
Expand All @@ -164,7 +164,7 @@ func (h *Handler) createDesktopConnection(
}
serviceConnTLS := tls.Client(serviceConn, tlsConfig)

if err := serviceConnTLS.Handshake(); err != nil {
if err := serviceConnTLS.HandshakeContext(r.Context()); err != nil {
return trace.NewAggregate(err, sendTDPError(ws, err))
}
log.Debug("Connected to windows_desktop_service")
Expand All @@ -185,11 +185,17 @@ func (h *Handler) createDesktopConnection(
return nil
}

func proxyClient(ctx context.Context, sessCtx *SessionContext, addr string) (*client.ProxyClient, error) {
func proxyClient(ctx context.Context, sessCtx *SessionContext, addr, windowsUser string) (*client.ProxyClient, error) {
cfg, err := makeTeleportClientConfig(ctx, sessCtx)
if err != nil {
return nil, trace.Wrap(err)
}

// Set HostLogin to avoid the default behavior of looking up the
// Unix user Teleport is running as (which doesn't work in containerized
// environments where we're running as an arbitrary UID)
cfg.HostLogin = windowsUser

if err := cfg.ParseProxyHost(addr); err != nil {
return nil, trace.Wrap(err)
}
Expand Down

0 comments on commit 443b7e1

Please sign in to comment.