Fix console WebSocket authentication for nodes on remote computes (#3078)

* Use the compute credentials for console and VNC WebSocket forwarding

The controller forwarded the console and VNC WebSocket to a compute with
its own local server credentials instead of the credentials stored on the
compute. Any remote compute with its own credentials rejected the
connection with a 401 error, so the web console could not open for nodes
running on a remote compute.

Fixes #3076

* Do not start the console when compute WebSocket authentication fails

The VPCS and VirtualBox console WebSocket routes still called
start_websocket_console() with None after the authentication dependency
rejected the client and closed the socket. The handler crashed with
"AttributeError: 'NoneType' object has no attribute 'client'".

Add the same guard the other node types already have. See #3076
This commit is contained in:
Guobin Yue authored and GitHub committed 2026-11-14 18:58:44 +01:00
1 parent 3aaf125b88
commit fe51feec66
6 files changed
+121 -26

No files matched your search

@@ -329,7 +329,8 @@ async def console_ws(
Console WebSocket.
"""
await node.start_websocket_console(websocket)
if websocket:
await node.start_websocket_console(websocket)
@router.post(
+2 -1
View File
@@ -301,7 +301,8 @@ async def console_ws(
Console WebSocket.
"""
await node.start_websocket_console(websocket)
if websocket:
await node.start_websocket_console(websocket)
@router.post(
+12 -23
View File
@@ -33,7 +33,6 @@ from fastapi.routing import APIRoute
from gns3server import schemas
from gns3server.api.openapi import binary_request_body, binary_response
from gns3server.config import Config
from gns3server.controller import Controller
from gns3server.controller.controller_error import (
ControllerBadRequestError,
@@ -859,19 +858,14 @@ async def ws_console(
try:
# forward WebSocket data in both directions between the client and the compute console WebSocket
log.info(f"Forwarding console WebSocket to '{ws_console_compute_url}'")
server_config = Config.instance().settings.Server
user = server_config.compute_username
password = server_config.compute_password
if not user:
raise ControllerForbiddenError("Compute username is not set")
user = user.strip()
if user and password:
auth_header = aiohttp.encode_basic_auth(user, password.get_secret_value(), encoding="utf-8")
else:
auth_header = aiohttp.encode_basic_auth(user, "", encoding="utf-8")
# authenticate with the credentials of this compute, not with the local server
# credentials: they only match for the local compute
headers = {}
if compute.auth_header:
headers["Authorization"] = compute.auth_header
ssl_context = Controller.instance().ssl_context()
async with HTTPClient.get_client().ws_connect(
ws_console_compute_url, headers={"Authorization": auth_header}, ssl_context=ssl_context
ws_console_compute_url, headers=headers, ssl_context=ssl_context
) as ws:
tasks = [
asyncio.ensure_future(ws_receive(ws)),
@@ -959,19 +953,14 @@ async def vnc_console(
try:
# forward WebSocket data in both directions between the client and the compute VNC console WebSocket
log.info(f"Forwarding VNC console WebSocket to '{vnc_console_compute_url}'")
server_config = Config.instance().settings.Server
user = server_config.compute_username
password = server_config.compute_password
if not user:
raise ControllerForbiddenError("Compute username is not set")
user = user.strip()
if user and password:
auth_header = aiohttp.encode_basic_auth(user, password.get_secret_value(), encoding="utf-8")
else:
auth_header = aiohttp.encode_basic_auth(user, "", encoding="utf-8")
# authenticate with the credentials of this compute, not with the local server
# credentials: they only match for the local compute
headers = {}
if compute.auth_header:
headers["Authorization"] = compute.auth_header
ssl_context = Controller.instance().ssl_context()
async with HTTPClient.get_client().ws_connect(
vnc_console_compute_url, headers={"Authorization": auth_header}, ssl_context=ssl_context
vnc_console_compute_url, headers=headers, ssl_context=ssl_context
) as ws:
tasks = [
asyncio.ensure_future(vnc_receive(ws)),