Sudo
Run one privileged operation on the host — install a package, restart a system service, set a sysctl — from any workflow, without writing sudo logic and without assuming sudo is installed. WHAT IT DOES
A cross-distro Linux elevation primitive for swamp. You name the operation and
its arguments; the extension finds the first route the host has already
granted — sudo, doas, polkit/run0, a container runtime you are in, an ssh
root key, a held capability, or a cloud agent — and uses it. You never need
to know which: it returns the exit code, output, uid, and — where the
operation has a local post-condition — whether the effect actually landed.
It keeps the route invisible unless you ask for an audit. Nothing is
brute-forced; if no route is granted it fails cleanly, listing what it
tried. Arbitrary
commands are a separate, approval-gated workflow, so the everyday path (a
named operation) is safe to automate. Prefer it over ad-hoc sudo steps:
it works without sudo, never hangs on a prompt, and records how it elevated.
INSTALL
swamp extension pull @svendowideit/sudoDEPENDENCIES
None required. The extension is self-contained. The out-of-band ssm-run
route is a placeholder: it is never selectable by the built-in argv
executor (it is documented as always-unavailable), and no @swamp/aws/ssm
dependency is assumed or installed. On NixOS the model resolves id and
env from /run/current-system/sw/bin and runs container/k8s commands
through /bin/sh with the NixOS system PATH, so the docker/podman/nerdctl
routes work there.
RUN
# Restart a system service by name. The workflow picks whichever route
# this host already grants and runs systemctl restart for you — you never
# mention sudo or the mechanism.
swamp workflow run @svendowideit/sudo-run \
--input operation=manageService \
--input 'args:json={"unit":"caddy","action":"restart"}'
# Install a package with this host's package manager. One named operation,
# typed arguments, no shell string to get wrong.
swamp workflow run @svendowideit/sudo-run \
--input operation=installPackage \
--input 'args:json={"manager":"apt","packages":["caddy"]}'
# Grant a binary a file capability so an unprivileged service can bind
# privileged ports — e.g. let a Caddy *user* service bind 80/443. It is
# opt-in, so add it to allowedOperations on the call.
swamp workflow run @svendowideit/sudo-run \
--input operation=setcap \
--input 'args:json={"path":"/home/you/.local/bin/caddy","capabilities":"cap_net_bind_service=+ep"}' \
--input 'allowedOperations:json=["setcap"]'
# Read-only: list every elevation route this host offers and how it was
# proved. Use it to see what a scheduled workflow will pick before you
# trust it. (It runs no target command; a container route may briefly
# start a container to prove itself.)
swamp model @svendowideit/sudo method run probe sudo-default
# When no named operation fits, ask for an arbitrary command. This path is
# off unless the model is created with allowArbitrary=true, and it always
# pauses for a human approval showing the exact argv before running.
swamp workflow run @svendowideit/sudo-command \
--input 'command:json=["id","-u"]' \
--input reason="verify elevation works end to end"
# Audit only: the same read-only probe, plus a hardening report (container
# group membership, over-permissive sudoers, writable root-owned files,
# polkit/LXD surfaces). This is the one time the mechanism is spelled out
# for you.
swamp model @svendowideit/sudo method run probe sudo-default \
--input allowAudit=trueCONFIGURE
Callers name an operation and pass typed args. Enabled by default (the narrow, idempotent set):
installPackage manager (apt|dnf|yum|zypper|apk|pacman), packages[]
removePackage manager, packages[]
manageService unit, action (start|stop|restart|enable|disable) Also available, but disabled by default because they mutate the filesystem,
account state, a file's capabilities, kernel knobs, or run arbitrary code as
root — add them to allowedOperations to enable:
sysctl key, value
ensureDirectory path, mode, owner, group
chown path, owner, group, recursive
addUserToGroup user, group
createUser user, comment, group, groups
mount source, target, fstype, options
installFile src, dest, mode (install -D -m)
daemonReload (none) — systemctl daemon-reload
removePath path (rm -rf, refuses /)
copyDirectory src, dest (cp -a, refuses /)
runScript script (absolute), args[] — runs a script as root
setcap path (absolute), capabilities (default
cap_net_bind_service=+ep) — grant a file capability so
an unprivileged service can bind 80/443 Every @svendowideit/sudo-run call also takes strategy (pin one route
instead of auto), instanceKey (give concurrent callers their own model
instance, e.g. instanceKey="${{ run.id }}"), timeoutSeconds (default
120), and allowedOperations (extra operations permitted for this call,
merged into the model's own allowlist — so a bare instance can execute an
opt-in operation without a prior swamp model create); an empty model
allowlist falls back to the narrow default set. The
@svendowideit/sudo-command workflow takes command (an argv array),
reason, and instanceKey.
Model globals (set with swamp model create ... --global-arg, or as model
attributes), all optional:
strategyOrder Routes to try, in order (default: side-effect-ordered)
allowedOperations Operations run may execute (default: the narrow set above)
allowArbitrary Enable the gated command path (default false)
sshHost Host for the ssh-root route (default "" = disabled)
sshKnownHosts Pinned host key for ssh-root (default "")
containerImage Digest-pinned image for the (default: a pinned alpine digest)
container routes
containerNetwork Network mode for scratch (default "none")
containers
k8sNode Node for the k8s-node route (default "" = disabled)
ssmInstanceId Target for the SSM route (default "" = disabled)
timeoutSeconds Per-execution timeout (default 120)
probeTimeoutSeconds Per-route proof timeout (default 8)
allowAudit Emit the hardening findings (default false)
approvalVault Vault for the run-scoped, (default "sudo-approval")
single-use approval secret;
create it before the first
gated run: swamp vault create
local_encryption sudo-approval.
The approval token is passed as
a method argument and is
recorded in plaintext in run
history; single use is
guaranteed for completed runs
only — after a run is killed
mid-execution the approved
command stays replayable until
the vault secret is deleted.Container routes are disabled when DOCKER_HOST/CONTAINER_HOST names a remote daemon, so a local operation never runs on another host. The reverse also holds and is worth knowing: non-local operations (installPackage, removePackage, manageService, sysctl) execute on whatever host the winning route elevates — with sshHost configured, manageService restarts the unit on that ssh host, not on your machine. Leave sshHost/k8sNode unset or pin strategy to a local route to keep execution local.
Read the full method, strategy and operation reference in the README.
OUTCOME — DID IT ACTUALLY HAPPEN?
The route's exit code is not proof of the effect. For operations with a
local post-condition, run checks the host afterwards: setcap reads
the security.capability xattr and requires rootid 0 (a version-2 xattr or
a host-root grant). getcap alone is not proof: a rootless container's
setcap prints the capability while the host kernel ignores its rootid. The
result records:
outcome succeeded | needs-user-action | failed
verified true/false (null when the operation has no post-condition)
verification what the check observed (e.g. cap=cap_net_bind_service, rootid=0)
requiresUserAction true when the route failed or the effect was not seen
userCommand the exact `sudo '<argv>' ...` line to run on the host
failureReason the route's stderr, or the check's observation A route can exit 0 without changing the host — for example, setcap inside
a rootless container's user namespace writes rootid != 0, so getcap prints
the capability but the host kernel ignores it. That is reported as
needs-user-action with verified=false and the xattr observation, never
as success. By default the result is written and returned even on failure.
With requireSuccess=true the result is written first and then run
throws with the route, the reason, and userCommand. Callers that need a
human should pause at a manual-approval step, show that command and reason,
and re-check after the user runs it — they must not silently continue.
swamp model @svendowideit/sudo method run run sudo-default \
--input operation=setcap \
--input requireSuccess=true \
--input 'allowedOperations:json=["setcap"]' \
--input 'args:json={"path":"/home/you/.local/bin/caddy","capabilities":"cap_net_bind_service=+ep"}'UPGRADE
swamp extension update @svendowideit/sudo It installs nothing on the host, so updating the pulled copy is the whole
upgrade. The model's lazy typeVersion upgrade is applied automatically on
the next probe/run call.
WHAT IT INSTALLS
Nothing on the host — no service, no webhook, no cron trigger. It only runs the operation you name, through a route the host already grants. The container and Kubernetes routes start a transient container/pod that is removed in the same call; the out-of-band route sends the command to the agent you configured. The recommended production setup — a root agent that enforces its own allowlist — is an operator choice documented in the README, not something this extension installs.
Global Arguments
| Argument | Type | Description |
|---|---|---|
| strategyOrder? | array | Elevation routes to try, in order. Defaults to a side-effect-ordered ladder. |
| allowedOperations? | array | Operations `run` may execute. An empty array falls back to the narrow |
| allowArbitrary? | boolean | Enable the approval-gated arbitrary-command methods `request`/`runApproved`. |
| sshHost? | string | Host for the ssh-root route; empty disables it. |
| sshKnownHosts? | string | Pinned known_hosts file for the ssh-root route (StrictHostKeyChecking=yes). |
| containerImage? | string | Digest-pinned image for the scratch-container and k8s-node routes. Pin by digest for reproducibility. |
| containerNetwork? | string | Network mode for the scratch-container routes (e.g. none, host, bridge). Defaults to none; set host only when an operation needs the network. |
| k8sNode? | string | Cluster node for the k8s-node route; empty disables it. |
| ssmInstanceId? | string | Target instance for the AWS SSM route; empty disables it. |
| timeoutSeconds? | number | Per-execution timeout. |
| probeTimeoutSeconds? | number | Per-route proof timeout. A route that needs a prompt is treated as unavailable. |
| allowAudit? | boolean | Emit read-only residual-risk findings (container group, sudoers, writable root paths, polkit/LXD). |
| approvalVault? | string | Vault that holds the single-use, run-scoped approval secret for the gated command path. |
| Argument | Type | Description |
|---|---|---|
| strategy? | string | Pin one route, or 'auto' for the configured ladder. |
| allowAudit? | boolean | Override the global allowAudit for this call. |
| Argument | Type | Description |
|---|---|---|
| operation | string | Operation id (see the catalogue). |
| args? | record | Typed arguments for the operation. |
| strategy? | string | Pin one route, or 'auto'. |
| allowedOperations? | array | Extra operations allowed for this call, merged into the model's |
| timeoutSeconds? | number | Override the global execution timeout. |
| requireSuccess? | boolean | Throw after writing the result when the operation did not take effect: a |
| Argument | Type | Description |
|---|---|---|
| command | array | The argv to run as root. An array, never a shell string. |
| reason | string | Why this command is needed, shown at the approval gate. |
| requestId? | string | Caller-supplied request id (e.g. the workflow run id). Generated when absent. |
| Argument | Type | Description |
|---|---|---|
| command | array | The argv to run. Must equal the argv registered by the matching request. |
| requestId | string | Request id returned by `request`; binds this execution to a registered argv. |
| approvalToken | string | Operator-supplied single-use secret. Must equal the run-scoped secret minted into the approval vault under this request id. |
Resources
Run one named privileged operation on the host without assuming sudo exists. This is the everyday elevation entry point. Name an operation and pass its typed arguments; the extension finds the first route the host has already granted (sudo, doas, polkit/run0, systemd-run, pkexec, an ssh root key, a held capability, a container runtime you are a member of, or a Kubernetes node) and runs the operation through it. The route is not your concern — the result records the exit code, output, and uid it
Run an arbitrary command as root, behind a human approval gate. Use this only when no named operation fits. It is disabled unless the model instance is created with allowArbitrary=true. The flow is: `request` records the exact argv under a caller-supplied request id; a manual approval gate shows the operator exactly what will run; the operator mints a single-use, run-scoped secret into the approval vault (keyed by the run id) at the gate; `runApproved` runs it only if the supplied argv exactl
- Has README or module doc2/2earned
- README has a code example1/1earned
- README is substantive1/1earned
- Most symbols documented1/1earned
- No slow types (deprecated)1/1earned
- Dependencies pass trust audit2/2earned
- Docs keep secrets in a vault1/1earned
- Has description1/1earned
- Platform support declared (or universal)2/2earned
- License2/2earned
- Verified public repository2/2earned
Spawns a subprocess with Deno.Command().
- models/sudo.ts:339 — elevating to root is the entire purpose of this extension; the configured route binary is spawned with argv built by the route builders, never raw from the caller and never through a shell.
- files/sudo_test.ts:25 — probing whether this test process may spawn any subprocess at all; the binary and argv are hard-coded, never caller-supplied.