Skip to content
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

Merged
merged 3 commits into from
Jan 15, 2018

Conversation

yush1ga
Copy link
Contributor

@yush1ga yush1ga commented Nov 10, 2017

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

  • Added subscription_auth_mode to namespace policy.
  • When subscription_auth_mode is Prefix, 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.

@yush1ga yush1ga self-assigned this Nov 10, 2017
@yush1ga yush1ga added this to the 1.22.0-incubating milestone Nov 10, 2017
@yush1ga yush1ga added the type/feature The PR added a new feature or issue requested a new feature label Nov 16, 2017
@yush1ga yush1ga force-pushed the subscription-acl branch 3 times, most recently from d69efdf to cf2d669 Compare December 19, 2017 01:03
@yush1ga yush1ga force-pushed the subscription-acl branch 2 times, most recently from 5788c78 to 3668902 Compare January 9, 2018 05:33
@yush1ga yush1ga requested a review from nkurihar January 9, 2018 05:41
case Prefix:
if (!subscription.startsWith(role)) {
permissionFuture.complete(false);
return;
Copy link
Contributor

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;

Copy link
Contributor Author

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.

Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I got it, thanks.

@nkurihar
Copy link
Contributor

nkurihar commented Jan 9, 2018

LGTM 👍

Copy link
Contributor

@merlimat merlimat left a 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);
Copy link
Contributor

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.

Copy link
Contributor

@saandrews saandrews left a 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?

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));
Copy link
Contributor

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?

@yush1ga
Copy link
Contributor Author

yush1ga commented Jan 12, 2018

@saandrews @merlimat
Thank you for comments.
I fixed things mentioned above.

Copy link
Contributor

@massakam massakam left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

LGTM

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
type/feature The PR added a new feature or issue requested a new feature
Projects
None yet
Development

Successfully merging this pull request may close these issues.

None yet

5 participants