Skip to content

Writing Plugins

External modules are standalone executables that communicate with glidesh via newline-delimited JSON on stdin/stdout. They can be written in any language — scripted or compiled. Plugins never receive SSH credentials — they request operations through glidesh, which proxies them over the existing SSH session. They do not receive the secrets vault either: a plugin sees only the secrets the plan passes it as arguments.

The protocol has three phases:

  1. Describe — glidesh probes the plugin during discovery to learn its name and version. This happens once at startup in a short-lived process. The describe handshake is only used during discovery — runtime check/apply processes do not receive a describe request.
  2. Check/Apply — glidesh spawns a new plugin process and sends a task; the plugin may issue SSH requests and returns a result
  3. Shutdown — glidesh tells the plugin to exit

All messages are single-line JSON, terminated by a newline.

glidesh sends:

{"method":"describe"}

Plugin responds:

{"name":"acme/nginx-vhost","version":"1.0.0","protocol_version":1}
Field Type Description
name string Canonical module name. May contain / for owner/name format
version string Module version (informational)
protocol_version integer Must be 1

The name in the describe response is authoritative — it becomes the name used in plans with external "acme/nginx-vhost".

After the handshake, glidesh sends check or apply requests:

{
"method": "check",
"resource_name": "mysite",
"args": {
"server_name": {"string": "example.com"},
"listen": {"integer": 443}
},
"os_info": {
"id": "ubuntu",
"version": "22.04",
"family": "debian",
"pkg_manager": "apt",
"init_system": "systemd",
"container_runtime": "docker" // may be null if no runtime detected
},
"vars": {"@host.name": "web-1", "@host.address": "10.0.0.1", "@os.family": "debian"},
"dry_run": false
}

The os_info values are the same ones a plan sees as ${@os.*}: family is one of debian, redhat, arch, alpine, suse, nixos (an unrecognised OS arrives as {"unknown": "<ID>"}), pkg_manager one of apt, dnf, yum, pacman, apk, zypper, nix, and init_system one of systemd, openrc, unknown. A nix_installed: true field is added on hosts where Nix is present. Host facts are not part of os_info; read them from vars (@fact.cpu.count, @fact.mem.total-mb, …).

Return one of three statuses:

{"status":"satisfied"}
{"status":"pending","plan":"will create /etc/nginx/sites-enabled/mysite"}
{"status":"unknown","reason":"cannot determine nginx state"}

A pending response may carry an optional diff describing the change in detail. Return it only when the request carried "diff": true, since that is the user asking for it and paying for whatever extra probes it costs; glidesh discards a diff it did not ask for. The field can be omitted entirely — plugins written before it existed keep working unchanged.

The request omits diff when the flag is absent, exactly as it omits nix_installed on a host without Nix, so the bytes a v1 plugin receives on an ordinary run are unchanged. Read a missing diff as false.

{"status":"pending","plan":"will update /etc/motd","diff":"-old line\n+new line"}

When the task’s step subscribes to a step that changed something, the check and apply requests carry "triggered": true. It means “redo your work”: a plugin that manages something that can be reloaded, restarted or rerun should answer check with pending when it is set, even though its state is in place, and do the work in apply. A plugin with nothing to redo answers as usual; a satisfied answer is reported ok and apply is not called.

Like diff, the field is omitted when false, so a plugin that predates it receives unchanged requests. Read a missing triggered as false.

{
"changed": true,
"output": "created vhost mysite",
"stderr": "",
"exit_code": 0
}

output is what a task’s register= captures. Add "output_cut": true when it is incomplete — typically an exec stdout that came back with "stdout_cut": true — and register= fails the task instead of capturing it. Omitted, it is false.

If something goes wrong, return an error at any point:

{"error":"nginx config syntax check failed"}

Plugins don’t have direct SSH access. Instead, they send SSH operation requests and glidesh responds with results. This proxy loop can repeat as many times as needed during a single check or apply call.

Request:

{"ssh":"exec","command":"nginx -t"}

Response:

{"ssh_result":"exec","exit_code":0,"stdout":"syntax ok\n","stderr":""}

stdout and stderr are each capped at 8 MiB, keeping the first and last 4 MiB (see Output limit). When stdout was cut, the response carries "stdout_cut": true; it is omitted otherwise. To read something larger, use download.

A plugin that passes such a stdout on as its apply output should set "output_cut": true, so that register= refuses it rather than hand later steps a value with its middle missing. glidesh cannot tell on its own: a plugin’s output is whatever the plugin writes.

Request:

{"ssh":"upload","path":"/etc/nginx/sites-enabled/mysite","content_base64":"c2VydmVyIHsgLi4uIH0="}

Response:

{"ssh_result":"upload","ok":true}

On failure, an error field is included:

{"ssh_result":"upload","ok":false,"error":"Permission denied"}

Request:

{"ssh":"download","path":"/etc/nginx/sites-enabled/mysite"}

Response:

{"ssh_result":"download","content_base64":"c2VydmVyIHsgLi4uIH0=","exists":true}

When the file doesn’t exist or an error occurs, exists is false and an optional error field explains why:

