From 06fdd89fcfa25a5863893313013c652ad1703d31 Mon Sep 17 00:00:00 2001 From: Zac Bergquist Date: Tue, 25 Jun 2024 08:32:23 -0600 Subject: [PATCH] Display websocket errors in the UI We never implemented UI support for the websocket error message, so errors were never surfaced to users. This also uncovered one case where we were sending invalid data (due to a missing version number). Closes #42626 --- lib/web/apiserver.go | 1 + web/packages/teleport/src/lib/term/protobuf.js | 2 ++ web/packages/teleport/src/lib/term/tty.ts | 3 +++ 3 files changed, 6 insertions(+) diff --git a/lib/web/apiserver.go b/lib/web/apiserver.go index 5833d7de50bd6..153867a7869b9 100644 --- a/lib/web/apiserver.go +++ b/lib/web/apiserver.go @@ -3821,6 +3821,7 @@ func (h *Handler) writeErrToWebSocket(ws *websocket.Conn, err error) { return } errEnvelope := terminal.Envelope{ + Version: defaults.WebsocketVersion, Type: defaults.WebsocketError, Payload: trace.UserMessage(err), } diff --git a/web/packages/teleport/src/lib/term/protobuf.js b/web/packages/teleport/src/lib/term/protobuf.js index c47cde49f7926..0aa52cf9148af 100644 --- a/web/packages/teleport/src/lib/term/protobuf.js +++ b/web/packages/teleport/src/lib/term/protobuf.js @@ -30,6 +30,7 @@ export const MessageTypeEnum = { FILE_TRANSFER_REQUEST: 'f', FILE_TRANSFER_DECISION: 't', WEBAUTHN_CHALLENGE: 'n', + ERROR: 'e', LATENCY: 'l', }; @@ -58,6 +59,7 @@ export const messageFields = { event: MessageTypeEnum.AUDIT.charCodeAt(0), close: MessageTypeEnum.SESSION_END.charCodeAt(0), challengeResponse: MessageTypeEnum.WEBAUTHN_CHALLENGE.charCodeAt(0), + error: MessageTypeEnum.ERROR.charCodeAt(0), }, }, }; diff --git a/web/packages/teleport/src/lib/term/tty.ts b/web/packages/teleport/src/lib/term/tty.ts index 703282bdcc2de..018b1d8c3a0d1 100644 --- a/web/packages/teleport/src/lib/term/tty.ts +++ b/web/packages/teleport/src/lib/term/tty.ts @@ -200,6 +200,9 @@ class Tty extends EventEmitterWebAuthnSender { this.emit(TermEvent.DATA, msg.payload); } break; + case MessageTypeEnum.ERROR: + this.emit(TermEvent.DATA, msg.payload + '\n'); + break; case MessageTypeEnum.LATENCY: this.emit(TermEvent.LATENCY, msg.payload); break;