| 1 | --- |
| 2 | title: Admin And Policy API |
| 3 | description: Portal relay operator endpoints for auth and policy control. |
| 4 | --- |
| 5 | |
| 6 | # Admin And Policy API |
| 7 | |
| 8 | Operator endpoints are the control surface for a relay. They all return |
| 9 | the standard JSON envelope described in [API Reference](/api-reference), except |
| 10 | for internal operational endpoints that are not part of the stable API. |
| 11 | |
| 12 | `/admin` is reserved for the frontend route. Relay admin auth endpoints live |
| 13 | under `/api/admin`, and enforcement settings live under `/api/policy`. |
| 14 | |
| 15 | ## Auth Flow |
| 16 | |
| 17 | 1. Set `ADMIN_TOKEN` on the relay. |
| 18 | 2. `POST /api/admin/auth/login` with `{ "token": "<admin-token>" }`. |
| 19 | 3. Send the returned `access_token` as `Authorization: Bearer <token>`. |
| 20 | 4. `POST /api/admin/auth/logout` to clear the browser-stored token. |
| 21 | |
| 22 | Admin bearer tokens are separate from SDK lease tokens. |
| 23 | |
| 24 | ## Endpoints |
| 25 | |
| 26 | | Method | Path | Auth | Body | Data | |
| 27 | |--------|------|------|------|------| |
| 28 | | `POST` | `/api/admin/auth/login` | None | `AdminAuthLoginRequest` | `AdminAuthLoginResponse` | |
| 29 | | `GET` | `/api/admin/auth/status` | Optional bearer | none | `AdminAuthStatusResponse` | |
| 30 | | `POST` | `/api/admin/auth/logout` | Bearer | none | `{}` | |
| 31 | | `GET` | `/api/policy` | Bearer | none | `PolicySettings` | |
| 32 | | `POST` | `/api/policy` | Bearer | `PolicySettings` | `PolicySettings` | |
| 33 | | `GET` | `/api/policy/state` | Bearer | none | `PolicyStateResponse` | |
| 34 | | `POST` | `/api/policy/leases` | Bearer | `LeasePolicyUpdate` | `{}` | |
| 35 | | `POST` | `/api/policy/ips` | Bearer | `IPPolicyUpdate` | `{}` | |
| 36 | |
| 37 | ## Auth Payloads |
| 38 | |
| 39 | `AdminAuthLoginRequest`: |
| 40 | |
| 41 | | Field | Type | Required | |
| 42 | |-------|------|----------| |
| 43 | | `token` | `string` | yes | |
| 44 | |
| 45 | `AdminAuthLoginResponse`: |
| 46 | |
| 47 | | Field | Type | |
| 48 | |-------|------| |
| 49 | | `access_token` | `string` | |
| 50 | |
| 51 | `AdminAuthStatusResponse`: |
| 52 | |
| 53 | | Field | Type | Notes | |
| 54 | |-------|------|-------| |
| 55 | | `authenticated` | `boolean` | true only when a valid bearer token was sent | |
| 56 | |
| 57 | ## State |
| 58 | |
| 59 | `GET /api/policy/state` returns the full policy view: |
| 60 | |
| 61 | | Field | Type | |
| 62 | |-------|------| |
| 63 | | `policy` | `PolicySettings` | |
| 64 | | `leases` | `PolicyLease[]` | |
| 65 | |
| 66 | `PolicyLease` uses the shared `Lease` fields from [API Reference](/api-reference#shared-types) |
| 67 | and adds: |
| 68 | |
| 69 | | Field | Type | Notes | |
| 70 | |-------|------|-------| |
| 71 | | `identity_key` | `string` | normalized `name:address` key | |
| 72 | | `address` | `string` | normalized Ethereum address | |
| 73 | | `bps` | `number` | bytes per second limit, `0` means unlimited | |
| 74 | | `client_ip` | `string` | relay-observed client IP | |
| 75 | | `reported_ip` | `string` | client-reported public IP, when present | |
| 76 | | `is_approved` | `boolean` | effective approval result | |
| 77 | | `is_banned` | `boolean` | identity is banned | |
| 78 | | `is_denied` | `boolean` | identity is denied | |
| 79 | | `is_ip_banned` | `boolean` | observed client IP is banned | |
| 80 | |
| 81 | ## Policy |
| 82 | |
| 83 | Policy settings are written as one object through `POST /api/policy` and returned |
| 84 | in the same shape: |
| 85 | |
| 86 | ```json |
| 87 | { |
| 88 | "approval_mode": "manual", |
| 89 | "udp": { |
| 90 | "enabled": true, |
| 91 | "max_leases": 10 |
| 92 | }, |
| 93 | "tcp_port": { |
| 94 | "enabled": false, |
| 95 | "max_leases": 0 |
| 96 | } |
| 97 | } |
| 98 | ``` |
| 99 | |
| 100 | `max_leases` must be non-negative. `0` means unlimited. |
| 101 | |
| 102 | Supported modes: |
| 103 | |
| 104 | | Mode | Behavior | |
| 105 | |------|----------| |
| 106 | | `auto` | active leases can route unless banned or denied | |
| 107 | | `manual` | active leases route only after approval | |
| 108 | |
| 109 | ## Lease Policy |
| 110 | |
| 111 | `POST /api/policy/leases` accepts a partial policy update for one identity: |
| 112 | |
| 113 | | Field | Type | Effect | |
| 114 | |-------|------|--------| |
| 115 | | `identity_key` | `string` | normalized `name:address` key | |
| 116 | | `is_banned` | `boolean` | ban or unban identity registration and renewal | |
| 117 | | `is_approved` | `boolean` | approve or revoke explicit approval | |
| 118 | | `is_denied` | `boolean` | deny or remove denial; `true` also revokes approval | |
| 119 | | `bps` | `number` | set bytes-per-second limit; `0` removes the limit | |
| 120 | |
| 121 | Lease policy updates persist to `policy.json` and return `{}` on success. |
| 122 | |
| 123 | ## IP Policy |
| 124 | |
| 125 | `POST /api/policy/ips` accepts: |
| 126 | |
| 127 | ```json |
| 128 | { "ip": "203.0.113.10", "is_banned": true } |
| 129 | ``` |
| 130 | |
| 131 | The IP must parse as a valid IPv4 or IPv6 address. |