Add this suggestion to a batch that can be applied as a single commit.
This suggestion is invalid because no changes were made to the code.
Suggestions cannot be applied while the pull request is closed.
Suggestions cannot be applied while viewing a subset of changes.
Only one suggestion per line can be applied in a batch.
Add this suggestion to a batch that can be applied as a single commit.
Applying suggestions on deleted lines is not supported.
You must change the existing code in this line in order to create a valid suggestion.
Outdated suggestions cannot be applied.
This suggestion has been applied or marked resolved.
Suggestions cannot be applied from pending reviews.
Suggestions cannot be applied on multi-line comments.
Suggestions cannot be applied while the pull request is queued to merge.
Suggestion cannot be applied right now. Please check back later.
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
ADR-32: Logical permissions #145
base: main
Are you sure you want to change the base?
ADR-32: Logical permissions #145
Changes from all commits
6a3ec84
878189e
File filter
Filter by extension
Conversations
Jump to
There are no files selected for viewing
Logical User Permissions
Proposed
Context and Problem Statement
The crux of a permission is whether a user can publish or subscribe to a subject. This is an appropriate basis for user permissions since every allow/deny can be expressed using a subject. Prior to JetStream, this model was sufficient since there were no abstractions of subjects other than
_INBOX.>
for the request-reply implementation. Theallow_responses
permission was introduced to address the generalization of a reply with the introduction of custom inbox prefixes. It would impractible to know and list the inboxes ahead of time.The introduction of JetStream brought an API which provides the ability to manage and interact with streams and consumers. This API was intended to be internal given the design of the subjects. Client libraries have implemented constructs over top the raw API calls. However, the these higher level constructs never manifested as user permissions.
The concern is that developers need to model permissions based on the internal JS subjects which is both difficult, but also introduces coupling between the developer's application-level need and the API design.
[Context | References | Prior Work]
Permissions are defined for publish or subscribe and list a set of subjects (including wildcards). As noted above,
allow_responses
is an abstraction to handle the "reply to any inbox" situation.With the introduction of JetStream, APIs such as
add-stream
,delete-stream
, etc. were introduced. These reduce down to (mostly) a set of request-reply interactions. For example, to create a stream, a request must be made to$JS.API.STREAM.CREATE.<name>
where<name>
is the named of the stream. To get consumer info a request to$JS.API.CONSUMER.INFO.<stream>.<name>
must be allowed.The question is, why does a developer need to know about these verbose subjects when defining permissions?
Design
Fundamentally, this design is a light abstraction on top of the current way permissions are defined in configuration or JWTs. These new constructs can be converted to a standard permissions map internally.
There are two potential layers to defining user permissions. First, a logical name must be defined for the underlying API subject. This mapping is shown in the table below. In addition to the name, the context (publish or subscribe) can also be inferred. For example, all of the JS APIs use request-reply initiated by the client. So
js-create-stream
is implicitly a publish-based permission. For subjects that are parameterized based on stream names, consumer names, or subjects, the(...)
syntax is used to support specifying these parameters.pub(subject)
{subject}
sub(subject)
{subject}
inbox
_INBOX.>
inbox(id)
_INBOX_{id}.>
--inbox-prefix
for private access.js-all
$JS.API.>
js-info
$JS.API.INFO
js-create-stream
$JS.API.STREAM.CREATE.*
js-create-stream(name)
$JS.API.STREAM.CREATE.{name}
js-update-stream
$JS.API.STREAM.UPDATE.*
js-update-stream(name)
$JS.API.STREAM.UPDATE.{name}
js-delete-stream
$JS.API.STREAM.DELETE.*
js-delete-stream(name)
$JS.API.STREAM.DELETE.{name}
js-purge-stream
$JS.API.STREAM.PURGE.*
js-purge-stream(name)
$JS.API.STREAM.PURGE.{name}
js-snapshot-stream
$JS.API.STREAM.SNAPSHOT.*
js-snapshot-stream(name)
$JS.API.STREAM.SNAPSHOT.{name}
js-snapshot-stream-ack
$JS.API.SNAPSHOT.ACK.*.>
js-snapshot-stream-ack(name)
$JS.API.SNAPSHOT.ACK.{name}.>
js-restore-stream
$JS.API.STREAM.RESTORE.*
js-restore-stream(name)
$JS.API.STREAM.RESTORE.{name}
js-snapshot-restore
$JS.API.SNAPSHOT.RESTORE.*.>
js-snapshot-restore(name)
$JS.API.SNAPSHOT.RESTORE.{name}.>
js-stream-names
$JS.API.STREAM.NAMES
js-stream-list
$JS.API.STREAM.LIST
js-stream-info
$JS.API.STREAM.INFO.*
js-stream-info(name)
$JS.API.STREAM.INFO.{name}
js-stream-delete-msg
$JS.API.STREAM.MSG.DELETE.*
js-stream-delete-msg(name)
$JS.API.STREAM.MSG.DELETE.{name}
js-stream-get-msg
$JS.API.DIRECT.GET.*
js-stream-get-msg(name)
$JS.API.DIRECT.GET.{name}
js-stream-get-last-subject-msg
$JS.API.DIRECT.GET.*.>
js-stream-get-last-subject-msg(stream)
$JS.API.DIRECT.GET.{stream}.>
js-stream-get-last-subject-msg(stream, subject)
$JS.API.DIRECT.GET.{stream}.{subject}
js-stream-get-last-subject-msg(*, subject)
$JS.API.DIRECT.GET.*.{subject}
js-create-ephemeral-consumer
$JS.API.CONSUMER.CREATE.*
js-create-ephemeral-consumer(stream)
$JS.API.CONSUMER.CREATE.{stream}
js-create-durable-consumer
$JS.API.CONSUMER.DURABLE.CREATE.*.*
js-create-durable-consumer(stream)
$JS.API.CONSUMER.DURABLE.CREATE.{stream}.*
js-create-durable-consumer(stream, name)
$JS.API.CONSUMER.DURABLE.CREATE.{stream}.{name}
js-create-durable-consumer(*, name)
$JS.API.CONSUMER.DURABLE.CREATE.*.{name}
js-delete-consumer
$JS.API.CONSUMER.DELETE.*.*
js-delete-consumer(stream)
$JS.API.CONSUMER.DELETE.{stream}.*
js-delete-consumer(stream, name)
$JS.API.CONSUMER.DELETE.{stream}.{name}
js-delete-consumer(*, name)
$JS.API.CONSUMER.DELETE.*.{name}
js-consumer-names
$JS.API.CONSUMER.NAMES.*
js-consumer-names(stream)
$JS.API.CONSUMER.NAMES.{stream}
js-consumer-list
$JS.API.CONSUMER.LIST.*
js-consumer-list(stream)
$JS.API.CONSUMER.LIST.{stream}
js-consumer-info
$JS.API.CONSUMER.INFO.*.*
js-consumer-info(stream)
$JS.API.CONSUMER.INFO.{stream}.*
js-consumer-info(stream, name)
$JS.API.CONSUMER.INFO.{stream}.{name}
js-consumer-info(*, name)
$JS.API.CONSUMER.INFO.*.{name}
js-consumer-next-msg
$JS.API.CONSUMER.MSG.NEXT.*.*
js-consumer-next-msg(stream)
$JS.API.CONSUMER.MSG.NEXT.{stream}.*
js-consumer-next-msg(stream, name)
$JS.API.CONSUMER.MSG.NEXT.{stream}.{name}
js-consumer-next-msg(*, name)
$JS.API.CONSUMER.MSG.NEXT.*.{name}
js-consumer-ack-reply
$JS.ACK.*.*.>
js-consumer-ack-reply(stream)
$JS.ACK.{stream}.*.>
js-consumer-ack-reply(stream, name)
$JS.ACK.{stream}.{name}.>
js-consumer-ack-reply(*, name)
$JS.ACK.*.{name}.>
kv-put
$KV.*.>
kv-put(bucket)
$KV.{bucket}.>
kv-put(bucket, key)
$KV.{bucket}.{key}
TODO: add remaining subjects, leader, peer, advisories, etc.
The second logical tier can be permission groups, often designed as roles, such as
js-stream-operator
. Parameters, such as stream or consumer names, will be transitively applied to the underlying permissions. The goal of roles is to abstract away a set of permissions for common use cases.This table shows a few examples.
js-stream-operator
js-create-stream
,js-update-stream
,js-delete-stream
js-purge-stream
,js-stream-info
,js-snapshot-stream
,js-restore-stream
js-stream-operator(name)
js-create-stream(name)
,js-update-stream(name)
, etc...js-stream-user(stream, subject)
publish(subject)
,js-stream-info(stream)
,js-stream-get-last-subject-msg(stream, subject)
publish(subject)
is alternative to independently setting a pub-allow.The best way to model this in configuration is TBD, however, one approach could support
allow
anddeny
as top-level keys in thepermissions
map which would be used exclusively with these new logical permissions.For example:
Decision
[Maybe this was just an architectural decision...]
TODO
Consequences
[Any consequences of this design, such as breaking change or Vorpal Bunnies]
TODO
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Maybe also need to cover how this maps to the imports and export syntax while we are at it, sub represent either a
stream
orservice
.Like being able to define that reading info about consumer and streams is ok from the other account but not ok to create, something like:
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Indeed. Fundamentally, these permissions can be thought of as functions that expand to one or more subjects
js-stream-info(EVENTS)
→$JS.API.STREAM.INFO.EVENTS
. I thought about having these permissions able to be intermingled with standard subjects. If that is the case, the ambiguity of subject vs perm needs to be removed, so some kind of prefix character could help differentiate, such as@
or whatever.Then you could have something like:
The implicit pub/sub information would really only apply in the user permissions context.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
this syntax is nice, I was thinking of granular permission like below but seems very verbose:
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
I like the structure that your example provides which provides namespacing (as I am doing
js-
andkv-
). A future state I considered was user-defined permissions which may break the structure. For example, if a new key calledroles
within an account is defined, you could declare new mappings off the primitive logical permissions the NATS server provides.There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
It should be possible to subset keys/object names on kv/object store - currently object store doesn't expose data chunks in a way that can be clamped.