Privilege Escalation (run-as)
By default every command runs as the user you connect with over SSH. run-as lets a
task escalate to another user — usually root — using sudo, doas, or su, so you
can log in as an unprivileged account and elevate only where needed.
It applies to everything a module does on the host: shell commands, package
installs, user/systemd/disk operations, and file uploads to root-owned paths — for both
the idempotency check and the apply.
The model
Section titled “The model”run-as takes the target user as its value:
| Form | Meaning |
|---|---|
run-as="root" |
Escalate to root |
run-as="postgres" |
Escalate to postgres |
run-as="" |
Explicitly do not escalate (cancels an inherited setting) |
| (omitted) | Inherit from the less-specific level |
The method defaults to sudo; override with run-as-method="doas" or
run-as-method="su".
Where you can set it
Section titled “Where you can set it”run-as is configurable at seven levels. The most specific wins, and the
work-side levels (task/step/plan) override the machine-side levels (host/group/global):
module/task > step > plan > host > group > global (inventory) > --run-as (CLI)Inventory
Section titled “Inventory”// Global default for every host.run-as "root"
group "web" run-as="root" { host "web-1" "10.0.0.1" user="deploy" host "web-2" "10.0.0.2" user="deploy" run-as-method="doas" // override method}
// Connecting as root already — opt out.host "legacy" "10.0.2.1" user="root" run-as=""The global default uses a top-level run-as "<user>" node; groups and hosts use the
run-as="<user>" attribute. Both accept run-as-method="<m>".
Set a default for the whole plan on the plan node — every step inherits it:
plan "deploy" run-as="root" { // every step escalates by default step "Install" { // inherits the plan's run-as package "nginx" state="present" } step "Audit" { shell "id" // also root (inherited) shell "whoami" run-as="" // opt out -> the login user }}Or scope escalation to individual steps and tasks instead of the whole plan:
plan "deploy" { step "Install" run-as="root" { // whole step escalates package "nginx" state="present" } step "Mixed" { shell "whoami" // runs as the login user disk "/dev/sdb" fs="ext4" run-as="root" // only this task escalates }}Included plans
Section titled “Included plans”When a plan pulls in another with include, the included
plan’s plan-level run-as applies to its own steps. The including plan’s steps are
unaffected, and a step in the included plan can still opt out with run-as="".
plan "db" run-as="root" { // governs the steps below, even when included step "Install Postgres" { package "postgresql" state="present" }}plan "deploy" { step "App config" { // runs as the login user shell "whoami" } include "common/db.kdl" // its "Install Postgres" step escalates to root}The CLI flags are the lowest-precedence default — a baseline that inventory and plan settings still override:
glidesh run -i inventory.kdl -p plan.kdl --run-as root --run-as-method sudoPasswords
Section titled “Passwords”sudo is the robust path and works two ways:
- Passwordless (
NOPASSWDsudoers entry): nothing else required. - With a password: supply it without echoing to the terminal. Glidesh feeds it to
sudo -Son stdin.
glidesh run ... --run-as root --ask-pass # prompt onceGLIDESH_RUNAS_PASS='…' glidesh run ... --run-as root # from the environmentThe password is held in process memory only — never logged or written to disk. It is
global for the run; GLIDESH_RUNAS_PASS takes precedence over --ask-pass.
Glidesh sends it only when sudo asks for it: each command gets a prompt of its own
(-p), and the password goes out when that prompt appears, never before — or when a
prompt PAM shows instead (Kerberos, say) has sat unanswered for two seconds. Without a
prompt — NOPASSWD, or a sudoers change during the run — no password is sent, so it
never reaches the command, whose input a sudoers log_input I/O log records. A second
prompt means the password was wrong, or PAM wants more than it (a one-time code):
nothing more is sent, and the task fails as a denied escalation. sudo -k keeps
cached credentials out of it, both ways: none from an earlier sudo are used, and a run
leaves none behind for the login user.
Method support and caveats
Section titled “Method support and caveats”| Method | Password | Notes |
|---|---|---|
sudo (default) |
passwordless or password via stdin | Recommended. |
doas |
passwordless only | doas reads passwords from a TTY; configure nopass/persist in doas.conf. |
su |
password via PTY | Requires a PTY, which merges stderr into stdout. File uploads, fetches and --diff reads work only for run-as="root" or the login user. Best-effort; prefer sudo. |
A denied escalation (wrong password, not a sudoer, missing TTY) is reported as a distinct error, not confused with a command that failed on its own.
File uploads to root-owned paths
Section titled “File uploads to root-owned paths”SFTP writes as the login user, so it cannot create files in directories like /etc
directly. With run-as set, the elevated shell writes the destination:
run-as="root"reads the content from a private (0600) file the login user staged in/tmp, then removes it.- Any other user — a service account like
postgres, which cannot open another user’s private file — gets the content on its input, sent by glidesh only once the destination has passed its check andsudois done with any password. Content sent this way passes throughsudo’s input, so a sudoerslog_inputI/O log records it — the content, never the password. sucannot take content on its input — its terminal would mangle binary data — so it works for root or the login user only: any otherrun-asuser fails the upload before anything is written, naming the limitation. Usesudoordoasfor it.
Fetches and --diff reads go through a private file the login user stages and then
reads. Root writes it directly, as does su — for root or the login user only, like
uploads; with sudo or doas, any other user’s read is written into it by the login
user, and so passes through sudo’s output, which log_output records.
What is staged never reaches the result: a file that
already existed keeps its owner, group, and mode, and a new one is created by the
escalation target, so the umask in effect (the session’s; sudo adds its own, 022
by default) or the directory’s default ACL decides the mode (0644 usually) — the same
as a plain upload
(Owner and Mode). Any explicit
owner/group/mode you set is applied afterwards.
Destinations other users control
Section titled “Destinations other users control”An escalated write follows symlinks, as any write does. If another user could put a
symlink at the destination — or swap one in while glidesh works — they could aim the
privileged write, or owner/group/mode, at any file on the host. So before creating
directories, writing, or changing attributes with run-as, glidesh applies the rule the
Linux kernel uses for symlinks (protected_symlinks) — whether or not the host enables
it — and fails the task otherwise, naming the entry. Along the path to /, and through
every symlink on the way:
- a directory must not be writable by others, nor by a group other than root’s, nor
carry an ACL that may let others write: on Linux, an ACL on a group-writable directory
(its group bits then show the ACL mask); on macOS and BSD, an entry allowing
add_file,add_subdirectory,delete_child,writesecurityorchown— which the mode bits do not show — or an ACL glidesh cannot read as macOS lists it (ls -le), which on FreeBSD is any ACL. A deny-only ACL, like theeveryone deny deleteof a macOS home, is fine; - a directory writable by a user’s private group is accepted, where the user is root,
the
run-asuser, the login user or the directory’s owner: the group has that user’s name, is their primary group, and lists no other member. Distributions with user-private groups (Debian, Ubuntu, Fedora) give such users a002umask, so every directory they create is group-writable. glidesh does not look for other accounts an administrator gave the same primary group; - a directory writable by others is accepted when it is sticky, like
/tmp, and what sits in it already exists as a directory or link: others cannot rename that. A file or a missing entry right under it is refused, since anyone could create it first — so upload to/tmp/app/xwith/tmp/appin place, not to/tmp/x; - a symlink, including the destination itself, must be owned by root, the
run-asuser, the login user, or the owner of the directory it sits in; what it points to is checked the same way; - a directory that does not exist yet is skipped: its parent decides who can create it. glidesh creates missing directories one at a time and checks each before creating the next inside it, so a new one that comes out writable by others — through the umask, a setgid parent or a default ACL — stops the task before anything goes in it.
For a recursive copy the rule covers the path to the destination and each file uploaded;
owner and group over the tree change a symlink found in it, never what it points
to, and mode skips symlinks. A --diff read is checked the same way: a destination
that fails shows no diff in the preview, and the upload itself is refused for the same
reason.
A directory’s owner is trusted with what is in it, as the kernel trusts it: uploading
as root into /var/www/html owned by www-data works, and www-data could redirect
that write — the same holds for any tool that writes there as root. To deploy into a
directory a team shares (say 2775 root:devs), write it without run-as as a user in
that group, or tighten the directory first.
How it differs from the SSH user
Section titled “How it differs from the SSH user”run-as is independent of the SSH login user (user="…" / ${@host.user}). You
connect as the login user and escalate to the run-as user; both can differ per host.

