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 QueueSubscribe permissions #1143

Merged
merged 2 commits into from Sep 27, 2019
Merged

Add QueueSubscribe permissions #1143

merged 2 commits into from Sep 27, 2019

Conversation

wallyqs
Copy link
Member

@wallyqs wallyqs commented Sep 26, 2019

Adds support for permissions for queue subscriptions. For example:

users = [
  {
    user: "foo", permissions: {
      sub: {
        # Allow plain subscription foo, but only v1 groups or *.dev queue groups
        allow: ["foo", "foo v1", "foo v1.>", "foo *.dev"]

        # Prevent queue subscriptions on prod groups
        deny: ["> *.prod"]
     }
  }
]

Signed-off-by: Jaime Piña jaime@synadia.com
Signed-off-by: Waldemar Quevedo wally@synadia.com

Copy link
Member

@derekcollison derekcollison left a comment

Choose a reason for hiding this comment

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

Looking pretty good.

server/client.go Outdated
n := len(vals)
if n == 1 {
s = vals[0]
} else if n >= 2 {
Copy link
Member

Choose a reason for hiding this comment

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

Will we catch "foo bar baz" as an error or just silently do "foo bar" essentially?

Copy link
Member

Choose a reason for hiding this comment

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

We should catch the error earlier in config parsing and options validation I guess.

Copy link
Member Author

Choose a reason for hiding this comment

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

Yes we should change to catch these errors earlier now...

Copy link
Contributor

Choose a reason for hiding this comment

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

I made the split function return an error. In setPermissions we handle it by logging and dropping that permission.

This would be in addition to handling it in the config parsing and the JWT code.

d4d71e9

server/client.go Outdated Show resolved Hide resolved
server/client.go Outdated Show resolved Hide resolved
server/client.go Outdated Show resolved Hide resolved
server/client.go Show resolved Hide resolved
server/client.go Outdated Show resolved Hide resolved
server/client.go Outdated Show resolved Hide resolved
server/client.go Outdated Show resolved Hide resolved
server/client.go Outdated Show resolved Hide resolved
server/client.go Outdated
n := len(vals)
if n == 1 {
s = vals[0]
} else if n >= 2 {
Copy link
Member

Choose a reason for hiding this comment

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

We should catch the error earlier in config parsing and options validation I guess.

server/client.go Outdated Show resolved Hide resolved
server/client.go Show resolved Hide resolved
server/client.go Outdated Show resolved Hide resolved
@variadico variadico force-pushed the q-sub-perms branch 2 times, most recently from 55d7b4d to ca9ab51 Compare September 27, 2019 00:49
Copy link
Member

@derekcollison derekcollison left a comment

Choose a reason for hiding this comment

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

Also would squash into one commit.

server/client.go Outdated Show resolved Hide resolved
server/client.go Outdated Show resolved Hide resolved
server/client.go Outdated Show resolved Hide resolved
Copy link
Member

@derekcollison derekcollison left a comment

Choose a reason for hiding this comment

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

Very close!

server/client.go Show resolved Hide resolved
server/client.go Outdated Show resolved Hide resolved
server/client.go Outdated Show resolved Hide resolved
server/client.go Outdated Show resolved Hide resolved
server/client.go Outdated Show resolved Hide resolved
server/client.go Show resolved Hide resolved
@variadico variadico force-pushed the q-sub-perms branch 2 times, most recently from f7c17ed to 03bc296 Compare September 27, 2019 02:52
Copy link
Member

@kozlovic kozlovic left a comment

Choose a reason for hiding this comment

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

I would like to see a test with mix of plain subs and queue subs. The one you added is good but exercise only the presence of a queue sub,

server/client.go Outdated Show resolved Hide resolved
})
}
}

Copy link
Member

Choose a reason for hiding this comment

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

I think we need to add a test (simpler I think that adding to existing test) where you have a the presence of a regular sub and try to queue subscribe. We want to check the conditions where say plain sub is allowed, but you try to queue subscribe with a queue name that is not in the list (or there is no queue name in the list), etc...

Copy link
Contributor

Choose a reason for hiding this comment

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

I appended two more cases to our list. Does this cover what you were thinking?

{
	name:    "plain sub is allowed, but queue subscribe with queue not in list",
	perms:   &SubjectPermission{Allow: []string{"foo bar"}},
	subject: "foo",
	queue:   "fizz",
	want:    "-ERR 'Permissions Violation for Subscription to \"foo\" using queue \"fizz\"'\r\n",
},
{
	name:    "allow plain sub, but do queue subscribe",
	perms:   &SubjectPermission{Allow: []string{"foo"}},
	subject: "foo",
	queue:   "bar",
	want:    "+OK\r\n",
},

Copy link
Member

Choose a reason for hiding this comment

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

Since you create only a queue sub, the last test should expect an error, no?

Copy link
Member

Choose a reason for hiding this comment

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

Oh, I take that back. As long as no queue name is specified, it means that all queues are allowed.

```
users = [
  {
    user: "foo", permissions: {
      sub: {
        # Allow plain subscription foo, but only v1 groups or *.dev queue groups
        allow: ["foo", "foo v1", "foo v1.>", "foo *.dev"]

        # Prevent queue subscriptions on prod groups
        deny: ["> *.prod"]
     }
  }
]
```

Signed-off-by: Jaime Piña <jaime@synadia.com>
Signed-off-by: Waldemar Quevedo <wally@synadia.com>
Copy link
Member

@kozlovic kozlovic left a comment

Choose a reason for hiding this comment

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

Last comment from me about the canQueueSubscribe() tests? I just want to know if I understand correctly.

server/client.go Outdated Show resolved Hide resolved
server/client.go Outdated Show resolved Hide resolved
Copy link
Member

@kozlovic kozlovic left a comment

Choose a reason for hiding this comment

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

LGTM!

@kozlovic kozlovic merged commit 4a9040e into master Sep 27, 2019
@kozlovic kozlovic deleted the q-sub-perms branch September 27, 2019 23:46
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

Successfully merging this pull request may close these issues.

None yet

5 participants