project-pegaprox icon indicating copy to clipboard operation
project-pegaprox copied to clipboard

[Bug] SSH connections are opened to PVE nodes on API-token clusters

Open MrMasterbay opened this issue 2 months ago • 3 comments

Describe the bug

PegaProx opens SSH connections to the PVE nodes although the cluster is configured with an API token only. It happens from normal UI browsing, not just from features that obviously need a shell, and there is no setting to prevent it.

Reported by an operator whose security team picked it up.

Steps to Reproduce

  1. Add a Proxmox cluster using an API token (no SSH key, no SSH password configured).
  2. Open any VM and go to its snapshot view.
  3. Watch the PVE node: an SSH connection attempt arrives from the PegaProx host, and the auth failure shows up in the node`s sshd log.

Expected behavior

A cluster configured for API-token access does not get SSH traffic unless an action is taken that genuinely requires a shell, and an operator can switch SSH off entirely for a cluster.

Environment

  • PegaProx Version: 1.2.0
  • Installation Method: Docker
  • OS: Debian 13
  • Browser: Chrome latest
  • Behind Reverse Proxy? No
  • UI? Corporate

Logs

Connecting to <node>:22 as <user>...
SSH auth failed for <user>@<node>

Screenshots

n/a

Checklist

  • [x] I have searched existing issues to make sure this is not a duplicate
  • [x] I am using the latest version of PegaProx
  • [x] I have put enough in here that someone can start on it without asking me three questions first
  • [x] I understand PegaProx is maintained by volunteers in their free time

Path, traced:

  1. web/src/vm_config.js - fetchEfficientInfo() calls /clusters/<id>/vms/<node>/<type>/<vmid>/snapshot-capability
  2. pegaprox/api/vms.py - manager.check_snapshot_capability(...)
  3. pegaprox/core/manager.py - check_efficient_snapshot_capability(...)
  4. _node_ssh_exec(node, "vgs --noheadings ...") - _ssh_connect(node_ip)

_node_ssh_exec and _ssh_connect have no precondition: they do not check whether the cluster authenticates with a token, whether SSH credentials exist, or whether SSH is wanted. The probe exists to decide whether space-efficient LVM snapshots can be offered, which does need a shell, but it is asked for every VM that is viewed.

There is also no opt-out - no disable_ssh / ssh_enabled style setting exists.

Suggested direction: skip the probe when SSH is not usable for that cluster and cache the answer per node instead of per VM view, and add an explicit per-cluster "API only" switch, with the features that need a shell saying so in the UI rather than failing at connect time.

MrMasterbay avatar Sep 21 '26 11:09 MrMasterbay

Fixed on Testing (4e9398e), ships with the next release.

Worth flagging that it was worse than the report: _ssh_connect fell back to password = config.pass_, and on a cluster where the token id is in the username that field is the token secret — it's what we concatenate into PVEAPIToken=user@realm!tokenid=<secret>. So every one of those attempts handed the API token to the node's sshd as a password. Not just noise in the auth log.

The rule for telling the two cases apart already existed in ssh_diagnose (and it's '!' in config.user, not _using_api_token — the latter is also true for clusters where we minted the token ourselves and the password is real). _ssh_connect just never had it, so there's one ssh_blocked_reason() now and both ask it. The sshpass path in utils/ssh.py and XCP-ng's own SSH honour it too — three implementations can reach a node, closing one would've been pointless.

Added a per-cluster off switch (ssh_disabled, off by default) with a toggle in the cluster dialog. Note it takes the node shell and the VNC tunnel with it, since they all go through the same connect.

Also: the snapshot panel used to say "Not enough VG free space (0.0 GB free)" when the truth was it couldn't reach the node to look. It says that now instead.

Marcus

mkellermann97 avatar Sep 22 '26 09:09 mkellermann97

Follow-up, and a correction to what I wrote above: that fix was incomplete.

I said every SSH path to a node goes through one connect function. It doesn't — there are five, and I'd closed one. _ssh_node_output_ex and the HA helpers each have their own key/agent/password ladder that never touches it, and three of those get handed the same stored secret as the password. So on a token-auth cluster the token was still going to sshd on those paths.

Caught it running the switch against a live instance rather than trusting the unit tests: ssh_disabled read true in the cluster listing and the hardening report still came back with 44 real results. All six are gated now (f098ebc), and the switch genuinely closes it — 412 with a reason instead of a report built on nothing.

Worth saying since your security team is watching this one: if you'd turned it on after my first commit you'd have had a switch that looked like it worked. It does now.

Marcus

mkellermann97 avatar Sep 22 '26 11:09 mkellermann97

On a cluster set up with only an API token and no SSH key or SSH password, PegaProx no longer opens SSH connections to the nodes, and the token secret is never offered to sshd as a password. The cluster dialog also has a new per-cluster switch to turn SSH off completely, and the snapshot panel now says SSH is unavailable instead of reporting 0 GB free. This ships in 1.3.0.

Marcus

mkellermann97 avatar Oct 07 '26 04:10 mkellermann97