Skip to content

feat(router): add ReBAC-protected event-to-socket relays - #1600

Open
JohnChantz wants to merge 4 commits into
mainfrom
feat/router-event-relays
Open

JohnChantz wants to merge 4 commits into
mainfrom
feat/router-event-relays

Conversation

@JohnChantz

Copy link
Copy Markdown
Contributor

What kind of change does this PR introduce?

  • Bugfix
  • Feature
  • Code style update
  • Refactor
  • Build-related changes
  • Other (please describe)

Does this PR introduce a breaking change?

  • Yes
  • No

The PR fulfills these requirements:

  • It's submitted to the main branch
  • When resolving a specific issue, it's referenced in the PR's description (e.g. fix #xxx, where "xxx" is the issue number)

If adding a new feature, the PR's description includes:

  • A convincing reason for adding this feature

Other information:

Split from #1594 (1/3). Follow-ups: Mongo live updates, then SQL live updates.

Apps need to forward exact Redis bus events to Socket.io without REST polling. Relays stay authorization-aware: subscribe is allowed only when User:<id> has the configured permission on <resourceType>:<resourceId>.

Summary

Admin-configured, ephemeral mappings from an exact Redis bus channel to a templated Socket.io event on /events/. Clients subscribe with relayId + resourceId; rooms are derived server-side. Admin CRUD is at /router/event-relays. Emission is local-only so HA instances do not duplicate.

Companion Admin UI: ConduitPlatform/Conduit-UI#327

Test plan

  • Router event-relay unit tests (pnpm --filter @conduitplatform/router test): channel matching, template rendering, ReBAC authorize, subscribe/unsubscribe rooms
  • Create/edit/disable/delete a relay via Admin API
  • Subscribe with a user token that has the relation → receive the templated payload
  • Subscribe without the relation → PERMISSION_DENIED
  • Confirm inactive relays and mismatched bus event names do not emit

@JohnChantz

Copy link
Copy Markdown
Contributor Author

Stack: this PR → #1601 (Mongo live updates) → #1602 (SQL live updates). Split from #1594.

@kkopanidis
kkopanidis added this pull request to stack #1603 September 11, 2026 17:43
Forward exact Redis bus events as templated Socket.io messages on
/events/, with resource-scoped rooms and local-only HA emission.
…ger) (#1604)

* fix(router): harden event relays for HA and auth lifetime

EventBus uses a single Redis message dispatcher with subscriberId maps,
SIGTERM/SIGINT shutdown, and subscribe-after-ACK. Hermes installs engine
middleware once, skips empty-room namespace broadcasts, demotes hot-path
logs, and re-authenticates recovered /events/ subscriptions. EventRelayManager
gains coalesced periodic reconcile, compiled templates, inbound caps,
TTL-cached emit-time ReBAC, room eviction, backpressure, preview API, and
metrics/docs aligned with the interventions plan.

* fix(router): address #1604 re-review P1 and P2 follow-ups

Recovery re-auth keeps per-user subscription state across disconnect;
emit-time ReBAC distinguishes unavailable vs deny; EventBus drops process
signal handlers and adds subscribeAck; manager subscribes only after Redis
ACK and broadcasts evictRelayIds on refresh; Hermes backpressure uses local
sockets without emit acks; cache is bounded; preview caps sample JSON;
handshake matcher rejects ticket/sid/non-namespace paths; socket middleware
rebind avoids duplicate registration on first sockets enable.

* fix(hermes): restore production tsc for engine middleware chain

Type the Socket.IO engine middleware runner as Express NextFunction so
recursive callbacks match registerGlobalMiddleware. Use Logger.info for
socket trace lines (IConduitLogger has no debug).

* fix(router): import Express Response for socket global middleware

_rebindSocketGlobalMiddlewares passes handlers typed with fetch Response
because Response was not imported from express, failing tsc against Hermes
registerSocketGlobalMiddleware.

* fix(router): quit EventBus on module shutdown signals

Stop event relays and call grpcSdk.bus.quit() from Router.shutdown(),
registered on SIGTERM/SIGINT with process exit so Redis teardown is not
left to SDK signal handlers. Tighten registerGlobalMiddleware typing and
trim handshake helper comment (deslop).

* fix(router): pass-3 recovery, scoped emit, and subscription hygiene

Recovery re-auth keeps membership on Authorization UNAVAILABLE and only
leaves on deny; re-check subscriptions for restored er: rooms via room map.
Prune user subscriptions on disconnect when no other socket holds them.
Scope relay emits to receivers in the target room; use Engine.IO
writeBuffer/writable for backpressure. Drop hot-path Hermes socket info logs.

* fix(router): pass-4 recovery map, backpressure, emit tests

Store relay subs on socket.data; resolve recovered rooms from context and
TTL room map without last-writer userId. Prune room map when unused on
disconnect. Backpressure uses writeBuffer depth only. Add Hermes/router
tests for room-scoped emit and queue metric.

* fix(router): clear eventRelaySubs from socket.data on recovery deny

* fix(router): clear socket.data subs on recovery fail-closed leave

getLocalRoomUserIds(namespace: string, room: string): Promise<string[]> {
return (
this._socketRouter?.getLocalRoomUserIds(namespace, room) ?? Promise.resolve([])

getLocalRoomsWithPrefix(namespace: string, prefix: string): Promise<string[]> {
return (
this._socketRouter?.getLocalRoomsWithPrefix(namespace, prefix) ??
Split validateEventRelayInput into per-field parsers to reduce complexity.
Silence unused-parameter lint in EventBus test FakeRedis stub.
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.

3 participants