Repository navigation
Conversation
There was a problem hiding this comment.
🟡 Changes recommended
Unhandled SIGHUP or SIGTERM can terminate the runner without cleanup, allowing detached guest descendants to run indefinitely and leaving the job cgroup behind.
1 open issue
What changed in this PR
Adds one-shot execution in running Proxmox guests through Manager authentication, supporting #541 without requiring guest SSH access.
Changes:
- Adds an owner/admin-authorized API and OS provider capability preserving arguments, output streams, and exit status.
- Introduces a restricted node runner with identity checks, privilege grants, and execution limits.
- Adds tests, CI coverage, and deployment instructions.
| File | Description |
|---|---|
packages/os-cloud-provider/test/provider.test.ts |
Tests provider execution and error handling. |
packages/os-cloud-provider/test/exec-guest.e2e.mjs |
Checks CLI execution and authorization end to end. |
packages/os-cloud-provider/src/index.ts |
Exposes the exec capability. |
packages/os-cloud-provider/src/exec.ts |
Implements requests and validates results. |
packages/os-cloud-provider/src/deploy.ts |
Exports the shared authenticated client factory. |
packages/os-cloud-provider/src/client.ts |
Supports preserving permission-denial errors. |
packages/os-cloud-provider/README.md |
Documents CLI usage and retry precautions. |
mie-opensource-landing/zensical.toml |
Adds administrator documentation navigation. |
mie-opensource-landing/docs/admins/guest-exec.md |
Documents setup, privileges, and limits. |
images/proxmox-ve/guest-exec/tests/verify.py |
Checks runner behavior in an LXC guest. |
images/proxmox-ve/guest-exec/tests/lxc.sh |
Creates the disposable LXC fixture. |
images/proxmox-ve/guest-exec/mieweb-guest-exec |
Implements restricted guest execution and cleanup. |
images/proxmox-ve/guest-exec/install-node.sh |
Installs the runner and Python bindings. |
create-a-container/utils/guest-exec.js |
Dispatches over restricted SSH and validates replies. |
create-a-container/routers/api/v1/containers.js |
Adds authorization, validation, and auditing. |
create-a-container/routers/api/v1/__tests__/containers.exec.test.js |
Tests API permissions, validation, and outcomes. |
create-a-container/openapi.v1.yaml |
Defines the execution API contract. |
.github/workflows/os-cloud-provider.yml |
Includes execution route tests and triggers. |
Review effort: Balanced
There was a problem hiding this comment.
🔵 Needs a closer look
The root-run SSH runner crosses host–guest security boundaries, requiring human security review and real Proxmox node validation of liblxc attachment, lifecycle locking, and cgroup cleanup beyond the substituted-configuration fixture.
Review effort: Balanced
There was a problem hiding this comment.
🔵 Needs a closer look
The root-run SSH runner crosses namespace and cgroup security boundaries, requiring human security review and native Proxmox validation because the fixture does not exercise lifecycle locking.
No open issues 🎉
1 resolved since last review
Review effort: Balanced
|
I validated commit
A cold The VM and its disks have been removed. The host/guest privilege boundary is ready for independent human security review. |
There was a problem hiding this comment.
🔵 Needs a closer look
The root-run SSH/liblxc security boundary requires maintainer review and real Proxmox validation of lifecycle locking, ABI compatibility, and cgroup handling, since the fixture substitutes Proxmox configuration lookup.
No open issues 🎉
Review effort: Balanced
There was a problem hiding this comment.
🔵 Needs a closer look
The root-run SSH/liblxc bridge crosses host–guest privilege boundaries, requiring independent security review of credentials, capabilities, containment, and guest-root grants beyond the reported acceptance tests.
No open issues 🎉
Review effort: Balanced
runleveldev
left a comment
There was a problem hiding this comment.
Requesting changes
Thanks for this. The work is careful, and much of the Manager side is well thought out: owner/admin authorization, argument and output limits, unknown-outcome handling that never retries, and auditing that omits arguments and output. I can't accept the node-side design, though. It breaks something that has been a goal of this project, even if we never wrote it down: this software does not touch the underlying Proxmox hosts. The only exceptions are the local compose stack, which is dev only, and small changes an admin can easily understand, such as creating the volumes directory or the NVIDIA snippets. I should have documented that more clearly, and I'll make sure it gets written down.
Why the node-side runner doesn't fit
-
Installation. Setup is currently a single container: the Manager image. This PR adds manual steps on every Proxmox node (run
install-node.sh, edit root'sauthorized_keys) and on Manager for every site and node pair (generate a key, writessh_config, add the node's host key toknown_hostsunder/etc/mieweb/guest-exec/<site>/<node>/). None of this can be done through the UI or API, and the work grows with every node added. -
Maintenance and fragility. We currently support any Proxmox version with a compatible API. The runner relies on Proxmox internals that aren't public interfaces:
- the lock file path
/run/lock/lxc/pve-config-<vmid>.lock - the output format of
pct config --current - the owner tag being the first tag
- the cgroup v2 layout and
cgroup.kill - liblxc's attach behavior
install-node.shalso downloads Debian'spython3-lxcand copies its bindings into/usr/local, where they load against theliblxc.so.1that ships withlxc-pve. Nothing guarantees those two are compatible. The docs already say to re-run the installer after upgrading the node's distribution or Python. Any of these can break on a routine Proxmox update. - the lock file path
-
Administration. Today admins can change their Proxmox hosts to meet their own organizational requirements, and this software keeps working. This PR adds state that each node has to preserve:
/usr/local/lib/mieweb-guest-exec, entries inauthorized_keys, and the root-grant files in/etc/mieweb/guest-exec-root/. Ordinary hardening, such as disabling root SSH or managingauthorized_keyscentrally, breaks exec. Root grants also live on node filesystems instead of in Manager's database, so authorization is split between Manager and files on each hypervisor that the UI and API can't see. -
Access and security. It isn't a listening daemon, but it gives every hypervisor a root entry point that Manager can reach with a key. The forced command and the
restrict/from=options narrow it. Still, if Manager or that key is compromised, the attacker can run root code that attaches to guests on every enabled node. Also, on a clustered PVE install/root/.ssh/authorized_keysis normally a symlink to/etc/pve/priv/authorized_keys, which is shared across the cluster. If so, the "dedicated key per node" setup actually applies to every node in the cluster. Either way, this is the kind of interaction with the host we should avoid. -
Updates. The runner has no update path. Every release that changes the runner or its protocol needs an admin to redeploy it to every node, in the right order relative to Manager. The PR already needs a strict rollout order: Manager, then the nodes, then the OS provider, then the CLI.
-
Operations. We don't currently require SSH access from Manager to the Proxmox nodes, only API access. This adds a new network path (Manager to each node's management IP on port 22), an SSH client in the Manager image, and per-node key and host-key management.
-
Test coverage. CI uses a fixture that replaces Proxmox's configuration lookup with a stand-in. The real Proxmox behavior (the lock,
pct config, the liblxc ABI) was checked by hand on one disposable PVE 9.3.1 VM. So the parts most likely to break on upgrades are the parts CI doesn't cover.
Other concerns
Running as UID/GID 1000 by default. Unless a root-grant file on the node matches the request, the runner runs commands as UID and GID 1000 (mieweb-guest-exec:68-70, docs/admins/guest-exec.md:48). Nothing else in this project gives UID 1000 a special meaning, and the assumption doesn't hold up:
- There may be no such user in the guest. Guests come from arbitrary Docker/OCI images, and many have no account with UID 1000. The command then runs as an unnamed UID with no home directory, no shell entry and none of the permissions the image expects.
- It isn't the caller's identity. Manager users have their own LDAP
uidNumber, so UID 1000 doesn't correspond to the person running the command. It's an arbitrary unprivileged ID, and its security benefit is unclear. - It doesn't match how ownership works today. The container owner already has full control of the guest: they choose the image and entrypoint, and they can SSH in. Running their commands as non-root protects nothing meaningful. It mainly breaks routine work like installing packages.
- It forces the root-grant mechanism. The non-root default is the reason per-node grant files exist. That puts authorization state on hypervisor filesystems, which makes the problem in point 3 worse.
Unless there's a specific threat model behind it, commands should run as guest root for owners and admins. If a different user is ever needed, it should be an optional per-request user name that the guest resolves, not a fixed numeric ID.
Exec cleanup kills daemons the user deliberately started. The runner puts each command in its own cgroup and writes to cgroup.kill when the command finishes or times out. As documented, this includes detached children and descendants that call setsid() (mieweb-guest-exec:225-226, docs/admins/guest-exec.md:62). So mieweb exec -- systemctl start foo keeps working, because systemd starts the service outside the exec's cgroup. But mieweb exec -- ./start-server.sh or nohup myapp & is killed the moment the exec returns. That breaks the behavior people expect from SSH: closing the session hangs up plain background jobs, but processes that detached on purpose keep running. The docs suggest using the guest's service manager, which assumes every guest image has one, and many Docker-derived guests don't. Cleanup should kill the command only when it times out. It shouldn't kill processes the command deliberately detached.
Preferred approach: termproxy with cmode: shell and a POSIX wrapper
This uses only the existing Proxmox API and the token Manager already stores for each node. Nothing is installed on the hosts or in the guests, and no new ports or SSH access are needed.
Background
- The Proxmox API has no LXC equivalent of the QEMU guest agent's
agent/exec, butPOST /nodes/{node}/lxc/{vmid}/termproxyplus thevncwebsocketWebSocket gives a terminal session in the guest. termproxyreads the container config on every call and builds the console command fromcmode(pve-containersrc/PVE/LXC.pmget_console_command):cmode: tty(the default) andcmode: consolerunlxc-console, which shows a getty login prompt.cmode: shellrunslxc-attach --clear-env -n <vmid>, a root shell with no login.
- Manager can set
cmode: shellthrough the API. That's a guest config change, not a change to the host. On a running guest, though, the change doesn't take effect until the guest restarts (confirmed on a real Proxmox node). Manager should therefore setcmode: shellwhen it creates the container, before the first start, so new guests support exec with no extra steps. Existing guests need a one-time restart, which Manager can trigger or leave to the owner. Exec on a guest that is still inttymode should fail with a clear "restart required" error instead of hanging at a login prompt. Manager can detect this withGET /nodes/{node}/lxc/{vmid}/pending, or by looking for a login prompt instead of the ready marker. termproxywraps the console indtach -A /var/run/dtach/vzctlconsole<vmid>(src/PVE/API2/LXC.pm,termproxy). Every console connection to the same guest therefore joins one shared, persistent session. Two simultaneous connections share the same shell, and closing the WebSocket only disconnects from the session without ending it. The wrapper below is designed for this.
Protocol
Before each exec, Manager:
- Generates a random per-request value
N(for example, 128 bits as hex). - Quotes each argv element for the shell: wrap it in single quotes and replace every
'with'\''. NUL bytes are already rejected. - Allows only one exec per guest at a time.
Step 1: bootstrap. Manager sends this single line, followed by CR (\r), to whatever shell lxc-attach started (the guest root's login shell). It then discards all output until MIEWEB-READY-N appears:
stty -echo -icanon -iexten -isig -ixon -icrnl -inlcr -igncr -istrip -opost min 1 time 0; printf 'M\111EWEB-READY-%s\n' N; exec /bin/sh -s 2>/dev/nullsttyputs the terminal into raw mode: no echo, no line buffering or line-length limit, no special handling of control characters (^C,^D,^V,^S/^Q), and no CR/LF translation in either direction.- The
\111escape means the echoed copy of this line can't match the ready marker. Only the realprintfoutput printsMIEWEB-READY-N. exec /bin/sh -s 2>/dev/nullreplaces the login shell (which may be bash with line editing and tab completion) with a non-interactive POSIXshthat reads the rest of its script from the terminal. Redirecting stderr makes it non-interactive, so there are no prompts and no line editing.
Step 2: wrapper. After the ready marker appears, Manager sends the wrapper. Here N is the per-request value and the fifth line is the quoted argv, in this example ls -la /root:
d=/tmp/.mieweb-exec-N
umask 077
mkdir "$d" || { printf '\nMIEWEB-ERROR-N\n'; exit 1; }
cd / || exit 1
'ls' '-la' '/root' </dev/null >"$d/o" 2>"$d/e" &
p=$!
( sleep 30; : >"$d/t"; kill -s KILL "$p" ) </dev/null >/dev/null 2>&1 &
w=$!
wait "$p"; rc=$?
kill -s KILL "$w" 2>/dev/null
t=0; [ -e "$d/t" ] && t=1
printf '\nMIEWEB-BEGIN-N %s %s %s %s\n' "$rc" "$t" $(wc -c <"$d/o") $(wc -c <"$d/e")
dd if="$d/o" bs=65536 count=1 2>/dev/null | od -A n -t x1 -v
printf 'MIEWEB-SPLIT-N\n'
dd if="$d/e" bs=65536 count=1 2>/dev/null | od -A n -t x1 -v
printf 'MIEWEB-END-N\n'
rm -rf "$d"
exit "$rc"What each part does:
- Scratch directory.
mkdirwithumask 077creates a private directory named withN. It fails if the path already exists, so concurrent runs can't collide and a pre-created symlink can't redirect the output. </dev/nullis required. The shell reads this script from the terminal. Without it, the command would consume the rest of the wrapper as its input.- Separate output streams. stdout and stderr go to separate files, so they never pass through the terminal raw.
- Timeout without
timeout.timeoutisn't POSIX. A backgroundsleep 30records a timeout flag and kills only the command.waitreturns the command's exit code, or 128 plus the signal number if it was killed, the same as the current PR. - Output encoding. POSIX has no
base64(uuencode -mis POSIX but rarely installed), so each stream is hex-encoded withod.ddcaps each one at 64 KiB, andwc -creports the full size so Manager can flag truncation. The command's output can never be mistaken for a marker, because it only reaches the terminal as hex. - Exiting.
exitends the shell, which ends the terminal session and the shareddtachsession with it. The kernel then sends SIGHUP to the shell's process group. That stops the timeout watcher and any plain&background jobs, while processes that detached on purpose (setsid, a double fork,nohup) keep running. This is the same as closing an SSH session.
Step 3: parsing. Manager reads until MIEWEB-END-N, or treats a missing marker as an error (see the last bullet):
MIEWEB-BEGIN-N <exitCode> <timedOut> <stdoutBytes> <stderrBytes>: a stream was truncated if its byte count is over 65536.- The hex between
BEGINandSPLITis stdout, and the hex betweenSPLITandENDis stderr. Strip the whitespace and decode it. MIEWEB-ERROR-Nmeans nothing was run.- If
ENDdoesn't arrive within an overall deadline (about 40 seconds), the outcome is unknown and must not be retried. That keeps the PR's current semantics.
What has been tested
- Shells: the wrapper ran under bash, dash (
debian:stable-slim) and BusyBox ash (alpine). It kept a literal argument containing', returned stdout and stderr separately and kept exit code 23. - Timeout: scaled down to 2 seconds, it returned exit code 137 with the timed-out flag set.
- Terminal bootstrap: the full bootstrap plus wrapper was run through a real terminal against both an interactive
bash -i(with line editing) andsh -i. A 10,017-byte argument containing tab,^C,^D,^V,^Q,^S, CR and'arrived at the command with exactly its original length. - Process lifetime: run through a terminal, a command that started
sleep &,setsid sleep &andnohup sleep &left thesetsidandnohupprocesses running after the exec. The plain background job and the timeout watcher were hung up. - Not yet tested: the actual
termproxy/vncwebsocket/dtachpath on Proxmox. The only thing confirmed on a real node so far is that changingcmodeon a running guest requires a restart.
Known limitations and open items
- Shared
dtachsession. Manager's one-exec-per-guest rule prevents its own collisions. But if someone has the Proxmox web console open, or a previous session is stuck, the bootstrap line is typed into that shell. Manager can't detect a person who is attached. We should document this and maybe check for it. - API token permissions. Manager's API token needs
VM.Console, plus permission to changecmode. Please confirm thatvncwebsocketworks with API token authentication and not only with ticket authentication. - Existing guests need a restart. Changing
cmodeonly takes effect after a restart, so the rollout needs a plan for guests that were created before this change. For example: setcmode: shellon all of them, and have exec report "restart required" until each guest has restarted. cmode: shellgives passwordless root to any Proxmox user withVM.Consoleon that guest. That's probably acceptable for our deployments, but it should be documented.- Tools required in the guest:
sh,stty,mkdir,sleep,wc,ddandod. Nearly every image has them, but distroless images have no shell. For those, exec should return the existing "unavailable" error. - No disk cap while the command runs. Output is truncated only afterwards, so a very noisy command could fill
/tmpwithin 30 seconds.ulimit -fwould cap it, but it kills the command withSIGXFSZ. I think the risk is acceptable without it. - The command can fake the markers. It can write to
/dev/ttyand discoverNthrough/proc/self/fd. That only lets it fake its own result to its own owner, so it isn't a security issue.
Also acceptable: an agent inside each guest
An agent in each guest that connects out to Manager, by long-polling or over a WebSocket, also needs no host changes, no new ports and no SSH. It would remove the terminal-related limitations above. The trade-offs are that every guest image needs the agent installed and it needs an update strategy. The authorization, limits and auditing in this PR would carry over almost unchanged.
If an agent on each node is truly necessary
I'd want to see why neither approach above can work. If a node agent is still needed, it must meet all of these:
- Packaged as a DEB, like the other components in this repo, with every non-system dependency bundled (PyPI packages, and the LXC Python bindings if they're still needed). No
apt-get downloadand copying into/usr/local. - Run as a sandboxed systemd service, preferably as a non-root user, with a bundled sudo and/or polkit policy for any privileges it needs. Use the usual systemd hardening options (
ProtectSystem=,NoNewPrivileges=, a minimalCapabilityBoundingSet=and so on). - No inbound connections to the node. We can't extend the Proxmox API, and I don't want to open a second port or require SSH. The agent should connect to Manager over HTTPS and either long-poll for jobs or hold a WebSocket open. Every configured site can already reach Manager's HTTP API, so this adds no new network requirement. The agent should register and authenticate through Manager, for example with an admin API key, not through keys placed on the node by hand.
Suggested path forward
The parts of this PR that don't depend on the execution method look reusable: the POST /sites/{siteId}/containers/{id}/exec contract in OpenAPI, the authorization checks, the argument and output limits, the unknown-outcome behavior, auditing, the OS provider and the CLI. Please keep those and replace the SSH runner with the termproxy approach above. Drop the UID 1000 default and the cleanup that kills detached processes. Happy to talk through any of it before you start.
|
We're taking this change over in #546. That PR keeps the parts of this one that don't depend on the execution method (the API contract, route, tests and OS provider), credited to @horner, and replaces the SSH node runner with a Proxmox |
Pull request was closed
Replace the SSH node runner from #543 with the Proxmox API alone. Nothing is installed on the Proxmox hosts and Manager needs no SSH access to them. With cmode: shell, the console that termproxy opens for a container is a root shell with no login. Manager connects to it with the existing node credentials over vncwebsocket and types a bootstrap line that puts the terminal into raw mode and switches to a non-interactive sh -s. It then sends a POSIX wrapper that runs the quoted argv with stdout and stderr redirected to files and a 30-second limit, and prints the exit code and hex-encoded streams between markers that contain a per-request nonce. * Containers get cmode: shell at create and reconfigure. On a running container the change waits for a restart, so the first exec on an older container sets it and returns exec_restart_required. * Commands run as guest root. The UID 1000 default and root grants are gone. * When the command returns, the shell exits, so plain background jobs get SIGHUP. Processes started with setsid or nohup keep running. * Only one exec runs per container at a time (exec_busy), because Proxmox shares a single dtach console session per container. * The live hostname and running state are checked through the API before the console is opened. Adds ws, because the WebSocket built into Node can't take the node's TLS agent or auth headers.
Carry over the parts of #543 that don't depend on how a command reaches the guest. These are the exec_container OpenAPI contract, the owner/admin route with its argument limits, error mapping and audit logging, the route tests, the OS provider exec verb with its tests, and the CI triggers. The SSH node runner, its installer and fixtures, and the setup docs are intentionally left behind (see the review on #543). The route still imports utils/guest-exec. A Proxmox termproxy backend replaces it in a follow-up commit. Co-authored-by: Doug Horner <horner@mieweb.com>
Replace the SSH node runner from #543 with the Proxmox API alone. Nothing is installed on the Proxmox hosts and Manager needs no SSH access to them. With cmode: shell, the console that termproxy opens for a container is a root shell with no login. Manager connects to it with the existing node credentials over vncwebsocket and types a bootstrap line that puts the terminal into raw mode and switches to a non-interactive sh -s. It then sends a POSIX wrapper that runs the quoted argv with stdout and stderr redirected to files and a 30-second limit, and prints the exit code and hex-encoded streams between markers that contain a per-request nonce. * Containers get cmode: shell at create and reconfigure. On a running container the change waits for a restart, so the first exec on an older container sets it and returns exec_restart_required. * Commands run as guest root. The UID 1000 default and root grants are gone. * When the command returns, the shell exits, so plain background jobs get SIGHUP. Processes started with setsid or nohup keep running. * Only one exec runs per container at a time (exec_busy), because Proxmox shares a single dtach console session per container. * The live hostname and running state are checked through the API before the console is opened. Adds ws, because the WebSocket built into Node can't take the node's TLS agent or auth headers.

Part of #541.
A container owner or Manager administrator can run a one-shot command in an already-running unprivileged Proxmox LXC guest with their existing Manager login. The guest needs no SSH server or published port.
POST /api/v1/sites/{siteId}/containers/{id}/execand the OS provider implementation. Preserve literal argv, both output streams and the guest exit status. An interrupted request reports an unknown outcome and is never replayed.Verification
All 12 Manager route tests and 126 provider tests passed. The provider typecheck and build passed. The complete Manager suite had one unrelated MCP proxy failure which also reproduces on the unchanged base.
A real CLI and provider exercised the HTTP API, Manager credentials, a restricted SSH connection, and an unprivileged Linux LXC guest with SSH unpublished. It preserved a literal argument, returned separate stdout/stderr with exit status 23, and denied a different owner's guest before dispatch.
A dropped HTTP reply after a completed state-changing command produced CLI status 125 and an unknown-outcome diagnostic. An independent guest read confirmed exactly one execution.
The standalone nested-LXC suite covers UID/GID, grants, binary output, truncation, timeout and cleanup of detached descendants. The fixture substitutes Proxmox configuration lookup. Process execution, user namespaces and cgroups are real. Run it with
bash images/proxmox-ve/guest-exec/tests/lxc.sh.On a disposable Proxmox VE 9.3.1 VM, the installed runner passed all six acceptance tests against an unprivileged guest. Holding the actual Proxmox guest configuration lock prevented dispatch, and the command succeeded after unlock. SIGHUP and SIGTERM each removed the job cgroup and reaped the command and its detached child. Proxmox validation details
Deploy Manager, configure the node and release the OS provider before releasing the CLI companion.
CLI companion: mieweb/cloud#30