Skip to content

arisrvx: the authenticate hook and principals (S5), and relay joins with token: oidc - #1130

Merged
transfix merged 10 commits into
masterfrom
feat/arisrvx-authenticate
Nov 11, 2026
Merged

transfix merged 10 commits into
masterfrom
feat/arisrvx-authenticate

Conversation

@transfix

@transfix transfix commented Nov 10, 2026 •

Copy link
Copy Markdown
Owner

S5 of the scripting-hosts roadmap's application-services cut (docs/roadmap/ARIADNE_SCRIPTING_HOSTS.md §6.5.4, the S5 row of §10): the authenticate hook and principals. #1122 (S2) is merged (698752b), so this now targets master, with master merged in.

It also carries #1132 (the client's relay: token: oidc and reconnects), squash-merged into this branch as d444453. See #1132 for that half's description and tests.

What it adds

@host.authenticate
async def auth(cred):                 # cred.bearer, cred.transport ("grpc" | "ws"), cred.peer
    user = await verify(cred.bearer)
    return {"id": user.sub, "roles": ["staff"]} if user else None
  • Transports. state_transport::set_authenticator takes a state_authenticator: a state_credential (bearer, transport, peer) maps to a principal id, or to "" and a reason.
    • gRPC calls it in Channel(), and WS during the upgrade. Both run on the connection's own thread, before it is admitted, so the call may block.
    • It replaces the room token. A refusal looks like a wrong room token's: gRPC UNAUTHENTICATED, or a refused upgrade, with nothing sent.
    • disconnect_principal closes a principal's connections.
    • valid_bearer_token takes up to 4096 characters, so a JWT fits.
  • The gate. state_inbound_gate::bind takes the claimant's principal.
    • A silent holder's id is taken over only by the same principal (total_principal_refusals).
    • principal_of(node_id) names whose a participant is: bound writes keyed by principal.
    • The participant path stays the pid's, so a client needn't know its principal's id to join.
  • arisrvx.
    • @host.authenticate runs on the script loop for each connection, within --auth-timeout (5 s; the relay waits with the new ServerLink::request). A None, a raise, or no verdict refuses the connection.
    • The relay keeps each principal by id and hands it to that caller's calls as ctx.principal, so role gates check its roles.
    • host.disconnect(principal) closes that principal's connections on the next room step.
    • Calls are limited per principal: --call-concurrency (8 in flight) and --call-rate (a token bucket, off by default). Past either, a call is answered rate_limited.
  • Clients. A refused join fails the load at once: "refused this host (unauthenticated…)", instead of waiting out the 10 s join. A connection the relay closes later (it stopped, or host.disconnect) ends the waiting calls unavailable, and later ones too.

Tests

  • StateTransportGrpcTest.InboundGateKeysANodeIdToItsPrincipal: takeover only by the same principal, principal_of.
  • StateTransportGrpcTest.AnAuthenticatorAdmitsAndBindsPrincipals and StateTransportWsTest.AnAuthenticatorJudgesTheHandshake:
    • a refused bearer is never admitted;
    • an admitted one is bound with its principal;
    • disconnect_principal closes it;
    • a 900-character bearer works over WS.
  • ServerLinkTest.ARequestWaitsForItsAnswerOrItsTimeout; pycvc_ariadne_server (the limits' token bucket, host.authenticate under plain python, a credential's repr hiding its token).
  • ctests against tests/auth_service.py, which knows two test tokens:
    • arisrvx_auth_staff: alice's principal (name, roles) reaches ctx, the role gate passes, a third call in flight is rate_limited, and host.disconnect closes her connection, so the next call is unavailable.
    • arisrvx_auth_user_ws: bob, over the WebSocket, is forbidden the staff function.
    • arisrvx_auth_refuses_{wrong,slow,raises}: a wrong token, a hook that stalls past --auth-timeout 1 and one that raises are all refused, unauthenticated, at once.

Run locally on Windows (static Release, gRPC + WS, pycvc core, wasmtime from cvcpkg):

  • the S2 + S5 ctest set and the new unit tests passed, 53/53;
  • state_transport_grpc_test 53, state_transport_ws_test 43 and room_relay_integration_test 19 passed in full.

