-
Notifications
You must be signed in to change notification settings - Fork 70
Add topic permissions commands #48
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
Conversation
9cd82c0 to
bc433fd
Compare
sijie
left a comment
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.
after thinking a bit more, the permissions related operations are spreading over multiple places. we should revisit it overall.
one solution is to move 'permissions' as the topic level command group. so the commands will be:
pulsarctl permissions grant --roles <roles> --actions <actions> <entity>pulsarctl permissions revoke --roles <roles> --actions <actions> <entity>pulsarctl permissions get <entity>.
pulsarctl should determine what entities (a namespace, a topic or a function) the operations apply to.
for example, tenant/ns is a namespace name. tenant/ns/topic is a topic name or a function name.
| return err | ||
| } | ||
|
|
||
| admin := cmdutils.NewPulsarClient() |
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.
how do we close admin? If we don't close admin, it might be worth fixing this problem in a subsequent pull request.
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.
Why do we need to close admin?
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.
why don't we need to close admin? releasing/closing a resource is always be the right practice to follow.
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 wonder is there has any resource we always keep with admin?
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.
isn't PulsarAdmin client a network client? If it is a network client, doesn't it keep any network related resources?
| args := []string{"get-permissions"} | ||
| _, _, nameErr, _ := TestTopicCommands(GetPermissionsCmd, args) | ||
| assert.NotNil(t, nameErr) | ||
| assert.Equal(t, "only one argument is allowed to be used as a name", nameErr.Error()) |
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.
| assert.Equal(t, "only one argument is allowed to be used as a name", nameErr.Error()) | |
| assert.Equal(t, "only one argument is allowed to be used as a topic name", nameErr.Error()) |
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's a common output for all commands which need one argument. The description will show which arg types the command needed.
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.
The error message is too generic. Users won’t be able to know what is the exact error. So you need to customize the error message for different commands.
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.
Okay. So maybe we can use a separate pull request to do this. It will modify all commands who use GetNameArg to ensure there is only one name argument.
| Out: "Invalid role name", | ||
| } | ||
|
|
||
| actionsError := Output{ |
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 seems to me that this is a topic level permissions. I don't think it should accept functions permissions.
- we should prevent people from granting
functionspermissions for a topic. - if broker doesn't prevent, we should add a logic to reject granting
functionspermissions for a topic. please create a Pulsar issue to track adding the logic.
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.
So who will grant functions permission?
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.
functions permission is only applied to namespace level.
@sijie Good idea. I will add a new command group. |
|
@sijie PTAL |
|
@sijie PTAL. Thanks. |
## OUTPUT
*get-permissions`*
```
➜ pulsarctl git:(topic-permission) ./pulsarctl topic get-permissions -h
USED FOR:
This command is used for getting the permissions on a topic.
REQUIRED PERMISSION:
This command requires namespace admin permissions.
EXAMPLES:
#Get the permissions on a topic <topic-name>
pulsarctl topic get-permissions <topic-name>
OUTPUT:
#normal output
{
"<role>": [
"<action>"
]
}
#the topic name is not specified
[✖] only one argument is allowed to be used as a name
#the topic name is not in the format of <tenant>/<namespace>/<topic> or <topic>
[✖] Invalid short topic name '<topic-name>', it should be in the format of <tenant>/<namespace>/<topic> or <topic>
#the topic name is not in the format of <domain>://<tenant>/<namespace>/<topic>
[✖] Invalid complete topic name '<topic-name>', it should be in the format of <domain>://<tenant>/<namespace>/<topic>
#the topic name is not in the format of <tenant>/<namespace>/<topic>
[✖] Invalid topic name '<topic-name>', it should be in the format of<tenant>/<namespace>/<topic>
#the namespace name is not in the format of <tenant>/<namespace>
[✖] The complete name of namespace is invalid. complete name : <namespace-complete-name>
#the tenant name and(or) namespace name is empty
[✖] Invalid tenant or namespace. [<tenant>/<namespace>]
#the tenant name contains unsupported special chars. the alphanumeric (a-zA-Z0-9) and the special chars (-=:.%) is allowed
[✖] Tenant name include unsupported special chars. tenant : [<namespace>]
#the namespace name contains unsupported special chars. the alphanumeric (a-zA-Z0-9) and the special chars (-=:.%) is allowed
[✖] Namespace name include unsupported special chars. namespace : [<namespace>]
Usage: pulsarctl topics get-permissions [flags]
Aliases: get-permissions, get
```
*grant-permissions*
```
➜ pulsarctl git:(topic-permission) ./pulsarctl topic grant-permissions -h
USED FOR:
This command is used for granting permissions to a client role on a single topic.
REQUIRED PERMISSION:
This command requires namespace admin permissions.
EXAMPLES:
#Grant permissions to a client on a single topic <topic-name>
pulsarctl topic grant-permissions --role <role> --actions <action-1> --actions <action-2> <topic-name>
OUTPUT:
#normal output
Grant role %s and actions %v to the topic %s successfully
#the topic name is not specified
[✖] only one argument is allowed to be used as a name
#the specified role is empty
Invalid role name
#the specified actions is not allowed.
The auth action only can be specified as 'produce', 'consume', or 'functions'. Invalid auth action '<actions>'
#the topic name is not in the format of <tenant>/<namespace>/<topic> or <topic>
[✖] Invalid short topic name '<topic-name>', it should be in the format of <tenant>/<namespace>/<topic> or <topic>
#the topic name is not in the format of <domain>://<tenant>/<namespace>/<topic>
[✖] Invalid complete topic name '<topic-name>', it should be in the format of <domain>://<tenant>/<namespace>/<topic>
#the topic name is not in the format of <tenant>/<namespace>/<topic>
[✖] Invalid topic name '<topic-name>', it should be in the format of<tenant>/<namespace>/<topic>
#the namespace name is not in the format of <tenant>/<namespace>
[✖] The complete name of namespace is invalid. complete name : <namespace-complete-name>
#the tenant name and(or) namespace name is empty
[✖] Invalid tenant or namespace. [<tenant>/<namespace>]
#the tenant name contains unsupported special chars. the alphanumeric (a-zA-Z0-9) and the special chars (-=:.%) is allowed
[✖] Tenant name include unsupported special chars. tenant : [<namespace>]
#the namespace name contains unsupported special chars. the alphanumeric (a-zA-Z0-9) and the special chars (-=:.%) is allowed
[✖] Namespace name include unsupported special chars. namespace : [<namespace>]
Usage: pulsarctl topics grant-permissions [flags]
Aliases: grant-permissions, grant
```
*revoke-permissions*
```
➜ pulsarctl git:(topic-permission) ./pulsarctl topic revoke-permissions -h
USED FOR:
This command is used for revoking permissions on a topic.
REQUIRED PERMISSION:
This command requires namespace admin permissions.
EXAMPLES:
OUTPUT:
#normal output
Revoke permissions for the role <role> to the topic <topic-name> successfully
#the specified role is empty
Invalid role name
#the topic name is not specified
[✖] only one argument is allowed to be used as a name
#the topic name is not in the format of <tenant>/<namespace>/<topic> or <topic>
[✖] Invalid short topic name '<topic-name>', it should be in the format of <tenant>/<namespace>/<topic> or <topic>
#the topic name is not in the format of <domain>://<tenant>/<namespace>/<topic>
[✖] Invalid complete topic name '<topic-name>', it should be in the format of <domain>://<tenant>/<namespace>/<topic>
#the topic name is not in the format of <tenant>/<namespace>/<topic>
[✖] Invalid topic name '<topic-name>', it should be in the format of<tenant>/<namespace>/<topic>
#the namespace name is not in the format of <tenant>/<namespace>
[✖] The complete name of namespace is invalid. complete name : <namespace-complete-name>
#the tenant name and(or) namespace name is empty
[✖] Invalid tenant or namespace. [<tenant>/<namespace>]
#the tenant name contains unsupported special chars. the alphanumeric (a-zA-Z0-9) and the special chars (-=:.%) is allowed
[✖] Tenant name include unsupported special chars. tenant : [<namespace>]
#the namespace name contains unsupported special chars. the alphanumeric (a-zA-Z0-9) and the special chars (-=:.%) is allowed
[✖] Namespace name include unsupported special chars. namespace : [<namespace>]
Usage: pulsarctl topics revoke-permissions [flags]
Aliases: revoke-permissions, revoke
```
## OUTPUT
*get-permissions`*
```
➜ pulsarctl git:(topic-permission) ./pulsarctl topic get-permissions -h
USED FOR:
This command is used for getting the permissions on a topic.
REQUIRED PERMISSION:
This command requires namespace admin permissions.
EXAMPLES:
#Get the permissions on a topic <topic-name>
pulsarctl topic get-permissions <topic-name>
OUTPUT:
#normal output
{
"<role>": [
"<action>"
]
}
#the topic name is not specified
[✖] only one argument is allowed to be used as a name
#the topic name is not in the format of <tenant>/<namespace>/<topic> or <topic>
[✖] Invalid short topic name '<topic-name>', it should be in the format of <tenant>/<namespace>/<topic> or <topic>
#the topic name is not in the format of <domain>://<tenant>/<namespace>/<topic>
[✖] Invalid complete topic name '<topic-name>', it should be in the format of <domain>://<tenant>/<namespace>/<topic>
#the topic name is not in the format of <tenant>/<namespace>/<topic>
[✖] Invalid topic name '<topic-name>', it should be in the format of<tenant>/<namespace>/<topic>
#the namespace name is not in the format of <tenant>/<namespace>
[✖] The complete name of namespace is invalid. complete name : <namespace-complete-name>
#the tenant name and(or) namespace name is empty
[✖] Invalid tenant or namespace. [<tenant>/<namespace>]
#the tenant name contains unsupported special chars. the alphanumeric (a-zA-Z0-9) and the special chars (-=:.%) is allowed
[✖] Tenant name include unsupported special chars. tenant : [<namespace>]
#the namespace name contains unsupported special chars. the alphanumeric (a-zA-Z0-9) and the special chars (-=:.%) is allowed
[✖] Namespace name include unsupported special chars. namespace : [<namespace>]
Usage: pulsarctl topics get-permissions [flags]
Aliases: get-permissions, get
```
*grant-permissions*
```
➜ pulsarctl git:(topic-permission) ./pulsarctl topic grant-permissions -h
USED FOR:
This command is used for granting permissions to a client role on a single topic.
REQUIRED PERMISSION:
This command requires namespace admin permissions.
EXAMPLES:
#Grant permissions to a client on a single topic <topic-name>
pulsarctl topic grant-permissions --role <role> --actions <action-1> --actions <action-2> <topic-name>
OUTPUT:
#normal output
Grant role %s and actions %v to the topic %s successfully
#the topic name is not specified
[✖] only one argument is allowed to be used as a name
#the specified role is empty
Invalid role name
#the specified actions is not allowed.
The auth action only can be specified as 'produce', 'consume', or 'functions'. Invalid auth action '<actions>'
#the topic name is not in the format of <tenant>/<namespace>/<topic> or <topic>
[✖] Invalid short topic name '<topic-name>', it should be in the format of <tenant>/<namespace>/<topic> or <topic>
#the topic name is not in the format of <domain>://<tenant>/<namespace>/<topic>
[✖] Invalid complete topic name '<topic-name>', it should be in the format of <domain>://<tenant>/<namespace>/<topic>
#the topic name is not in the format of <tenant>/<namespace>/<topic>
[✖] Invalid topic name '<topic-name>', it should be in the format of<tenant>/<namespace>/<topic>
#the namespace name is not in the format of <tenant>/<namespace>
[✖] The complete name of namespace is invalid. complete name : <namespace-complete-name>
#the tenant name and(or) namespace name is empty
[✖] Invalid tenant or namespace. [<tenant>/<namespace>]
#the tenant name contains unsupported special chars. the alphanumeric (a-zA-Z0-9) and the special chars (-=:.%) is allowed
[✖] Tenant name include unsupported special chars. tenant : [<namespace>]
#the namespace name contains unsupported special chars. the alphanumeric (a-zA-Z0-9) and the special chars (-=:.%) is allowed
[✖] Namespace name include unsupported special chars. namespace : [<namespace>]
Usage: pulsarctl topics grant-permissions [flags]
Aliases: grant-permissions, grant
```
*revoke-permissions*
```
➜ pulsarctl git:(topic-permission) ./pulsarctl topic revoke-permissions -h
USED FOR:
This command is used for revoking permissions on a topic.
REQUIRED PERMISSION:
This command requires namespace admin permissions.
EXAMPLES:
OUTPUT:
#normal output
Revoke permissions for the role <role> to the topic <topic-name> successfully
#the specified role is empty
Invalid role name
#the topic name is not specified
[✖] only one argument is allowed to be used as a name
#the topic name is not in the format of <tenant>/<namespace>/<topic> or <topic>
[✖] Invalid short topic name '<topic-name>', it should be in the format of <tenant>/<namespace>/<topic> or <topic>
#the topic name is not in the format of <domain>://<tenant>/<namespace>/<topic>
[✖] Invalid complete topic name '<topic-name>', it should be in the format of <domain>://<tenant>/<namespace>/<topic>
#the topic name is not in the format of <tenant>/<namespace>/<topic>
[✖] Invalid topic name '<topic-name>', it should be in the format of<tenant>/<namespace>/<topic>
#the namespace name is not in the format of <tenant>/<namespace>
[✖] The complete name of namespace is invalid. complete name : <namespace-complete-name>
#the tenant name and(or) namespace name is empty
[✖] Invalid tenant or namespace. [<tenant>/<namespace>]
#the tenant name contains unsupported special chars. the alphanumeric (a-zA-Z0-9) and the special chars (-=:.%) is allowed
[✖] Tenant name include unsupported special chars. tenant : [<namespace>]
#the namespace name contains unsupported special chars. the alphanumeric (a-zA-Z0-9) and the special chars (-=:.%) is allowed
[✖] Namespace name include unsupported special chars. namespace : [<namespace>]
Usage: pulsarctl topics revoke-permissions [flags]
Aliases: revoke-permissions, revoke
```
OUTPUT
get-permissions`
grant-permissions
revoke-permissions