Skip to content

Getting started

This guide puts the gate on one Linux server, called main as at RetroSpeedLab, for an agent that logs in as maintainer-ops. Every command runs as root on that server unless it says otherwise.

1. Install

ops-gate needs Python 3.12 and runs its verbs through sudo. Install it into a root-owned virtual environment, so the agent's user cannot change the code it is forced to run:

python3 -m venv /opt/ops-gate
/opt/ops-gate/bin/pip install ops-gate
ln --symbolic --force /opt/ops-gate/bin/ops-gate /usr/local/bin/ops-gate
useradd --system --create-home --shell /bin/sh maintainer-ops

2. Create the approver key

On the approver's machine, not on the server:

ops-gate keygen approver.key

It writes the private key as hex to approver.key with mode 0600, refuses to overwrite an existing file, and prints the public key as hex. Keep the private key with whoever signs approvals, for example your backend; the server only gets the public half.

3. Write a verb table

A minimal table with one verb of each class. Every key is required; the Reference explains each one.

verbs.toml
user = "maintainer-ops"
purpose = "retro-speedlab-ops"
programs = ["/usr/bin/dokku", "/usr/bin/journalctl"]
hosts = ["main"]
approval_seconds = 900
output_characters = 12000
step_seconds = 600

[apps]
list = ["/usr/bin/dokku", "apps:list"]
header = "=====>"
pattern = "[a-z0-9-]+"
never = ["retro-speedlab-maintainer"]
guarded = []

[limits.reads]
calls = 60
seconds = 3600

[limits.repairs]
calls = 3
seconds = 3600

[limits.approvals]
calls = 6
seconds = 3600

[arguments.app]
kind = "app"

[arguments.restartable]
kind = "restartable-app"

[arguments.lines]
kind = "integer"
minimum = 1
maximum = 500

[arguments.size]
kind = "choice"
values = ["200M", "500M", "1G"]

[verbs.app-logs]
class = "read"
limit = "reads"
about = "The last lines of one Dokku app's logs, at most 500."
arguments = ["app", "lines"]
steps = [["/usr/bin/dokku", "logs", "{app}", "--num", "{lines}"]]

[verbs.restart]
class = "repair"
limit = "repairs"
about = "Restart one Dokku app, never the maintainer itself."
arguments = ["restartable"]
steps = [["/usr/bin/dokku", "ps:restart", "{restartable}"]]

[verbs.vacuum-journal]
class = "approval"
limit = "approvals"
about = "Shrink the system journal to the given size: 200M, 500M or 1G."
arguments = ["size"]
steps = [["/usr/bin/journalctl", "--vacuum-size={size}"]]

RetroSpeedLab's full table with fifteen verbs is examples/retrospeedlab/verbs.toml.

4. Install the table, the sudoers rules and the state

ops-gate sudoers verbs.toml > sudoers
visudo --check --file=sudoers
install --mode=0440 --owner=root --group=root sudoers /etc/sudoers.d/maintainer-ops

install --directory --mode=0750 --owner=root --group=maintainer-ops /etc/ops-gate
install --mode=0640 --owner=root --group=maintainer-ops verbs.toml /etc/ops-gate/verbs.toml
printf 'main\n' > /etc/ops-gate/host
printf '%s\n' '<the public key keygen printed>' > /etc/ops-gate/approver.pub

install --directory --mode=0700 --owner=maintainer-ops --group=maintainer-ops /var/lib/ops-gate
printf '{"calls": {}, "used": {}}' > /var/lib/ops-gate/state.json
chown maintainer-ops:maintainer-ops /var/lib/ops-gate/state.json
chmod 0600 /var/lib/ops-gate/state.json

The sudoers drop-in is named after the table's user, which is where the updater later replaces it. The state file must exist before the first call: the gate keeps its rate limit counters and spent approvals there and never creates it.

5. Force the gate on the agent's SSH key

In ~maintainer-ops/.ssh/authorized_keys, with the file and its directory owned by root so the agent cannot change them:

restrict,command="/usr/local/bin/ops-gate serve" ssh-ed25519 AAAA… maintainer

Whatever the agent asks for, sshd runs ops-gate serve, which reads the request from SSH_ORIGINAL_COMMAND.

6. First run

From the agent's machine:

ssh maintainer-ops@main "app-logs retro-speedlab-backend 120"
$ /usr/bin/dokku logs retro-speedlab-backend --num 120
2026-12-03T10:15:02Z app[web.1]: …

Each step's command is printed before its output, and the call exits with the highest exit status of its steps. A verb that needs approval is refused without one:

ssh maintainer-ops@main "vacuum-journal 500M"   # refused: vacuum-journal needs approval

A refusal exits with status 2 and is logged to syslog under ops-gate, so journalctl -t ops-gate shows every call, run or refused.

To approve the risky one, the approver signs exactly those words for that host:

ops-gate approve --key approver.key --table verbs.toml --host main vacuum-journal 500M

It prints the command with its approval appended, vacuum-journal 500M approval=…, valid for the table's approval_seconds. The agent sends that line once; a second send is refused with "the approval was used already". A backend signs the same approval in code:

import time

from cryptography.hazmat.primitives.asymmetric.ed25519 import Ed25519PrivateKey
from ops_gate.approval import sign_run

key = Ed25519PrivateKey.from_private_bytes(bytes.fromhex(signing_key_hex))
token = sign_run(key, "retro-speedlab-ops", "main", ("vacuum-journal", "500M"), int(time.time()) + 840)

7. Optional: signed table updates

To let a merged, approver-signed table replace the running one, set up the updater:

printf '%s\n' 'https://api.retrospeedlab.com/maintainer/ops-approvals/{host}' > /etc/ops-gate/approvals-url
install --directory --mode=0700 --owner=root --group=root /var/lib/ops-updater
printf '{}' > /var/lib/ops-updater/used.json

and run ops-gate update as root from a systemd timer:

/etc/systemd/system/ops-updater.service
[Unit]
Description=Install the approver-signed verb table of the ops gate
Wants=network-online.target
After=network-online.target

[Service]
Type=oneshot
ExecStart=/usr/local/bin/ops-gate update
PrivateTmp=yes
ProtectHome=yes
/etc/systemd/system/ops-updater.timer
[Unit]
Description=Look for approver-signed verb tables every two minutes

[Timer]
OnBootSec=2min
OnUnitActiveSec=2min

[Install]
WantedBy=timers.target
systemctl daemon-reload
systemctl enable --now ops-updater.timer

The timer must run more often than approval_seconds, or a signed table expires before the server fetches it.