Repository navigation
arisrvx: the authenticate hook and principals (S5), and relay joins with token: oidc - #1130
Merged
Merged
Conversation
…(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}.
* 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
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.
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
Add this suggestion to a batch that can be applied as a single commit.This suggestion is invalid because no changes were made to the code.Suggestions cannot be applied while the pull request is closed.Suggestions cannot be applied while viewing a subset of changes.Only one suggestion per line can be applied in a batch.Add this suggestion to a batch that can be applied as a single commit.Applying suggestions on deleted lines is not supported.You must change the existing code in this line in order to create a valid suggestion.Outdated suggestions cannot be applied.This suggestion has been applied or marked resolved.Suggestions cannot be applied from pending reviews.Suggestions cannot be applied on multi-line comments.Suggestions cannot be applied while the pull request is queued to merge.Suggestion cannot be applied right now. Please check back later.
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
authenticatehook 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: oidcand reconnects), squash-merged into this branch as d444453. See #1132 for that half's description and tests.What it adds
state_transport::set_authenticatortakes astate_authenticator: astate_credential(bearer, transport, peer) maps to a principal id, or to "" and a reason.Channel(), and WS during the upgrade. Both run on the connection's own thread, before it is admitted, so the call may block.UNAUTHENTICATED, or a refused upgrade, with nothing sent.disconnect_principalcloses a principal's connections.valid_bearer_tokentakes up to 4096 characters, so a JWT fits.state_inbound_gate::bindtakes the claimant's principal.total_principal_refusals).principal_of(node_id)names whose a participant is: bound writes keyed by principal.@host.authenticateruns on the script loop for each connection, within--auth-timeout(5 s; the relay waits with the newServerLink::request). A None, a raise, or no verdict refuses the connection.ctx.principal, so role gates check itsroles.host.disconnect(principal)closes that principal's connections on the next room step.--call-concurrency(8 in flight) and--call-rate(a token bucket, off by default). Past either, a call is answeredrate_limited.host.disconnect) ends the waiting callsunavailable, and later ones too.Tests
StateTransportGrpcTest.InboundGateKeysANodeIdToItsPrincipal: takeover only by the same principal,principal_of.StateTransportGrpcTest.AnAuthenticatorAdmitsAndBindsPrincipalsandStateTransportWsTest.AnAuthenticatorJudgesTheHandshake:disconnect_principalcloses it;ServerLinkTest.ARequestWaitsForItsAnswerOrItsTimeout;pycvc_ariadne_server(the limits' token bucket,host.authenticateunder plain python, a credential's repr hiding its token).tests/auth_service.py, which knows two test tokens:arisrvx_auth_staff: alice's principal (name, roles) reachesctx, the role gate passes, a third call in flight israte_limited, andhost.disconnectcloses her connection, so the next call isunavailable.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 1and one that raises are all refused, unauthenticated, at once.Run locally on Windows (static Release, gRPC + WS, pycvc core, wasmtime from cvcpkg):
state_transport_grpc_test53,state_transport_ws_test43 androom_relay_integration_test19 passed in full.Not in this PR
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.host.disconnect, as §6.5.4 says.