Skip to content

Admin REST API (internals)

Every node container that runs the Python SDK exposes a read-only operator surface under /admin/ on its HTTP port: five routes protected by Auth0 JWT validation plus a YAML allowlist, each call written to a structured audit log. This page documents the routes, the allowlist file and its environment variable, the audit fields, where the router is mounted, and a security divergence from the C++ SDK that the platform team should close. Node authors never see or configure any of this; the surface is inherited from the SDK.

Where it is mounted

src/neuraverse_sdk/api/http/http_api.py builds the FastAPI app (docs_url and openapi_url disabled), includes the node router, then unconditionally includes build_admin_router() from neuraverse_sdk.api.http.admin. serve_http() binds uvicorn to HttpConfig.address and HttpConfig.port from the http: block of service_config.yaml. There is no switch to leave the admin router out and no check on the bind address.

The allowlist is bound during dependency-injection wiring in node_manager_service.py: binder.bind(AdminAllowlist, AdminAllowlist()) runs once at service start, and the instance installs a SIGHUP handler that re-reads the file in place.

flowchart LR
    C[nodectl / curl<br/>Authorization: Bearer JWT] --> U[uvicorn on http.address:http.port]
    U --> R[APIRouter prefix /admin]
    R --> D[RequireAdmin scope]
    D --> J[JWTAuthValidator<br/>signature, issuer, audience, expiry]
    J --> A[AdminAllowlist.check<br/>sub first, then email, then scope]
    A -->|listed| H[route handler] --> L[nodectl.audit log line]
    A -->|not listed| E[NeuraPublicAuthorizationError<br/>echoes sub and email]

Routes

All routes live in src/neuraverse_sdk/api/http/admin/router.py, prefix /admin, tag admin, and every one depends on RequireAdmin("read"). Version 1 is read-only; the module docstring reserves mutators (restart-soft, log-level) for a later step on the same auth and allowlist pipeline.

Route Response body Notes
GET /admin/whoami {"sub", "email", "scopes"} of the resolved admin entry Cheapest way to test the whole auth pipeline.
GET /admin/node/status {"service_name", "uptime_seconds", "registered_classes", "bound_instances"} Uptime from NodeController._start_time_monotonic; classes are the keys of NodesRegistry.current_nodes_instances_registry, useful before any node is initialized.
GET /admin/nodes {"nodes": [{"node_id", "class_name", "state"}, ...]} sorted by node_id Only bound instances (those the engine has sent InitializeNode for) are listed; entries with node_id is None are skipped.
GET /admin/nodes/{node_id}/state {"node_id", "class_name", "state"} NeuraPublicResourceNotFoundError when the id is not bound on this container.
GET /admin/nodes/{node_id}/diag state fields plus "last_status": {"result_code", "result_message", "state"} and "topics": {"inputs": {port: topic}, "outputs": {port: topic}} last_status is the controller's _last_status_by_node_id snapshot recorded by _record_last_status_snapshot(), or null. Topic maps are best-effort and empty before the dataflow exists.

state is the ExecutionState enum name with the EXECUTION_STATE_ prefix removed (RUNNING, CONFIGURED, ...), or UNKNOWN when the state machine cannot be read; the helpers are written so a wedged node instance cannot 500 the whole surface.

The C++ SDK serves the same routes through cpp-httplib regex routes, which since cpp-httplib 0.58.0 (SDK 2.46.1) do not match request paths over 256 characters. /admin/nodes/<id>/state and /diag therefore return 404 for node IDs longer than about 230 characters on C++ nodes; the Python router has no such limit.

The module docstring positions the surface as the fallback path for when the engine cannot reach a node: the CLI flow is identical to engine-mediated access, only the URL changes.

Authentication and authorization

