Admin And Policy API
Operator endpoints are the control surface for a relay. They all return the standard JSON envelope described in API Reference, except for internal operational endpoints that are not part of the stable API.
/admin is reserved for the frontend route. Relay admin auth endpoints live
under /api/admin, and enforcement settings live under /api/policy.
Auth Flow
- Set
ADMIN_TOKENon the relay. POST /api/admin/auth/loginwith{ "token": "<admin-token>" }.- Send the returned
access_tokenasAuthorization: Bearer <token>. POST /api/admin/auth/logoutto clear the browser-stored token.
Admin bearer tokens are separate from SDK lease tokens.
Endpoints
| Method | Path | Auth | Body | Data |
|---|---|---|---|---|
POST | /api/admin/auth/login | None | AdminAuthLoginRequest | AdminAuthLoginResponse |
GET | /api/admin/auth/status | Optional bearer | none | AdminAuthStatusResponse |
POST | /api/admin/auth/logout | Bearer | none | {} |
GET | /api/policy | Bearer | none | PolicySettings |
POST | /api/policy | Bearer | PolicySettings | PolicySettings |
GET | /api/policy/state | Bearer | none | PolicyStateResponse |
POST | /api/policy/leases | Bearer | LeasePolicyUpdate | {} |
GET | /api/admin/metrics | Bearer | none | Prometheus text exposition |
Relay Metrics
GET /api/admin/metrics uses the same ADMIN_TOKEN bearer check as the other
admin endpoints. Configure the scraper with a bearer token and restrict access
to this operator route. When ADMIN_TOKEN is unset, the endpoint cannot be
scraped. The relay uses the standard Prometheus handler on this existing route;
there is no separate metrics listener or exporter setting, and no public /metrics endpoint.
| Metric | Type | Meaning |
|---|---|---|
portal_relay_active_leases | gauge | Non-expired lease registrations; one lease counts once even if it enables both TCP and UDP. |
portal_relay_active_connections | gauge | Bridged HTTP/SNI and raw TCP streams, including overlay streams. |
portal_relay_active_udp_flows | gauge | Tracked flows on active leases, including idle flows until expiry. |
portal_relay_forwarded_stream_bytes_total | counter | Successful stream bytes written in both directions; excludes UDP payloads. |
portal_relay_http_requests_total{method,code} | counter | Requests through the relay HTTP handler; methods outside the standard set use unknown. |
portal_relay_http_request_duration_seconds{code} | histogram | Time spent in the relay HTTP handler, in seconds. |
The HTTP series include control API and frontend requests, but not SNI-routed
tenant streams or raw TCP/UDP traffic. They have no URL, host, tenant, or
application labels. The snapshot series read portal.Server.Stats() during
each scrape and can reflect concurrent changes between fields. The forwarded
byte counter resets with a new Server instance; HTTP counters reset with a new
relay metrics registry. Standard Go and process metrics are included.
The current snapshot cannot provide separate HTTP/SNI, raw TCP, and UDP traffic
panels; that requires a separate relay stats contract change.
Auth Payloads
AdminAuthLoginRequest:
| Field | Type | Required |
|---|---|---|
token | string | yes |
AdminAuthLoginResponse:
| Field | Type |
|---|---|
access_token | string |
AdminAuthStatusResponse:
| Field | Type | Notes |
|---|---|---|
authenticated | boolean | true only when a valid bearer token was sent |
State
GET /api/policy/state returns the full policy view:
| Field | Type |
|---|---|
policy | PolicySettings |
leases | PolicyLease[] |
PolicyLease uses the shared Lease fields from API Reference and adds:
| Field | Type | Notes |
|---|---|---|
lease_id | string | relay lease ID; unique per row, so HTTP replicas of one identity stay separate |
identity_key | string | normalized name:address key |
address | string | normalized Ethereum address |
bps | number | effective stream bytes per second limit, including the relay default when no individual override exists; 0 means unlimited |
client_ip | string | relay-observed client IP |
reported_ip | string | client-reported public IP, when present |
is_approved | boolean | effective approval result |
is_banned | boolean | identity is banned |
is_denied | boolean | identity is denied |
Policy
Policy settings are written as one object through POST /api/policy and returned
in the same shape:
{
"approval_mode": "manual",
"udp": {
"enabled": true,
"max_leases": 10
},
"tcp_port": {
"enabled": false,
"max_leases": 0
}
} max_leases must be non-negative. 0 means unlimited.
Supported modes:
| Mode | Behavior |
|---|---|
auto | active leases can route unless banned or denied |
manual | active leases route only after approval |
A lease that stops being routable loses its idle reverse streams at once, so its ready count falls to 0 and the tunnel stops reporting ready. It keeps
renewing, and it reconnects within about 3 seconds after you approve it. No new
registration is needed.
Lease Policy
POST /api/policy/leases accepts a partial policy update for one identity:
| Field | Type | Effect |
|---|---|---|
identity_key | string | normalized name:address key |
is_banned | boolean | block or unblock routing for the identity |
is_approved | boolean | approve or revoke explicit approval |
is_denied | boolean | deny or remove denial; true also revokes approval |
bps | number | set an individual stream bytes-per-second override; 0 explicitly permits unlimited traffic; omitting the field leaves its setting unchanged |
reset_bps | boolean | true deletes the individual override and restores the relay default; cannot be combined with bps |
Lease policy updates persist to policy.json and return {} on success.
Identities without an individual override inherit DEFAULT_IDENTITY_BPS (default 1048576). Saved positive limits and explicit zero overrides take
precedence when the relay restarts with a different default. The budget is
shared across the identity’s stream connections and both directions.
Use Use relay default in the dashboard’s BPS settings to remove an override.
The reset persists, so subsequent relay defaults apply after restart too.