|
| 1 | +# rampart-openclaw-plugin |
| 2 | + |
| 3 | +**Rampart AI agent firewall — native OpenClaw plugin (v1.0)** |
| 4 | + |
| 5 | +This OpenClaw plugin integrates [Rampart](https://github.com/peg/rampart) using the native `before_tool_call` hook API (OpenClaw ≥ 2026.3.28). It is the primary integration path, replacing the legacy dist-file patching approach. |
| 6 | + |
| 7 | +--- |
| 8 | + |
| 9 | +## Quick start |
| 10 | + |
| 11 | +```bash |
| 12 | +# 1. Install Rampart |
| 13 | +go install github.com/peg/rampart@latest |
| 14 | + |
| 15 | +# 2. Start Rampart policy server (defaults to :9090) |
| 16 | +rampart serve |
| 17 | + |
| 18 | +# 3. Install this plugin |
| 19 | +openclaw plugins install /path/to/rampart-openclaw-plugin |
| 20 | +``` |
| 21 | + |
| 22 | +That's it. Every tool call is now checked against your Rampart policies. |
| 23 | + |
| 24 | +--- |
| 25 | + |
| 26 | +## What happens on each decision |
| 27 | + |
| 28 | +Every time the OpenClaw agent calls a tool (`exec`, `read`, `write`, `web_fetch`, `message`, etc.), this plugin intercepts the call **before it executes** and checks it against the running Rampart policy engine (`rampart serve`). |
| 29 | + |
| 30 | +| Decision | What happens | |
| 31 | +|----------|-------------| |
| 32 | +| `allow` | Tool call proceeds normally | |
| 33 | +| `deny` | Tool call is blocked; agent sees a `blockReason` message | |
| 34 | +| `ask` | OpenClaw pauses and prompts you for approval (120 s timeout → auto-deny) | |
| 35 | + |
| 36 | +### The always-allow flow |
| 37 | + |
| 38 | +When Rampart returns `ask` and you click **Allow Always** in the OpenClaw approval UI: |
| 39 | + |
| 40 | +1. The plugin calls `POST /v1/approvals/{id}/resolve` with `persist: true` |
| 41 | +2. Rampart writes a rule to `~/.rampart/policies/auto-allowed.yaml` |
| 42 | +3. Future calls matching the same tool + pattern are automatically allowed — you are never asked again |
| 43 | + |
| 44 | +### Fail-open behavior |
| 45 | + |
| 46 | +If `rampart serve` is not running or unreachable, the plugin **fails open** (allows the call) and logs at debug level. This matches Rampart's existing default behavior and keeps OpenClaw functional when Rampart is down. |
| 47 | + |
| 48 | +If `rampart serve` is reachable but returns a 5xx error, the plugin also fails open but logs a warning. |
| 49 | + |
| 50 | +--- |
| 51 | + |
| 52 | +## Configuration |
| 53 | + |
| 54 | +Plugin config lives in your OpenClaw config file under `plugins.rampart`: |
| 55 | + |
| 56 | +```yaml |
| 57 | +plugins: |
| 58 | + rampart: |
| 59 | + serveUrl: "http://localhost:9090" # default |
| 60 | + enabled: true # default |
| 61 | + timeoutMs: 3000 # ms to wait for Rampart before failing open |
| 62 | + approvalTimeoutMs: 120000 # ms before unanswered approval auto-denies |
| 63 | +``` |
| 64 | +
|
| 65 | +| Option | Type | Default | Description | |
| 66 | +|--------|------|---------|-------------| |
| 67 | +| `serveUrl` | string | `http://localhost:9090` | Rampart serve endpoint | |
| 68 | +| `enabled` | boolean | `true` | Disable the plugin without uninstalling | |
| 69 | +| `timeoutMs` | number | `3000` | Max ms to wait for Rampart before failing open | |
| 70 | +| `approvalTimeoutMs` | number | `120000` | Ms before an unanswered approval auto-denies | |
| 71 | + |
| 72 | +--- |
| 73 | + |
| 74 | +## Authentication |
| 75 | + |
| 76 | +The plugin reads your Rampart token from (in order): |
| 77 | + |
| 78 | +1. `RAMPART_TOKEN` environment variable |
| 79 | +2. `~/.rampart/token` file |
| 80 | + |
| 81 | +This matches the standard Rampart CLI token resolution. |
| 82 | + |
| 83 | +--- |
| 84 | + |
| 85 | +## Security note |
| 86 | + |
| 87 | +The plugin only makes network calls to **localhost** (or whatever `serveUrl` is configured to). It reads a single token file from `~/.rampart/token`. It does not phone home, send telemetry, or make any external network requests. |
| 88 | + |
| 89 | +--- |
| 90 | + |
| 91 | +## Rampart API contract |
| 92 | + |
| 93 | +The plugin calls: |
| 94 | + |
| 95 | +``` |
| 96 | +POST http://localhost:9090/v1/tool/{toolName} |
| 97 | +Content-Type: application/json |
| 98 | +Authorization: Bearer <token> |
| 99 | +
|
| 100 | +{ |
| 101 | + "agent": "main", |
| 102 | + "session": "...", |
| 103 | + "run_id": "...", |
| 104 | + "params": { "command": "ls -la" } |
| 105 | +} |
| 106 | +``` |
| 107 | + |
| 108 | +Expected response shapes: |
| 109 | + |
| 110 | +```json |
| 111 | +{ "allowed": true, "decision": "allow", "message": "..." } |
| 112 | +{ "allowed": false, "decision": "deny", "message": "blocked by policy X", "policy": "no-rm-rf" } |
| 113 | +{ "allowed": false, "decision": "ask", "message": "shell command requires approval", "severity": "warning", "approval_id": "abc123" } |
| 114 | +``` |
| 115 | + |
| 116 | +When `decision` is `ask`, the plugin uses `approval_id` to call back into Rampart's approval API when the user resolves the prompt: |
| 117 | + |
| 118 | +``` |
| 119 | +POST http://localhost:9090/v1/approvals/{approval_id}/resolve |
| 120 | +{ "approved": true, "resolved_by": "openclaw", "persist": true } |
| 121 | +``` |
| 122 | + |
| 123 | +The plugin also posts to `POST /v1/audit` after each tool call (best-effort, fire-and-forget). |
| 124 | + |
| 125 | +--- |
| 126 | + |
| 127 | +## Replacing the dist-patching approach |
| 128 | + |
| 129 | +Previously, Rampart intercepted OpenClaw tool calls by patching JavaScript files inside OpenClaw's bundled `dist/` directory: |
| 130 | + |
| 131 | +```bash |
| 132 | +sudo rampart setup openclaw --patch-tools --force |
| 133 | +``` |
| 134 | + |
| 135 | +This was fragile — every `openclaw upgrade` would overwrite the patches. |
| 136 | + |
| 137 | +With this plugin installed, you can remove the dist patches: |
| 138 | + |
| 139 | +```bash |
| 140 | +# Re-install OpenClaw without the patches (or let an upgrade overwrite them) |
| 141 | +# The plugin handles interception through the stable hook API instead. |
| 142 | +``` |
| 143 | + |
| 144 | +--- |
| 145 | + |
| 146 | +## Development |
| 147 | + |
| 148 | +```bash |
| 149 | +# Verify no syntax errors (ESM import test) |
| 150 | +node -e "import('./index.js').then(() => console.log('ok')).catch(e => console.error(e))" |
| 151 | +
|
| 152 | +# Verify manifest JSON |
| 153 | +cat openclaw.plugin.json | node -e "process.stdin.resume(); let d=''; process.stdin.on('data',c=>d+=c); process.stdin.on('end',()=>{JSON.parse(d); console.log('valid json')})" |
| 154 | +``` |
0 commit comments