Skip to content

Conversation

@zymap
Copy link
Member

@zymap zymap commented Sep 10, 2019

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

@zymap zymap requested a review from sijie September 10, 2019 08:44
@zymap zymap added this to the 0.0.1 milestone Sep 10, 2019
@zymap zymap self-assigned this Sep 10, 2019
Copy link
Member

@sijie sijie left a 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()
Copy link
Member

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.

Copy link
Member Author

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?

Copy link
Member

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.

Copy link
Member Author

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?

Copy link
Member

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())
Copy link
Member

Choose a reason for hiding this comment

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

Suggested change
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())

Copy link
Member Author

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.

Copy link
Member

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.

Copy link
Member Author

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{
Copy link
Member

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 functions permissions for a topic.
  • if broker doesn't prevent, we should add a logic to reject granting functions permissions for a topic. please create a Pulsar issue to track adding the logic.

Copy link
Member Author

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?

Copy link
Member

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.

@zymap
Copy link
Member Author

zymap commented Sep 11, 2019

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.

@sijie Good idea. I will add a new command group.

@sijie sijie mentioned this pull request Sep 18, 2019
29 tasks
@zymap
Copy link
Member Author

zymap commented Sep 19, 2019

@sijie PTAL

@zymap zymap changed the base branch from topic-partitioned-commands to master September 19, 2019 11:35
@zymap
Copy link
Member Author

zymap commented Sep 19, 2019

@sijie PTAL. Thanks.

@sijie sijie merged commit 58d9832 into master Sep 19, 2019
@sijie sijie deleted the topic-permission branch September 19, 2019 15:34
tisonkun pushed a commit to tisonkun/pulsar-client-go that referenced this pull request Aug 15, 2023
## 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
```
tisonkun pushed a commit to apache/pulsar-client-go that referenced this pull request Aug 16, 2023
## 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
```
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Projects

None yet

Development

Successfully merging this pull request may close these issues.

3 participants