Skip to main content
Glama
README.md
# podman-proxy MCP server

Name-based routing to rootless podman services for this lab machine:
`https://<name>.home.arpa` resolves via **`/etc/hosts`** to `127.0.0.1`, where the
**Caddy** container (quadlet `caddy.container`, ports 80/443) routes by `Host`
header to the podman service. An MCP server lets this harness create, update and
remove both halves of every route.

```
browser / curl ── searxng.home.arpa ──> /etc/hosts ──> 127.0.0.1:443
                                                         │ caddy (rootless podman, web_net + shared nets)
                                                         ├─ https://app1.home.arpa  -> app1-container:8080
                                                         ├─ https://searxng.home.arpa -> searxng:8080
                                                         └─ (hand-written blocks stay in the main Caddyfile)
```

Standalone repo since 2026-11-30 — previously `mcp/podman-proxy/` inside
[agentic-workflow-tool](https://github.com/wgayton/agentic-workflow-tool)
(issue #45). Same code, same behaviour; the host-side MCP registration is
unchanged.

## Layout

```
podman-proxy/
├── src/index.ts            zero-dependency MCP stdio server (bun)
├── src/lib/config.ts       paths/env (SCI_PROXY_* overrides)
├── src/lib/caddy.ts        sites/*.caddy management + validate/reload via podman exec
├── src/lib/hosts.ts        sudo helper invocation
├── src/lib/podman.ts       podman ps/inspect + network connect
├── src/lib/validate.ts     hostname/IP/target validation
├── src/lib/journal.ts      append-only audit log (~/.local/state/sci-proxy/journal.jsonl)
├── scripts/hosts-helper.py root-owned /etc/hosts helper (installed by --sudo)
├── scripts/install.sh      phase 1 user setup | --sudo privileged phase | --uninstall
├── tests/                  bun tests — hermetic, no podman/root/network needed
└── .github/workflows/      CI: typecheck + tests + helper selftest
```

Config roots (all overridable via `SCI_PROXY_*` env vars):

| What | Default |
|---|---|
| Caddy config tree | `~/containers/caddy` (quadlet mounts it at `/etc/caddy`) |
| MCP-managed site files | `~/containers/caddy/sites/*.caddy` (imported by the main Caddyfile) |
| Hostname suffix | `.home.arpa` (RFC 8375) |
| Hosts helper | `/usr/local/lib/sci-proxy/hosts-helper` (root:root 0755) |
| Journal | `~/.local/state/sci-proxy/journal.jsonl` |

## Install

```bash
git clone <this-repo> ~/Projects/agentics/podman-proxy
cd ~/Projects/agentics/podman-proxy

# phase 1 — no root: config layout, caddy image, quadlet service up, smoke test
bash scripts/install.sh

# phase 2 — one-time, prompts for your password
bash scripts/install.sh --sudo

# then confirm the global MCP registration (opencode hot-reloads it)
opencode mcp list          # → podman-proxy: connected
```

`--sudo` installs the helper + suffix allowlist at `/usr/local/lib/sci-proxy/`,
adds `/etc/sudoers.d/sci-proxy-hosts` granting `NOPASSWD` **only** for that exact
script (validated with `visudo -c`), and runs the helper selftest.

### MCP registration

The server is registered globally — in `~/.config/opencode/opencode.json`, not in
any project — so every session on this machine gets the tools:

```jsonc
"podman-proxy": {
  "type": "local",
  "command": ["bun", "run", "/home/wgayton/Projects/agentics/podman-proxy/src/index.ts"],
  "cwd": "/home/wgayton/Projects/agentics/podman-proxy",
  "protocol": "legacy"                       // classic stdio initialize handshake
}
```

An optional per-project override can be added to any project's own
`opencode.json`; the global entry is enough for the lab machine.

## Tools

| Tool | Purpose |
|---|---|
| `proxy_status` | caddy state, managed sites, hosts entries, helper availability |
| `proxy_list` | managed site entries |
| `proxy_add` | site file + hosts entry + reload. `target`: `searxng`, `searxng:8080` or `127.0.0.1:8888` |
| `proxy_update` | change upstream/TLS of an existing site |
| `proxy_remove` | remove site (+ hosts entry unless `remove_hosts=false`) |
| `proxy_reload` | validate + reload after manual edits |
| `hosts_list` / `hosts_add` / `hosts_remove` | direct management of the hosts block |
| `containers_list` | podman containers with networks + published ports (pick targets) |

All mutators take `dry_run: true`. Every mutation is journaled.

Upstream resolution: container targets require caddy to share a podman network
with the target — the server runs `podman network connect` automatically when
needed. Pod targets resolve under the **pod's** DNS name (containers in a pod
share the netns; membership lives on the infra container), so both
`<container>:<port>` and `<pod>:<port>` work — pods need the explicit port.
Loopback `host:port` targets are rewritten to `host.containers.internal` (or the
network gateway) as seen from the caddy container — note this only reaches
services published on `0.0.0.0`, not loopback-only (`127.0.0.1`) publishes;
attach those to a shared network instead.

Trailing-dot FQDNs are accepted (`demo.home.arpa.` == `demo.home.arpa`).

## Development

```bash
bun install           # dev deps only: typescript + bun types
bun run verify        # typecheck + tests + hosts-helper selftest + install.sh syntax
```

Tests are hermetic: `tests/fixtures/env.ts` redirects every path into a temp
directory, so nothing touches `~/containers/caddy`, `/etc/hosts` or the real
journal, and no podman/root/network access is required. CI runs the same suite
(`.github/workflows/test.yml`). See [AGENTS.md](AGENTS.md) for the rules that
keep this server trustworthy.

## Security model

- The MCP server and caddy run **unprivileged** (your user). Caddy binds 80/443
  because `net.ipv4.ip_unprivileged_port_start` is 53 on this host.
- `/etc/hosts` is edited only by the root-owned helper. It validates strictly
  (suffix allowlist, RFC-1123 labels, `ipaddress` IP parsing), refuses names that
  already exist anywhere in the file, edits **only** inside the
  `# BEGIN/END sci-proxy-mcp` marker block, takes an exclusive `flock`, writes
  atomically (temp + `os.replace`, ownership/mode preserved) and keeps a backup
  at `/etc/hosts.sci-proxy-mcp.bak`. It honors no environment variables.
- Trust implication (accepted by design): any process running as your user can
  add/remove entries under `home.arpa` via the helper without a password. It
  cannot touch unrelated hosts entries or other root files.
- The MCP can only manage names under the configured suffix; hand-written
  Caddyfile blocks outside `sites/` are never modified.

## Troubleshooting

- `hosts helper requires one-time setup` → run `bash scripts/install.sh --sudo`.
- `caddy container "caddy" is not running` → `systemctl --user start caddy`; logs:
  `journalctl --user -u caddy.service`.
- `caddy validate failed` → the site file is bad; the server rolls back and the
  error includes caddy's message. Fix and retry, or `proxy_remove`.
- TLS warnings in the browser / `curl` without `-k` → caddy uses its internal CA
  for `*.home.arpa`. Export and trust the root once:
  ```bash
  podman cp caddy:/data/caddy/pki/authorities/local/root.crt ~/containers/caddy/rootCA.crt
  sudo cp ~/containers/caddy/rootCA.crt /etc/pki/ca-trust/source/anchors/sci-proxy-root.crt
  sudo update-ca-trust        # system store: curl, OpenSSL, browsers
  ```
  For node/bun-based clients, appending works without system changes:
  `export NODE_EXTRA_CA_CERTS="$HOME/containers/caddy/rootCA.crt"`.
- Everything the MCP did: `~/.local/state/sci-proxy/journal.jsonl`.

## Uninstall

```bash
bash scripts/install.sh --uninstall   # helper + sudoers
```

The caddy service is shared infrastructure and is left running; remove MCP-managed
routes with `proxy_remove` before tearing it down if desired.

## License

MIT (© 2026 William Gayton) — see [LICENSE](LICENSE).