[Feature] Support scoped sudo permissions instead of requiring sudo bash
Describe the feature
Support least-privilege SSH/sudo execution for non-root Proxmox users.
Currently, several SSH operations are wrapped using a pattern similar to:
echo "<base64>" | base64 -d | sudo -n bash
Because the actual command is passed to bash over stdin, sudoers can only match the bash executable itself. This makes it difficult to restrict PegaProx to only the commands it actually requires.
It would be useful if PegaProx separated SSH execution into:
- Unprivileged commands, executed directly as the configured SSH user where possible.
- Privileged commands, executed as the specific command through
sudo -nrather than through a generic root shell.
For example:
sudo -n /usr/sbin/ha-manager ...
instead of:
echo "<payload>" | base64 -d | sudo -n bash
This would allow administrators to build narrowly scoped sudoers policies based on the PegaProx features they choose to enable.
Ideally, the documentation could also provide a minimum-permission sudoers example.
Use Case
In environments where least privilege is required, granting a service account unrestricted passwordless root access is undesirable.
With the current execution model, allowing sudo bash effectively allows arbitrary root command execution, even when PegaProx only needs a small number of specific commands.
Executing commands directly would allow administrators to whitelist only the required operations and reduce the privileges available to the PegaProx SSH account.
Alternatives considered
NOPASSWD: ALL
This provides full functionality but gives the PegaProx SSH account unrestricted root access.
Allowing bash through sudoers
For example:
pegaprox ALL=(root) NOPASSWD: /bin/bash
This does not provide meaningful restriction because arbitrary commands can still be provided to the root shell through stdin.
Maintaining a custom patch
The SSH execution logic could be modified locally, but upstream support would make least-privilege deployments easier to maintain and benefit other users as well.
How important is this for you?
Would improve my workflow.
This would make it easier to deploy PegaProx in environments where service accounts are expected to follow least-privilege principles.
Checklist
- [x] I have searched existing issues and discussions to make sure this hasn't been requested before
Your read of it is right — there is one helper that wraps everything as echo <b64> | base64 -d | sudo -n bash, and around fifty call sites go through sudo one way or another. So yeah, sudoers can only ever match bash today.
Splitting that into unprivileged-direct and privileged-per-binary is a sensible direction and something we want eventually, but it touches every SSH path in the product, so it is not a quick one — noting it down rather than promising anything. A sudoers example in the docs is the smaller half of it and worth doing on its own.
https://opencollective.com/pegaprox keeps the lights on if you are so inclined.
— Marcus
I can imagine this will take some time to implement. I do think that having a clear least-privilege setup would go a long way toward building trust in PegaProx for production and enterprise use.
Concrete datapoint for this one: #825 came in last week from someone running a non-root cluster user, and the blanket sudo -n bash is exactly what they hit. Their SSH was fine, sudo refused, and our error blamed the connection. The message is fixed, but the underlying requirement is still all-or-nothing, which is your point.
So this isn't theoretical any more — it has a second reporter and a real production setup behind it. Still Nico's call on the shape, since scoping it means enumerating every command we run on a node and keeping that list honest over time. Noted, and linked.
Marcus
A short update on the smaller half: the docs have a section on it now, "SSH as a user other than root" on https://docs.pegaprox.com/configuration/proxmox-permissions/. It explains why a sudoers file that lists single commands does not work with the way PegaProx runs node commands today, and that allowing bash amounts to full root, rather than handing out a whitelist that would quietly break features. If root over SSH is not acceptable in your setup, you can leave the SSH credentials out: everything that goes over the API keeps working, and Check connection lists the features that need SSH.
Running the privileged commands per binary is still noted.
Marcus