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

[v16] Fixes withheld TDP messages in proxy #42706

Merged
merged 5 commits into from
Jun 11, 2024
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.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
5 changes: 0 additions & 5 deletions lib/web/apiserver.go
Original file line number Diff line number Diff line change
Expand Up @@ -98,7 +98,6 @@ import (
"github.com/gravitational/teleport/lib/secret"
"github.com/gravitational/teleport/lib/services"
"github.com/gravitational/teleport/lib/session"
"github.com/gravitational/teleport/lib/srv/desktop/tdp"
"github.com/gravitational/teleport/lib/tlsca"
"github.com/gravitational/teleport/lib/utils"
"github.com/gravitational/teleport/lib/web/app"
Expand Down Expand Up @@ -188,10 +187,6 @@ type Handler struct {
// an authenticated websocket so unauthenticated sockets dont get left
// open.
wsIODeadline time.Duration

// withheldMessages is a list of any messages that came from the browser which were
// withheld while the user was performing MFA.
withheldMessages []tdp.Message
}

// HandlerOption is a functional argument - an option that can be passed
Expand Down
16 changes: 12 additions & 4 deletions lib/web/desktop.go
Original file line number Diff line number Diff line change
Expand Up @@ -175,8 +175,10 @@ func (h *Handler) createDesktopConnection(
return sendTDPError(err)
}

// Holds any messages withheld while issuing certs.
var withheld []tdp.Message
// Issue certificate for the user/desktop combination and perform MFA ceremony if required.
certs, err := h.issueCerts(ctx, ws, sctx, mfaRequired, certsReq)
certs, err := h.issueCerts(ctx, ws, sctx, mfaRequired, certsReq, &withheld)
if err != nil {
return sendTDPError(err)
}
Expand Down Expand Up @@ -222,11 +224,15 @@ func (h *Handler) createDesktopConnection(
if err != nil {
return sendTDPError(err)
}
for _, msg := range h.withheldMessages {
for _, msg := range withheld {
log.Debugf("Sending withheld message: %v", msg)
if err := tdpConn.WriteMessage(msg); err != nil {
return sendTDPError(err)
}
}
// nil out the slice so we don't hang on to these messages
// for the rest of the connection
withheld = nil

// proxyWebsocketConn hangs here until connection is closed
handleProxyWebsocketConnErr(
Expand Down Expand Up @@ -314,9 +320,10 @@ func (h *Handler) issueCerts(
sctx *SessionContext,
mfaRequired bool,
certsReq *proto.UserCertsRequest,
withheld *[]tdp.Message,
) (certs *proto.Certs, err error) {
if mfaRequired {
certs, err = h.performMFACeremony(ctx, ws, sctx, certsReq)
certs, err = h.performMFACeremony(ctx, ws, sctx, certsReq, withheld)
if err != nil {
return nil, trace.Wrap(err)
}
Expand Down Expand Up @@ -363,6 +370,7 @@ func (h *Handler) performMFACeremony(
ws *websocket.Conn,
sctx *SessionContext,
certsReq *proto.UserCertsRequest,
withheld *[]tdp.Message,
) (_ *proto.Certs, err error) {
ctx, span := h.tracer.Start(ctx, "desktop/performMFACeremony")
defer func() {
Expand Down Expand Up @@ -413,7 +421,7 @@ func (h *Handler) performMFACeremony(
if err != nil {
return nil, trace.Wrap(err)
}
h.withheldMessages = append(h.withheldMessages, msg)
*withheld = append(*withheld, msg)
continue
}

Expand Down
Loading