[Bug] Token-only Proxmox clusters: VNC handler password login fails with 401
Describe the bug
On a cluster configured with API-token-only authentication (user@realm!tokenid plus token secret), VM noVNC consoles repeatedly show "Connecting / Reconnecting". Cluster status and resource views work normally using the same API token. The token has Administrator permissions. The reverse proxy successfully upgrades the browser WebSocket (101), but PegaProx closes it after a Proxmox 401.
The VNC WebSocket handler in pegaprox/api/vms.py attempts POST https://<PVE>:8006/api2/json/access/ticket with manager.config.user and manager.config.pass_. In API-token-only mode these are a token ID and token secret, not password-login credentials, so Proxmox rejects the request. The standalone VNC handler fails at the urllib.request.urlopen(login_req, ...) call (around line 8576 in 1.2.0). The main-port fallback handler also performs the same password login (around line 9202).
This is distinct from #945: the WebSocket is routed to the standalone VNC listener on port 5001, and the observed error occurs before the PVE VNC WebSocket connection. The configured account uses TOTP, so switching PegaProx to password authentication is not an option in this setup.
Steps to Reproduce
- Add a Proxmox cluster to PegaProx with a valid API token (
user@realm!tokenidand token secret) and no account password. Grant the token access to a test VM's console. - Confirm that cluster and VM status load successfully.
- Open the VM's noVNC console. With a reverse proxy, route
/api/clusters/.../vncwebsocketto PegaProx port 5001 and confirm the upgrade returns101. - Observe the reconnect loop and backend
HTTP Error 401: authentication failurefrom the/access/ticketlogin in the VNC handler.
Expected behavior
The VNC handler should support token-only cluster authentication, using a consistent authentication identity for the PVE vncproxy request and subsequent PVE WebSocket upgrade, without attempting a password login with the token secret. If this mode cannot be supported, the UI should clearly say so instead of accepting the cluster and failing only when a console is opened.
Environment
- PegaProx Version: 1.2.0, Docker image
ghcr.io/pegaprox/pegaprox:latest, image revision124857faba561cf3fc55eed8bb85a19119253e20 - Installation Method: Docker
- OS: Debian Docker host
- Browser: Chromium-based
- Behind Reverse Proxy? Caddy, with WebSocket path routed to PegaProx port 5001
- UI? Modern Layout
- Proxmox cluster authentication: API token only; account uses TOTP
Logs
Redacted backend excerpt:
[VNC] Requesting ticket from <PVE host> for qemu/<VMID>
[VNC] Got ticket for qemu/<VMID>, port=<VNC port>
VNC WS handler error: HTTPError: HTTP Error 401: authentication failure
File "/app/pegaprox/api/vms.py", line 8576, in vnc_handler
with urllib.request.urlopen(req, context=ssl_ctx, timeout=10) as r:
Caddy access log for the same console request: HTTP 101 Switching Protocols, then connection closes after about 3 seconds. No tokens, tickets, cookies, hostnames, or VM identifiers are included here.
Checklist
- [x] I searched existing issues; #945 concerns a different reverse-proxy console path.
- [x] The running Docker image reports PegaProx version 1.2.0.
- [x] The report includes reproduction steps, the failing source location, and sanitized logs.
- [x] I understand PegaProx is maintained by volunteers.
Hi @stanthewizzard, thanks for the detail, that report saved me the investigation.
Confirmed against the current code. vnc_handler does an unconditional password login to /access/ticket with config.user and config.pass_ before it does anything else, and on a token-only cluster those are the token id and the token secret, so Proxmox is right to answer 401. It is not one spot either: the same unguarded login sits in four console paths (vnc_poll, handle_vnc_websocket, vnc_handler, vnc_websocket_proxy). Only the termproxy one checks for a password first.
The irritating part is that the code directly after it already knows how to do this properly, it sends Authorization: PVEAPIToken=... for the websocket leg. It just never gets there, because the login above it throws first.
Related to #945, which is the same corner from the other side, so it wants fixing as one batch rather than two. No date from me, but it is queued.
If PegaProx is doing work for you, https://opencollective.com/pegaprox is what keeps it moving.
Marcus
Confirmed, fixed on Testing, and your read of it is exactly right.
Two things were wrong on a token-only cluster. The handler logged in to /access/ticket with config.user and config.pass_ - which on a token cluster hold the token id and the token secret, not a username and password, so PVE was right to answer 401. And even where that login happened to succeed, the cookie it produced was the wrong identity to present: a vncticket is bound to the auth context that asked for it, so a ticket minted under the API token cannot be redeemed under a freshly logged-in session.
Both are gone. There is now one helper that decides the upgrade credentials for every console path - PVEAPIToken= when the cluster authenticates with a token, the manager's own session cookie when it authenticates with a password, and a fresh login only in the case that actually calls for one. Previously the standalone listener on 5001 had a version of this logic and the two main-port handlers did not, which is why you saw it on 5001 and #945 saw a different failure on 5000 - same root cause, two symptoms.
Your last point stands too, and it is fair: accepting a cluster and then failing only when someone opens a console is a bad way to find out. That belongs in the cluster form rather than in the console, so I have not folded it into this fix - if you want to open it separately it will not get lost.
TOTP is not in the way here; nothing on this path needs an interactive login any more.
If you have a chance to try a Testing build against your Caddy setup before this lands in a release, that would be worth a lot - token-only plus TOTP plus a proxy is a combination we cannot fully assemble here.
I'll try Thanks
Hey,
as i am also running a token only setup i gave Testing a try and checked if i can use the console now. Unfortunately its for me not working. I see the websocket properly setting up but the console does not show up and fails to "error".
I was not sure if its related to my setup/environment/network/firewall (raw docker, no reverse proxy, mapping 443/444/445 to 5000/5001/5002) and gave claude my logs and claude was able to slop a fix. So its not my setup :D
But due to my missing knowledge about that claude did there i refrain from sharing that right away. Claude described me the issue as follows:
Console broken on API-token-only clusters + encrypted VNC frame reordering
Two bugs, both affecting the VNC/noVNC console:
- Backend: passthrough-first ordering for token-only clusters (#955)
All four VNC handlers (vnc_poll, handle_vnc_websocket, the async WS server handler, vnc_websocket_proxy) logged in with username/password before checking the browser-supplied passthrough ticket. On clusters configured with an API token only (no password), this login crashed before the passthrough path was ever reached.
Fix: Check passthrough first. If no passthrough is available, delegate auth to manager.mint_console_auth_ticket() which gracefully returns None on token-only clusters, producing a clear 502/close instead of a stack trace. Common logic extracted into _pve_console_ws_path() and _pve_console_ws_auth() helpers.
- Frontend: serialize encrypted WebSocket message decryption
SecureVncSocket's message handler was async — each incoming frame kicked off an independent _decrypt() promise. When two frames arrived in quick succession, the second could resolve before the first, delivering plaintext to noVNC out of order and corrupting the RFB byte stream. Also, _recvSeq was incremented after the await, so two concurrent handlers could read the same stale expected value and throw a false "out-of-order" error.
Fix: Chain message handlers via a _recvChain promise so decryption runs strictly in order. Move _recvSeq increment before the await.
If helpful i can share any logs/details (or what claude changed in the code) let me know.
On token-only clusters the console no longer tries a password login with the token secret: all four console handlers now request the vncproxy through the token session and present the same token on the websocket upgrade. The Stable Mode frame ordering problem mentioned further up the thread is fixed too, decrypts now run strictly in order. Both ship in 1.3.0.
PegaProx lives from sponsorships, so https://opencollective.com/pegaprox is always appreciated.
Marcus