Not in this PR

  • The client's token: oidc (§6.5.7). It needs a join deferred until the sign-in, a reconnect that refreshes the token, and a policy that binds the credential to the relay's origin (CredentialStore::token_for). This is a follow-up.
  • Re-validating long-lived connections stays the service's job: a task that calls host.disconnect, as §6.5.4 says.
  • No release.

…(S2)

S2 of the scripting-hosts roadmap's application-services cut
(docs/roadmap/ARIADNE_SCRIPTING_HOSTS.md 10).

room-call (6.5.5): a client calls a function the relay's Python exports.
The call rides the caller's own participant path with ttl_hops 0, and
room_write_gate refuses one on another's path or one it would fan out.
Replies go only to the connection holding the pid
(state_transport::send_message_to_holder, gRPC and WS). In the DSL:
room-call, room-call-async and room-call-opts. In Python: export(clients=,
roles=, timeout=, is_async=), CallError, and ctx (principal, call_id,
idempotency_key, deadline, progress). Then forbidden, internal (traceback
logged, never sent), deadline_exceeded, too_large (--call-result-max),
not_found, and unavailable from stock arisrv. --script-slow-ms logs a slow
sync function by name.

DSL values keep their types: the relay and Python hand each other value_t
in cvc.state_exec.value capsules that pycvc converts
(pycvc.value_from_capsule, pycvc.value_capsule), never JSON. Between
processes the wire is the DSL's own JSON, which keeps int vs float.

A server document's python: block runs on the script thread (6.2), with
no --python too; its exports and the program's are the document's
functions, a call parks the program and init: waits in place.
arisrvx check takes the program optionally.

