Repository navigation
I can't figure out how to prevent clients writing into streams it has no permissions for inside an account #8924
For the live of me I cannot work out how to give a client read-only access to its own stream through a pull consumer. Every permission set I tried also lets that client write into the other streams of the account. Why would I want to let random strangers on the public internet share the same NATS account? Why can't I just give them a push consumer and be done with it? I was hoping I could make a small data feed web app, while avoiding a nanny state situation (where everyone else has to deal with a shitty pagination over HTTP aislop implementation) by giving everyone direct access to their NATS stream so they could play around with a nats CLI, make their own clients, replay past events for troubleshooting, etc... I've even tried a stream per client. No luck: I'm using what #8805 recommends: A direct write is refused, as expected: But bob can put a message into ALICE_EVENTS regardless by naming alice's subject as his reply subject on a request to his own consumer: I did confirm which permissions I can get workingSo the direct publish, wildcard replies, and the create-subject-vs-body Does a stream per user help? **Nope**ALICE_EVENTS and BOB_EVENTS are separate streams, and bob has no permissions for ALICE_EVENTS or Tried the other two grants on their own.
A client with no publish permission at all is fully contained, but then it Is this just a limitation of the security model? I've seen fixes recently go out to block one client from deleting other clients streams. And preventing reads from other streams. It's fine if the answer is the only security boundary is the account and every client sharing an account needs to completely trust all other clients in the same account. |
Replies: 2 comments
|
This is a real limitation of the current permission model: the reply subject on a request is chosen by the requester, and a server-generated response to that reply is effectively a publish to an arbitrary subject. Per-client subject permissions can’t fully sandbox request/reply inside one account. The account is the security boundary; clients sharing an account have to trust each other. Options:
Given the current behavior, I would not expose a shared account directly to random internet clients. |
|
You can accomplish what you need via ALLOW permissions, which is harder then we want since you have to explicitly state every subject you want to send or receive from. So in a simple case, let's say we have an EVENT stream with "event.>" as the subject. Giving this subject as an explicit ALLOW will allow a user to place things in the stream. For responses, acks, consumers etc. We will want to use the INBOX prefix setting in the client and list that as explicitly a subject we can subscribe to, e.g. "_INBOX.derek.>". Check the docs or your favorite LLM on setting the INBOX prefix in your desired language. This link can also help: https://natsbyexample.com/examples/auth/private-inbox/cli |
You can accomplish what you need via ALLOW permissions, which is harder then we want since you have to explicitly state every subject you want to send or receive from.
So in a simple case, let's say we have an EVENT stream with "event.>" as the subject. Giving this subject as an explicit ALLOW will allow a user to place things in the stream.
For responses, acks, consumers etc. We will want to use the INBOX prefix setting in the client and list that as explicitly a subject we can subscribe to, e.g. "_INBOX.derek.>". Check the docs or your favorite LLM on setting the INBOX prefix in your desired language. This link can also help: https://natsbyexample.com/examples/auth/private-inbox/cli