Metadata-Version: 2.4
Name: ops-gate
Version: 0.1.1
Summary: Let an AI agent run root commands on your servers: only allowlisted verbs, risky ones only with a signed, single-use human approval
Keywords: ai-agents,llm,sudo,ssh,devops,human-in-the-loop,mcp
Author: datenwissenschaften
Author-email: datenwissenschaften <martin.franke@datenwissenschaften.com>
License-Expression: MIT
License-File: LICENSE
Classifier: Development Status :: 4 - Beta
Classifier: Environment :: Console
Classifier: Intended Audience :: System Administrators
Classifier: Operating System :: POSIX :: Linux
Classifier: Programming Language :: Python :: 3.12
Classifier: Topic :: Security
Classifier: Topic :: System :: Systems Administration
Classifier: Typing :: Typed
Requires-Dist: cryptography>=44
Requires-Python: >=3.12, <4.0
Project-URL: Repository, https://github.com/datenwissenschaften/ops-gate
Project-URL: Used by, https://github.com/datenwissenschaften/retro-speedlab-suite
Description-Content-Type: text/markdown

# ops-gate

![An AI agent waits at a gate that opens only for a signed approval](https://raw.githubusercontent.com/datenwissenschaften/ops-gate/main/assets/banner.webp)

[![CI](https://github.com/datenwissenschaften/ops-gate/actions/workflows/ci.yml/badge.svg)](https://github.com/datenwissenschaften/ops-gate/actions/workflows/ci.yml) [![PyPI](https://img.shields.io/pypi/v/ops-gate.svg)](https://pypi.org/project/ops-gate/) ![Python 3.12](https://img.shields.io/badge/python-3.12-blue.svg) [![License: MIT](https://img.shields.io/badge/License-MIT-yellow.svg)](LICENSE)

**Let an AI agent fix your servers without handing it a root shell.**

An agent that runs production needs root for real work: read logs, free a full disk, restart a stuck app. Giving it `sudo` or a shell means one bad prompt can do anything. `ops-gate` gives the agent a short menu instead:

- **Read** verbs run at once, **repair** verbs run within a rate limit, and **approval** verbs run only with a human's signed, single-use approval for that exact command on that exact server.
- One TOML table defines every verb. The gate checks each call against it, and the sudoers rules are generated from the same table, so the two can never drift apart.
- The agent can propose a new table, but it only takes effect once an approver signs the table that is merged on `main`.
- It's about 500 lines of Python with one dependency (`cryptography`), so it can be audited in an afternoon.

## Used in production by RetroSpeedLab

[RetroSpeedLab](https://www.retrospeedlab.com) is a game studio run by AI agents ([suite](https://github.com/datenwissenschaften/retro-speedlab-suite)). Its maintainer agent keeps two Dokku servers healthy through `ops-gate`, and every example here is its real table ([`examples/retrospeedlab/verbs.toml`](examples/retrospeedlab/verbs.toml)):

```text
agent  → ssh maintainer-ops@main "app-logs retro-speedlab-backend 120"     # read: runs
agent  → ssh maintainer-ops@main "prune-images 96"                         # repair: at most 3 an hour
agent  → ssh maintainer-ops@main "restart retro-speedlab-maintainer"       # refused: it may not restart itself
agent  → ssh maintainer-ops@main "vacuum-journal 500M"                     # refused: needs approval
owner  → clicks Approve in Discord; the backend signs "vacuum-journal 500M" for main, valid 14 minutes
agent  → ssh maintainer-ops@main "vacuum-journal 500M approval=…"          # runs once, then the token is spent
```

## How it works

```text
agent ──ssh──▶ authorized_keys: command="ops-gate serve"
                 │  plain words only; verb, arguments and approval checked against verbs.toml
                 │  per-class rate limit; signed approval verified and spent
                 ▼
               sudo --non-interactive -- <the verb's fixed argv>   (sudoers generated from verbs.toml)
```

A verb is a fixed argv with typed arguments (`integer` with bounds, `choice`, or an app name from your platform's app list):

```toml
[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}"]]
```

An approval is an Ed25519 signature over the purpose, host, exact words, expiry and nonce. The gate refuses it if it is forged, expired, valid for too long, for another host, for different words, or already used.

## Quickstart

```bash
sudo python3 -m venv /opt/ops-gate && sudo /opt/ops-gate/bin/pip install ops-gate
sudo ln -s /opt/ops-gate/bin/ops-gate /usr/local/bin/ops-gate

ops-gate keygen approver.key                        # keep the private key with your approver; prints the public key
ops-gate sudoers verbs.toml | sudo tee /etc/sudoers.d/maintainer-ops && sudo visudo --check
# /etc/ops-gate/{verbs.toml,host,approver.pub}; the agent's key in ~maintainer-ops/.ssh/authorized_keys:
#   restrict,command="/usr/local/bin/ops-gate serve" ssh-ed25519 AAAA…

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

Your backend signs approvals in code with `ops_gate.approval.sign_run(key, purpose, host, words, expiry)`. Signed table updates are pulled by `ops-gate update` (a systemd timer) from `/etc/ops-gate/approvals-url`, checked against the sudoers rules with `visudo`, then installed.

## Development

```bash
uv sync && uv run ruff check && uv run mypy && uv run pytest
```

The acceptance scenarios in [`tests/features/gate.feature`](tests/features/gate.feature) describe the gate's behaviour in plain language.

MIT © datenwissenschaften. Built by [Dr. Franke Datenwissenschaften](https://www.datenwissenschaften.com): AI agents and data platforms that run in production.