Relay joins (6.5.7): relay_session / attach_relay, the relay: block (url,
room, token env:/file:, ca, subscribe) and --relay/--relay-room/--relay-ca
in ari and the x hosts, waiting out the admission hold before init:.
Subscriptions are mirrored read-only under the document's root. arigl's
conference session installs a room_call_client. arisrv --tls-cert and
--tls-key serve both gRPC planes over TLS for grpcs:// clients
(tls_config::client_tls for gRPC's roots); wss:// is refused.

Tests: ServerLinkTest, RoomRelayLoopbackTest.ARoomCallReachesTheRelayAndOnlyItsCaller,
RoomCallsTest.ParseCall, pycvc_ariadne_server, arisrvx_doc_python,
arisrvx_check_doc_python, arisrvx_room_call_{grpc,grpcs,tls_needs_its_ca,ws_arix}
and arisrv_room_call_unavailable.
The client-to-relay hop was the DSL's JSON, which keeps int vs float but
not symbols or bytes. It is now typed CBOR in the message's bytes
(application/x-cvc-room-call+cbor and -reply+cbor), so every data value
arrives as it was sent, on every hop of a call.

The codec is the WebAssembly guests' value_cbor, moved into the core
library as cvc/state/state_exec/value_cbor.h (encode_cbor, decode_cbor,
cbor_handles, cbor_options). With cbor_options::symbols a symbol crosses
under tag 39, IANA's "identifier", and reads back as a symbol. The guests'
boundary keeps symbols as text: src/ariadne_wasm/value_cbor.h is now thin
wrappers with its old names.

A function or a host object doesn't cross and fails the call where it is
sent, as a TypeError. --call-result-max counts the encoded bytes.

Tests: ValueCbor.* (round trips with types, the symbol tag on and off,
what is refused); the loopback room-call test sends a symbol and bytes;
RoomCallsTest.ParseCall reads CBOR; call_client.ari checks symbols and
bytes end to end, and that a lambda is refused.
S5 of the scripting-hosts roadmap's application-services cut
(docs/roadmap/ARIADNE_SCRIPTING_HOSTS.md 6.5.4 and the S5 row of 10),
stacked on S2.

Transports: state_transport::set_authenticator takes a state_authenticator
(a state_credential of bearer, transport and peer, mapped to a principal
id, or "" and why). gRPC calls it in Channel(), WS during the upgrade, on
the connection's own thread before it is admitted, in place of the room
token; a refusal is the room token's (UNAUTHENTICATED, a refused upgrade),
with nothing sent. disconnect_principal closes a principal's connections.
valid_bearer_token allows bearers up to 4096 characters, so a JWT fits.

The gate: state_inbound_gate::bind takes the claimant's principal; a
silent holder's id is taken over only by the same principal
(total_principal_refusals), and principal_of names whose a participant is.

arisrvx: @host.authenticate (sync or async; a principal dict with a str id,
or None) runs on the script loop for each connection, within
--auth-timeout (5 s; ServerLink::request waits). The relay keeps each
principal by id for its calls' ctx.principal, so role gates check its
roles. host.disconnect(principal) closes that principal's connections on
the next room step. Calls are limited per principal: --call-concurrency
(8 in flight) and --call-rate (a token bucket, off by default), past which
a call is answered rate_limited.

Clients: a refused join fails at once ("refused this host
(unauthenticated...)"), and a connection the relay closes later ends the
waiting and later calls unavailable.

Not here: the client's token: oidc, which needs a join deferred until the
sign-in and a reconnect that refreshes the token.

Tests: StateTransportGrpcTest.InboundGateKeysANodeIdToItsPrincipal,
StateTransportGrpcTest.AnAuthenticatorAdmitsAndBindsPrincipals,
StateTransportWsTest.AnAuthenticatorJudgesTheHandshake,
ServerLinkTest.ARequestWaitsForItsAnswerOrItsTimeout, pycvc_ariadne_server,
and arisrvx_auth_{staff,user_ws,refuses_wrong,refuses_slow,refuses_raises}.
Base automatically changed from feat/arisrvx-room-call to master November 10, 2026 20:18
* relay joins: token: oidc (a host credential) and reconnects

The client half S2 and S5 left out (docs/roadmap/ARIADNE_SCRIPTING_HOSTS.md
6.5.7), stacked on S5.

relay: token: credential:NAME, or oidc:NAME for the credential an
(oidc-sign-in ...) keeps, and --relay-credential NAME: the token is read
from the host's credential store (net_host_access) at every join, for
the relay's origin (relay_credential_origin: https://host:port for
grpcs:// and wss://, http:// for grpc:// and ws://), which a policy line
binds the credential to. A credential the relay refused, or that its
renewer says is expiring, is renewed first: an OIDC sign-in refreshes it.

The join waits for the credential: attach_relay begins the session, and
pump() dials from the frames once the credential holds a token, on a
thread of its own so a frame never waits on the network. Until then
room-call answers unavailable.

Every join reconnects: a link the relay closes is dialed again after 1 s,
doubling to 30 s, with the token read again, the shard and the
participant id kept. A dial counts once the relay's Hello arrives
(replies write through the admission hold). The document sees
relay.status and relay.joins under its root.

S1's arisrvx_program waited for job.state and could read steps half
written (the relay writes a subtree leaf by leaf); it waits for the last
leaf now.

Tests: RoomRelayLoopbackTest.ARelaySessionJoinsOnceItsCredentialHoldsAToken,
RoomRelayLoopbackTest.ARelaySessionRenewsARefusedCredential,
arisrvx_auth_credential (a credential through --credential-env and a
policy line; host.disconnect, then the client is back and admitted
again), and arisrvx_auth_staff now revokes (the hook refuses, so the
client stays out).

* docs(roadmap): the client join is #1132
@transfix transfix changed the title arisrvx: the authenticate hook and principals (S5) arisrvx: the authenticate hook and principals (S5), and relay joins with token: oidc Nov 10, 2026
CI's arigl-web job (emscripten, no pthreads) failed on
state_transport_ws::disconnect_principal: a browser connection has no
abort_io(). A browser accepts no connections, so none has a principal: the
browser build returns 0.

relay_session's dialer thread would throw there (std::thread in a
single-threaded build), so that build dials in the frame, as a token join's
dial does at the load.
Picks up #1133, which puts room_calls.cpp's seven objects on the writable-data scan's allowlist; the scan failed package-linux / libcvc-release-grpc on them.
@transfix
transfix merged commit 3c1f780 into master Nov 11, 2026
28 of 33 checks passed
@transfix
transfix deleted the feat/arisrvx-authenticate branch November 11, 2026 06:53
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

1 participant