PORTAL v2

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

  1. Set ADMIN_TOKEN on the relay.
  2. POST /api/admin/auth/login with { "token": "<admin-token>" }.
  3. Send the returned access_token as Authorization: Bearer <token>.
  4. POST /api/admin/auth/logout to clear the browser-stored token.

Admin bearer tokens are separate from SDK lease tokens.

Endpoints

MethodPathAuthBodyData
POST/api/admin/auth/loginNoneAdminAuthLoginRequestAdminAuthLoginResponse
GET/api/admin/auth/statusOptional bearernoneAdminAuthStatusResponse
POST/api/admin/auth/logoutBearernone{}
GET/api/policyBearernonePolicySettings
POST/api/policyBearerPolicySettingsPolicySettings
GET/api/policy/stateBearernonePolicyStateResponse
POST/api/policy/leasesBearerLeasePolicyUpdate{}
GET/api/admin/metricsBearernonePrometheus 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.

MetricTypeMeaning
portal_relay_active_leasesgaugeNon-expired lease registrations; one lease counts once even if it enables both TCP and UDP.
portal_relay_active_connectionsgaugeBridged HTTP/SNI and raw TCP streams, including overlay streams.
portal_relay_active_udp_flowsgaugeTracked flows on active leases, including idle flows until expiry.
portal_relay_forwarded_stream_bytes_totalcounterSuccessful stream bytes written in both directions; excludes UDP payloads.
portal_relay_http_requests_total{method,code}counterRequests through the relay HTTP handler; methods outside the standard set use unknown.
portal_relay_http_request_duration_seconds{code}histogramTime 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:

FieldTypeRequired
tokenstringyes

AdminAuthLoginResponse:

FieldType
access_tokenstring

AdminAuthStatusResponse:

FieldTypeNotes
authenticatedbooleantrue only when a valid bearer token was sent

State

GET /api/policy/state returns the full policy view:

FieldType
policyPolicySettings
leasesPolicyLease[]

PolicyLease uses the shared Lease fields from API Reference and adds:

FieldTypeNotes
lease_idstringrelay lease ID; unique per row, so HTTP replicas of one identity stay separate
identity_keystringnormalized name:address key
addressstringnormalized Ethereum address
bpsnumbereffective stream bytes per second limit, including the relay default when no individual override exists; 0 means unlimited
client_ipstringrelay-observed client IP
reported_ipstringclient-reported public IP, when present
is_approvedbooleaneffective approval result
is_bannedbooleanidentity is banned
is_deniedbooleanidentity 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:

ModeBehavior
autoactive leases can route unless banned or denied
manualactive 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:

FieldTypeEffect
identity_keystringnormalized name:address key
is_bannedbooleanblock or unblock routing for the identity
is_approvedbooleanapprove or revoke explicit approval
is_deniedbooleandeny or remove denial; true also revokes approval
bpsnumberset an individual stream bytes-per-second override; 0 explicitly permits unlimited traffic; omitting the field leaves its setting unchanged
reset_bpsbooleantrue 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.