Authentication and signed streams
Cabby answers two questions for every client: who is connecting, and which streams it may read. For each one it either asks your app (RPC) or checks something your app signed with the shared secret, without calling your app.
| Ask your app | Check a signature, no call | |
|---|---|---|
| Connect | RPC connect |
a JWT |
| Subscribe | RPC command, for your channels |
a signed stream name, a Turbo stream name |
One secret
--secret (CABBY_SECRET) is the base of every key. A key you don't set yourself comes from it:
| Key | Flag | Without the flag |
|---|---|---|
| JWT | --jwt_secret |
the secret |
| Signed streams | --streams_secret |
the secret |
| Turbo Streams | --turbo_streams_secret |
--streams_secret, else the secret |
| HTTP RPC | --http_rpc_secret |
HMAC-SHA256 of rpc-cable with the secret, in hex |
| HTTP broadcasts | --broadcast_key |
HMAC-SHA256 of broadcast-cable with the secret, in hex |
cabby-rails derives its keys from the same secret, so a Rails app needs only CABBY_SECRET,
plus a key of its own for Turbo Streams, CABBY_TURBO_STREAMS_SECRET, when it uses Turbo
(Rails). For the RPC and
broadcast keys, Cabby logs auto-generated authorization secret from the application secret. In
another language, set --broadcast_key yourself, as the Node.js guide does, or derive
it the same way:
none turns a single key off, for example --http_rpc_secret=none. For
--turbo_streams_secret and --cable_ready_secret it refuses every name of that kind, and
--api_secret=none stops Cabby at startup (Configuration).
RPC: ask your app
With --rpc_host, Cabby calls your app when a client connects, subscribes, sends a message and
disconnects. A full URL selects HTTP RPC: Cabby sends POST requests to <rpc_host>/connect,
<rpc_host>/command and <rpc_host>/disconnect, with Authorization: Bearer <key> and the HTTP
RPC key from the table above. Anything else, such as the default localhost:50051, is a gRPC
address.
connectgets the request'sCookieheader. List the other headers it needs with--headers=cookie,x-tenant, and limit the cookies with--proxy-cookies.- Your app sees the client's address as
REMOTE_ADDR. Behind a proxy that is the proxy's address; addx-forwarded-forto--headersto pass the client's on. --rpc_concurrency(28 by default) limits the calls in flight at once.
--norpc runs Cabby without an app. Connections then need a JWT or --noauth; without either,
Cabby answers {"type":"disconnect","reason":"unauthorized","reconnect":false} and closes the
connection.
JWT: identify without a call
With a JWT key (--jwt_secret, or --secret), Cabby reads a token from the connection and takes
the client's identifiers from it, without calling connect. The startup log says so:
INF JWT authentication is enabled (param: jid, enforced: false)
The token is signed with HS256 (HS384 and HS512 work too). Its ext claim holds the identifiers
as a JSON string, the same identifiers your connect would return, and exp its expiry:
// token.js
const SECRET = process.env. // same value as --secret (or --jwt_secret)
const
In Rails, cabby-rails makes the token for you: Cabby.jwt, and the action_cable_with_jwt_meta_tag
and cabby_token_meta_tag helpers for the layout (Rails).
The client sends it in one of three places:
| Where | Example |
|---|---|
| Query parameter | wss://cable.example.com/cable?jid=<token> |
| Header | X-JID: <token> |
| WebSocket subprotocol | cabby-token.<token>, next to actioncable-v1-json |
--jwt_param renames jid, and the header becomes X-<param>. anycable-token.<token> works as
a subprotocol too, and Cabby reads the subprotocols on every Sec-WebSocket-Protocol line the
client sends.
- No token: Cabby calls
connectas usual. With--enforce_jwt, it rejects the connection instead. - Expired token:
{"type":"disconnect","reason":"token_expired","reconnect":false}. Issue a new token and reconnect. - Bad signature:
{"type":"disconnect","reason":"unauthorized","reconnect":false}.
Subscriptions to your channels still go to your app over RPC; signed streams don't need it.
Signed streams
A signed stream lets a client read one stream your app chose for it, with no RPC call. Your app
signs the stream's name with --streams_secret (or --secret): the name as JSON, in Base64, then
-- and the hex HMAC-SHA256 of that Base64 text. The Node.js and
FastAPI guides have the helper. The client subscribes to the $pubsub channel:
That name is room:1 signed with the secret s3cret. A name signed with another secret gets
reject_subscription, and with --debug Cabby logs subscription failed with
error="verification failed".
- Presence is on for signed streams (
--streams_presence, true by default); whispers are off until you add--streams_whisper. See History, recovery and presence. - Server-Sent Events take the same name in
?signed_stream=, Durable Streams in?signed=. See SSE and Durable Streams.
Turbo Streams
turbo_stream_from subscribes to Turbo::StreamsChannel with a stream name Rails signed. By
default that subscription is an RPC call. --turbo_streams lets Cabby check the signature itself,
with --turbo_streams_secret, else --streams_secret, else --secret:
INF Using channels router: $pubsub, Turbo::StreamsChannel
The key must be the one Rails signs with; the Hotwire guide explains how cabby-rails
keeps them in step. Over SSE, pass the signed name in ?turbo_signed_stream_name=.
With one key for Turbo Streams and signed streams, a Turbo signed name is also a signed $pubsub
name, which gives presence on its stream, and whispers with --streams_whisper. Cabby says so at
startup, and the same goes for CableReady names with --cable_ready:
WRN Turbo Streams signed names are also accepted by $pubsub (the same key verifies them), where they give presence on their stream; set --turbo_streams_secret to a key of its own context=config
If your app uses presence or whispers on signed streams, give Turbo Streams a key of its own:
CABBY_TURBO_STREAMS_SECRET, set for both your app and Cabby (or --cable_ready_secret for
CableReady). If it uses neither, --streams_presence=false turns that presence off.
What the public flags turn off
| Flag | What Cabby stops checking |
|---|---|
--public_streams |
Stream signatures. A client subscribes to {"channel":"$pubsub","stream_name":"news"} and reads any stream it can name, whatever it was meant for, history included. Public streams also allow presence and whispers. With the Pusher endpoint on, names starting with private- or presence- still need a signature. |
--noauth |
Connections. Cabby accepts every connection without calling connect; subscriptions to your channels still go to your app. |
--public |
Both of the above, and the broadcast key: /_broadcast takes requests without one. |
--public logs WRN Server is running in the public mode at startup, and while every origin is
allowed it adds that pages on any site can open connections too. Without a key, the broadcast
endpoint and the API are announced at warn level, with what anyone who reaches them can do. Use
--public for local experiments only. --noauth with signed streams is a real setup: anyone may connect, and the
signed names decide what each client reads.
--allowed_origins decides which web pages may open connections at all; see
Configuration.