-
Notifications
You must be signed in to change notification settings - Fork 3.6k
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
Add subscription auth mode by prefix #899
Conversation
3d06de6
to
6924b86
Compare
d69efdf
to
cf2d669
Compare
5788c78
to
3668902
Compare
case Prefix: | ||
if (!subscription.startsWith(role)) { | ||
permissionFuture.complete(false); | ||
return; |
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.
Should we return permissionFuture
here?
return permissionFuture;
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 return
is for lambda of line 88 and it need not return any values.
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 got it, thanks.
LGTM 👍 |
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.
Change looks good, just make sure the reason for rejection is immediately clear for the user.
switch (policies.get().subscription_auth_mode) { | ||
case Prefix: | ||
if (!subscription.startsWith(role)) { | ||
permissionFuture.complete(false); |
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 think it's important to bubble back to user the exact reason for the consumer creation to fail. E.g.: In the exception thrown, it should include something like:
Failed to create consumer - The subscription name needs to be prefixed by the authentication role, like MY-ROLE-xxxx
Including the actual role used by the consumer.
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.
Changes looks good. Can you add unit test to cover success/failure case when prefix is enabled?
3668902
to
b1ba82b
Compare
case Prefix: | ||
if (!subscription.startsWith(role)) { | ||
PulsarServerException ex = new PulsarServerException( | ||
String.format("Failed to create consumer - The subscription name needs to be prefixed by the authentication role, like %s-xxxx", role)); |
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.
Can you add the destination info in the message?
b1ba82b
to
acb351f
Compare
acb351f
to
35c3198
Compare
@saandrews @merlimat |
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.
LGTM
Motivation
#893
In our use case, there are cases that one tenant's producer wants to send messages to the other tenants' consumers.
In such a case, some consumers use very simple subscription name like "sub", "sub1" or "subscription_prod" and these are conflicted.
Modifications
subscription_auth_mode
to namespace policy.subscription_auth_mode
isPrefix
, a client have to use subscription name including role name prefix like${AuthRroleName}-foobar
.Result
Since a client is forced to use role-prefixed subscription name, conflicts of subscription name can be avoided.
I'm going to create test and documentation for this and send another PR.