Skip to main content

Sudo

@svendowideit/sudov2026.11.07.4· MIT(was none)· 17d agoBEHAVIORSWORKFLOWSACCEPTED WARNINGS
01README

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/sudo

DEPENDENCIES

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=true

CONFIGURE

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.

02Behaviors1
@svendowideit/sudov2026.11.07.4sudo.ts

Global Arguments

ArgumentTypeDescription
strategyOrder?arrayElevation routes to try, in order. Defaults to a side-effect-ordered ladder.
allowedOperations?arrayOperations `run` may execute. An empty array falls back to the narrow
allowArbitrary?booleanEnable the approval-gated arbitrary-command methods `request`/`runApproved`.
sshHost?stringHost for the ssh-root route; empty disables it.
sshKnownHosts?stringPinned known_hosts file for the ssh-root route (StrictHostKeyChecking=yes).
containerImage?stringDigest-pinned image for the scratch-container and k8s-node routes. Pin by digest for reproducibility.
containerNetwork?stringNetwork mode for the scratch-container routes (e.g. none, host, bridge). Defaults to none; set host only when an operation needs the network.
k8sNode?stringCluster node for the k8s-node route; empty disables it.
ssmInstanceId?stringTarget instance for the AWS SSM route; empty disables it.
timeoutSeconds?numberPer-execution timeout.
probeTimeoutSeconds?numberPer-route proof timeout. A route that needs a prompt is treated as unavailable.
allowAudit?booleanEmit read-only residual-risk findings (container group, sudoers, writable root paths, polkit/LXD).
approvalVault?stringVault that holds the single-use, run-scoped approval secret for the gated command path.
fn probe(strategy?: string, allowAudit?: boolean)
Enumerate the elevation ladder and report the first route that proves host root; optionally emit read-only residual-risk findings. Never runs the target command, but may start a transient privileged container/pod to prove a container route.
ArgumentTypeDescription
strategy?stringPin one route, or 'auto' for the configured ladder.
allowAudit?booleanOverride the global allowAudit for this call.
fn run(operation: string, args?: record, strategy?: string, allowedOperations?: array, timeoutSeconds?: number, requireSuccess?: boolean)
Execute a named operation through the resolved elevation route. Records exit code, output, route, and whether the effect was locally verified. A non-zero program exit is recorded, not thrown, unless requireSuccess=true; then it writes the result and throws with the route, the reason, and the exact host command to run. Callers that need a human can use the result's requiresUserAction/userCommand/failureReason at a manual-approval step.
ArgumentTypeDescription
operationstringOperation id (see the catalogue).
args?recordTyped arguments for the operation.
strategy?stringPin one route, or 'auto'.
allowedOperations?arrayExtra operations allowed for this call, merged into the model's
timeoutSeconds?numberOverride the global execution timeout.
requireSuccess?booleanThrow after writing the result when the operation did not take effect: a
fn request(command: array, reason: string, requestId?: string)
Register an arbitrary argv and mint a request id. Requires allowArbitrary=true. The caller must present the request id, a matching argv, and an operator approval token to runApproved.
ArgumentTypeDescription
commandarrayThe argv to run as root. An array, never a shell string.
reasonstringWhy this command is needed, shown at the approval gate.
requestId?stringCaller-supplied request id (e.g. the workflow run id). Generated when absent.
fn runApproved(command: array, requestId: string, approvalToken: string)
Execute an arbitrary argv after operator approval. Requires allowArbitrary=true, a requestId registered by `request` whose stored argv equals the supplied argv, and an approval token matching SWAMP_SUDO_APPROVAL_TOKEN. The registered request is consumed on success (single use).
ArgumentTypeDescription
commandarrayThe argv to run. Must equal the argv registered by the matching request.
requestIdstringRequest id returned by `request`; binds this execution to a registered argv.
approvalTokenstringOperator-supplied single-use secret. Must equal the run-scoped secret minted into the approval vault under this request id.

Resources

probe(infinite)— Last probe result: ladder, winner, and residual-risk findings
result(infinite)— Last privileged execution result
request(1d)— A registered arbitrary-command request awaiting approval
03Workflows2
@svendowideit/sudo-run8a692931-ff1e-475a-bb1b-383f4cdca2f5

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

elevateResolve the elevation ladder and run the operation.
1.run— Run the named operation through the resolved route.
@svendowideit/sudo-command35f5f9fc-b3b1-4d20-ab45-5f26cda39c8d

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

approve-and-runRegister the request, wait at the gate, then run if approved.
1.request— Record the exact argv and reason under this run's request id, so the approved command cannot be swapped later.
2.gate— Wait for a human to approve the exact command.
3.run— Execute the command only if it exactly matches the recorded request and the operator-minted, run-scoped secret is correct (then consume both).
04Previous Versions5
2026.10.11.1
2026.10.10.2
2026.10.10.1
2026.10.04.2
2026.10.03.1
05Stats
A
100 / 100
Downloads
41
Archive size
73.1 KB
  • 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

07Platforms