Security
Signatures, both ways
One secret per connection signs everything between ReplyBrain and your app: every call ReplyBrain makes to your mount, and every event your app posts. Scheme v2:
ReplyBrain-Signature: t=<unix seconds>,v2=<hex HMAC-SHA256(secret, signed string)>
ReplyBrain-Key-Id: key_1
signed string = "v2\n" + t + "\n" + METHOD + "\n" + path + "\n" + connection_id + "\n" + raw body
METHODis upper case (POST).pathis the absolute request path as sent, your mount included (/replybrain/capabilities/message.withdraw,/v1/connections/<id>/events), with?querywhen there is one.- The
connection_idis the audience: a request signed for one connection verifies on no other, and a request signed for one path (averify) cannot be replayed on another (aperform). - A signature older or newer than five minutes is refused: keep your server's clock in sync.
- Old
v1signatures (timestamp and body only) are refused.
The gem signs and verifies for you (ReplyBrain::Client::Signature.sign / .verify! for anything by hand). See Connection events for a worked example.
Rotating the secret with two keys
A connection holds its current key and, during a rotation, the previous one; both verify, the current one signs.
- You receive a new key (
key_2) and its secret. - Deploy your app with both, the new one first:
The first key signs your events; both verify ReplyBrain's calls.
c.signing_secrets = { "key_2" => creds[:secret_2], "key_1" => creds[:secret_1] } - ReplyBrain starts signing with
key_2. - Once nothing signed with
key_1is in flight (more than five minutes later), the old key is retired: remove it from your credentials and deploy.
A credential may carry an expiry; the connection's status reports grants: expiring within 14 days of it, and revoked once nothing can be signed.
API keys
/v1 takes organization-owned secret keys only (rb_sk_live_…), as Authorization: Bearer. Browser sessions and other key types are refused.
- Scopes per resource family:
cases.read,cases.write, … A write needs<family>.write. Actions with money, identity, deployment or work-tracker effects also needactions.<effect class>. - Bounds: a key may be limited to some products, connections, accounts or cases. Everything outside answers
404, as if it did not exist. - A decision made with a key (approving an action, deciding a need) is recorded as the decision of the member who created it. If that person leaves the organization, the key stops working.
- Your app's own key is bounded to its connection with
connections.read; its events need no key at all.
Keep secret keys on servers only, never in a browser or a mobile app.
What leaves your app
Only what you choose to send:
- Events: the message text, its direction and channel, and the
requesterandassigneefields you fill in. - Facts: exactly what your serializers return, only for the account in scope.
- Capability answers: the refs you return.
Send the minimum a support reply needs. Prefer your own opaque ids for ref and account_scope, send labels people read instead of internal codes, and leave out anything you would not show the customer: tokens, password hashes, full payment details, internal notes, other customers' data.
An email or name in requester is kept as your word about the customer, never treated as proof of who they are, and ReplyBrain never writes to an address it learned that way: a connected case's replies go back through your app.