dependencies.py defines RequireAdmin(scope), a callable FastAPI dependency:

  1. JWTAuthValidator() from neuraverse_common.http.auth.jwt_dependencies validates the bearer token (signature, issuer, audience, expiry) through the service's JwtValidator, which node_manager_service binds from the jwt: block of the service config, and yields the claims. A missing or invalid token raises NeuraPublicAuthenticationError before the allowlist is consulted.
  2. Identity is sub (claim sub) and email (claim https://neuraverse.com/email, falling back to email).
  3. inject.instance(AdminAllowlist).check(sub=..., email=..., scope=...) must return an entry, otherwise NeuraPublicAuthorizationError is raised with a message that echoes the token's sub and email and names the missing scope, so the caller can ask to be added.

Neither SDK reads forwarded identity headers; validation is in-process.

The allowlist file

allowlist.py:

Item Value
Default path /etc/neuraverse/admin_allowlist.yaml (DEFAULT_ALLOWLIST_PATH), mounted from a ConfigMap in Kubernetes deployments
Override environment variable NEURAVERSE_ADMIN_ALLOWLIST_PATH (ALLOWLIST_PATH_ENV), read once in AdminAllowlist.__init__
Scopes read, write, destructive (VALID_SCOPES); any other value fails the parse
Matching by sub first, then by lower-cased email; the entry must contain the requested scope
Reload SIGHUP (handler chains to any pre-existing handler) or AdminAllowlist.reload()
admins:
  - sub: "auth0|abc123"          # preferred, stable
    email: alice@example.com     # fallback, mutable
    scopes: [read]

Failure behaviour is deliberately asymmetric. A missing file logs Admin allowlist ... not found and loads an empty roster, so every admin call is rejected. A file that fails to parse logs an error and keeps the previous in-memory snapshot, so a bad edit cannot lock operators out of a running node. Each entry needs at least sub or email. Edge nodes that lose connectivity keep the in-memory copy; nothing is fetched remotely on the request path.

Audit log

audit.py writes one record per admin call to the stdlib logger nodectl.audit (AUDIT_LOGGER_NAME), bypassing the LoggerFactory wrapper so the structured fields land as LogRecord attributes via extra= and can be filtered or shipped separately. The message reads admin <op> <target or -> -> <outcome>; the extras are:

Field Set by Meaning
audit always True marks the stream
actor AdminUser.identity sub, else email, else <unknown>
op route admin.whoami, admin.node.status, admin.nodes.list, admin.nodes.state, admin.nodes.diag
outcome record() ok, or error when the body raised (the exception is re-raised)
target route the node_id for the per-node routes
latency_ms record() wall time of the handler body
source_ip request.client.host transport address, never a header
request_id optional never passed by the Python routes today
args route sanitized extras only, for example {"count": n} on admin.nodes.list
error record() ExceptionType: message on failure

emit() is documented as taking pre-sanitized args: never tokens or raw bodies. The audit stream sits alongside the ordinary logs and may be retained longer.

Operator use

The surface exists for operators and the nodectl CLI; it is not part of the node-author contract and must not appear in the vendored guide (/admin/ and nodectl are on the public denylist). Manual check against a node container, with the port taken from the http: block of its service_config.yaml:

TOKEN=...   # Auth0 access token for a listed identity
curl -sS -H "Authorization: Bearer $TOKEN" http://<node-host>:<http.port>/admin/whoami
curl -sS -H "Authorization: Bearer $TOKEN" http://<node-host>:<http.port>/admin/nodes

An authorization error whose message says Admin permission required (scope='read'). Token identity: sub=..., email=... means the JWT is valid and the identity is simply not in the allowlist. An authentication error (Authentication data is invalid) means the JWT itself was rejected.

Coverage and specifications

The behaviour is pinned by specifications/specs/admin/ (allowlist matching and env-var loading, audit extras, /admin/whoami pipeline, /admin/node/status, list/state/diag, scope enforcement) via the loader tests/specs/test_admin_specs.py and the steps in specifications/specs/steps/admin_steps.py. Note that pyproject.toml omits */api/http/* from coverage, so these specs run in the coverage job but do not count towards fail_under. There is no numbered prompt for the admin API under specifications/prompts/.

C++ SDK differences

Since SDK 2.47.0

The C++ admin routes validate a bearer JWT in-process, like Python. Earlier C++ nodes trusted mesh-forwarded identity headers; x-neura-sub and x-neura-email are no longer read, and http.admin.allow_non_loopback_bind and the loopback-only bind check are gone. A deployment that relied on the forwarded headers must send Authorization: Bearer <JWT> instead.

The C++ routes use the jwt / jwt__* configuration of NodeServiceApi. The token's sub, or email (https://neuraverse.com/email, falling back to email), is matched against the unchanged YAML allowlist.

Aspect C++ SDK Python SDK (this page)
Surface enabled by default No: admin.enabled = false; routes are registered only when enabled, on any bind address Yes: app.include_router(build_admin_router()) is unconditional
Identity source Bearer JWT validated in-process Same
Missing or invalid token 401 NeuraPublicAuthenticationError
Key set unreachable 503 Only on a connect timeout
Allowlist miss 403, body echoes Token identity: sub=..., email=... NeuraPublicAuthorizationError with the same echo
Bearer scheme Case-sensitive Any case (FastAPI)
Error body {"error": "..."} NeuraHttpError envelope
Claims used String sub and email claims only Same claims, any JSON type
Allowlist schema, scopes, SIGHUP semantics Same Same
Five read routes and response shapes Same Same
Audit fields ts, actor, op, target, outcome, latency_ms, source_ip, request_id, args, error No explicit ts field (the timestamp comes from the log record); request_id never populated

The C++ listener is plain HTTP, so the token is not encrypted unless TLS is terminated in front of it.

Follow-up for the platform team

Python nodes expose /admin/* on every HTTP listener, protected only by the JWT check and the allowlist, while C++ registers the routes only when admin.enabled is set. Options to evaluate: an admin.enabled flag in NodeServiceConfig mirroring the C++ default, or an explicit decision to keep the surface always mounted. The allowlist schema, the audit field names and the five route shapes are frozen cross-SDK contracts so one ConfigMap and one nodectl serve both SDKs; the ts and request_id gaps above are the only places where the Python emitter and the C++ writer differ today.

See also