feat: open realtime tokens to chat members

The connection-token route is guarded by jz.bm.realtime-access instead
of presentations.realtime-owner: chat-group members get a token, and
when golem15.presentations is active so does everyone its owner guard
lets through (looked up by name among the activated plugins, no import).
Everyone else gets 401, 403 or 503 in the guard's error shape. The
realtime routes mount when golem15.chat or golem15.presentations is
active. /_chat, /_chatchannels and /_chatbots are reserved prefixes of
the student app.
This commit is contained in:
2026-10-26 15:49:29 +01:00
parent cb7ba7ec8a
commit eea171cee6
4 changed files with 131 additions and 17 deletions

View File

@@ -203,23 +203,27 @@ func (p *Plugin) Routes(r pact.Router) error {
// mountRealtime mounts the realtime driver's routes: with the Centrifugo
// driver the connection-token route (user) and the subscribe proxy
// (server-to-server, authenticated by its shared secret). The phone remote
// of golem15.presentations is the only realtime consumer, so nothing is
// mounted without it, and the token route is limited to presentation owners
// by its presentations.realtime-owner guard, named here without importing
// the plugin. Only the token route is throttled, per user. The subscribe
// proxy is called by Centrifugo from 127.0.0.1 for every client, so any
// throttle there would be one shared bucket that a single token holder
// could exhaust and lock the owner out; it relies on its constant-time
// secret check and Centrifugo's own limits instead. Routes built without
// Boot (bare tests) mount nothing; the default null driver declares no
// routes.
// (server-to-server, authenticated by its shared secret). The realtime
// consumers are the BM chat (golem15.chat) and the phone remote of
// golem15.presentations, so nothing is mounted without either, and the
// token route is limited to chat-group members and presentation owners by
// jz.bm.realtime-access, which reaches the presentations guard by name
// without importing the plugin. Only the token route is throttled, per
// user. The subscribe proxy is called by Centrifugo from 127.0.0.1 for
// every client, so any throttle there would be one shared bucket that a
// single token holder could exhaust and lock everyone out; it relies on its
// constant-time secret check and Centrifugo's own limits instead. Routes
// built without Boot (bare tests) mount nothing; the default null driver
// declares no routes.
func (p *Plugin) mountRealtime(r pact.Router) error {
if p.realtime == nil || p.app == nil || !p.app.HasPlugin("golem15.presentations") {
if p.realtime == nil || p.app == nil {
return nil
}
if !p.app.HasPlugin("golem15.chat") && !p.app.HasPlugin("golem15.presentations") {
return nil
}
return lighthouse.Mount(r, p.realtime.Driver(), lighthouse.Surfaces{
UserAuth: surf.Use("jwt.auth", "presentations.realtime-owner", bucketRealtime),
UserAuth: surf.Use("jwt.auth", MiddlewareRealtimeAccess, bucketRealtime),
ServerToServer: surf.Use(),
Middleware: surf.Use(),
})