{"ssh_result":"download","content_base64":"","exists":false,"error":"No such file"}

Request:

{"ssh":"checksum","path":"/etc/nginx/sites-enabled/mysite"}

Response:

{"ssh_result":"checksum","hash":"a1b2c3...","exists":true}

When the file doesn’t exist: {"ssh_result":"checksum","hash":"","exists":false}. On other failures, an error field is included.

set_attrs — Set file ownership and permissions

Section titled “set_attrs — Set file ownership and permissions”

Request:

{"ssh":"set_attrs","path":"/etc/nginx/sites-enabled/mysite","owner":"root","group":"root","mode":"0644"}

Response:

{"ssh_result":"set_attrs","ok":true}

On failure: {"ssh_result":"set_attrs","ok":false,"error":"Permission denied"}.

All fields in set_attrs except path are optional — only provided fields are changed.

glidesh sends a shutdown request when it no longer needs the plugin:

{"method":"shutdown"}

The plugin should exit cleanly.

All four implementations below do the same thing — set /etc/motd on the target host. The plugin:

  1. describe — reports itself as example/motd with protocol version 1
  2. check — downloads /etc/motd via SSH proxy and compares to the desired content
  3. apply — uploads the new content via SSH proxy
  4. shutdown — exits cleanly

Save the file as glidesh-module-example-motd (compiled languages produce a binary with this name), place it in one of the discovery paths, and use it in a plan:

step "Set MOTD" {
external "example/motd" "Managed by glidesh."
}
#!/usr/bin/env bash
set -euo pipefail
MOTD_PATH="/etc/motd"
while IFS= read -r line; do
method=$(echo "$line" | jq -r '.method // empty')
case "$method" in
describe)
echo '{"name":"example/motd","version":"1.0.0","protocol_version":1}'
;;
check)
resource=$(echo "$line" | jq -r '.resource_name')
desired="$resource"$'\n'
echo "{\"ssh\":\"download\",\"path\":\"$MOTD_PATH\"}"
IFS= read -r result
exists=$(echo "$result" | jq -r '.exists')
if [ "$exists" = "false" ]; then
echo "{\"status\":\"pending\",\"plan\":\"will create $MOTD_PATH\"}"
else
current=$(echo "$result" | jq -r '.content_base64' | base64 -d)
if [ "$current" = "$desired" ]; then
echo '{"status":"satisfied"}'
else
echo "{\"status\":\"pending\",\"plan\":\"will update $MOTD_PATH\"}"
fi
fi
;;
apply)
resource=$(echo "$line" | jq -r '.resource_name')
content=$(printf '%s\n' "$resource" | base64 -w0)
echo "{\"ssh\":\"upload\",\"path\":\"$MOTD_PATH\",\"content_base64\":\"$content\"}"
IFS= read -r _result
echo "{\"changed\":true,\"output\":\"set $MOTD_PATH\",\"stderr\":\"\",\"exit_code\":0}"
;;
shutdown)
exit 0
;;
esac
done

Requires jq and base64 on the machine running glidesh.

Convention Details
Executable prefix glidesh-module- (required for discovery)
Name format owner/name recommended for distribution
Protocol version Must be 1
Describe response Must return non-empty name
Distribution Place in ./modules/ (relative to inventory) or ~/.glidesh/modules/

glidesh runs every plugin process inside a sandbox:

Measure Platform Effect
Env scrub All Only PATH, HOME/USERPROFILE, LANG, temp dir vars are passed. Secrets are stripped.
Vault isolation All Secret-carrying values are stripped from the request’s vars; a plugin sees only what the plan passes it explicitly.
stderr redaction All Plugin stderr is scrubbed of decrypted secrets before it reaches the debug log.
Temp workdir All Plugin CWD is the system temp directory, not the project directory.
Session isolation Unix setsid() — plugin cannot signal glidesh’s process group.
Filesystem restriction Linux 5.13+ landlock limits access to /tmp, /usr, /lib, /lib64, plus read and execute on the plugin’s own file. Home dirs, project files — including the files next to the plugin — and SSH keys are blocked. A plugin must therefore be self-contained: it cannot load helper files from its own directory.

Runtime (check/apply) processes also receive GLIDESH_PROTOCOL_VERSION and GLIDESH_MODULE_NAME environment variables.

  • Use dry_run in the check/apply request to avoid side effects during --dry-run runs
  • register captures nothing from a task during a dry run, so do not expect a plugin’s preview output to be readable by a later step
  • The os_info field tells you the target OS, package manager, and init system — use it to adapt behavior
  • Template variables from the plan are available in vars — the plugin receives them already interpolated, minus any value carrying a secret (pass those explicitly as arguments)
  • Keep plugins stateless between check and apply — glidesh may call them in any order
  • Return descriptive plan messages in Pending responses — they lead the dry-run output for the task, and a run normally counts a task as “would change” when check returns pending. The exception is a step using subscribe: its target having changed force-applies the step, so it counts as “would change” even on a satisfied response
  • apply is still called during a --dry-run run, with dry_run: true in the request. Honor it: report what you would do and change nothing