go-sse icon indicating copy to clipboard operation
go-sse copied to clipboard

Conditional publish based on user permissions

Open NathanBaulch opened this issue 6 months ago • 1 comments

I'm enjoying this library and impressed by your responsiveness to people's issues!

One problem I'm having is I need to filter events per session based on authorization rules in my security layer. I have a single SSE endpoint that thousands of users connect to, each with unique permissions that influence the events they receive.

I thought about using a custom MessageWriter wrapper which might work, but the concrete Message struct is highly optimized for streaming and I'd rather not have to unmarshal the message data for every connected client on the way out.

I also thought about partitioning my users into separate topics but my permissions are too fine-grained to make this feasible.

Couple of ideas off the top of my head:

  1. Make Message an interface so I can attach arbitrary metadata
  2. Add a public map[string]any field to Message
  3. Pass context.Context to MessageWriter.Send so I can grab metadata from that
  4. Introduce first-class middleware support
  5. Tease apart the pub/sub and wire-format responsibilities - looks like this is already on your radar

Cheers!

NathanBaulch avatar Aug 20 '24 05:08 NathanBaulch