Skip to content

feat(kafka acl): add grant-admin command#1230

Merged
rkpattnaik780 merged 10 commits intomainfrom
acl_convenience_admin
Oct 28, 2021
Merged

feat(kafka acl): add grant-admin command#1230
rkpattnaik780 merged 10 commits intomainfrom
acl_convenience_admin

Conversation

@rkpattnaik780
Copy link
Contributor

@rkpattnaik780 rkpattnaik780 commented Oct 18, 2021

Add rhoas kafka acl admin command.

Closes #1199

Verification Steps

  1. Run admin command with --user flag set to abc
rhoas kafka acl grant-admin --user abc  
  1. It should create a permission for Kafka Instance with principal=abc and operationType=ALTER

Type of change

  • Bug fix (non-breaking change which fixes an issue)
  • New feature (non-breaking change which adds functionality)
  • Breaking change (fix or feature that would cause existing functionality to not work as expected)
  • Documentation change
  • Other (please specify)

Checklist

  • Documentation added for the feature
  • CI and all relevant tests are passing
  • Code Review completed
  • Verified independently by reviewer

@rkpattnaik780 rkpattnaik780 changed the title Acl convenience admin feat(kafka acl): add admin command Oct 20, 2021
Copy link
Contributor

@craicoverflow craicoverflow left a comment

Choose a reason for hiding this comment

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

Command did not work for me:

❯ ./rhoas kafka acl admin
panic: message "kafka.acl.grantPermissions.error.noPrincipalsSelected" not found in language "en"

goroutine 1 [running]:
github.com/nicksnyder/go-i18n/v2/i18n.(*Localizer).MustLocalize(0xc0001af540, 0xc000133c28, 0x0, 0x0)
        /home/ephelan/.gvm/pkgsets/go1.16.4/global/pkg/mod/github.com/nicksnyder/go-i18n/v2@v2.1.2/i18n/localizer.go:211 +0x7c
github.com/redhat-developer/app-services-cli/pkg/localize/goi18n.(*Goi18n).MustLocalize(0xc00070ccd0, 0x1e4d942, 0x35, 0x0, 0x0, 0x0, 0xc0000ea100, 0xc000133cf8)
        /home/ephelan/code/github.com/redhat-developer/app-services-cli/pkg/localize/goi18n/go_i18n.go:85 +0x165
github.com/redhat-developer/app-services-cli/pkg/localize/goi18n.(*Goi18n).MustLocalizeError(0xc00070ccd0, 0x1e4d942, 0x35, 0x0, 0x0, 0x0, 0xc000133ce0, 0x0)
        /home/ephelan/code/github.com/redhat-developer/app-services-cli/pkg/localize/goi18n/go_i18n.go:111 +0x67
github.com/redhat-developer/app-services-cli/pkg/cmd/kafka/acl/admin.NewAdminACLCommand.func1(0xc0001d3680, 0x2db8c80, 0x0, 0x0, 0x0, 0x0)
        /home/ephelan/code/github.com/redhat-developer/app-services-cli/pkg/cmd/kafka/acl/admin/admin.go:71 +0x18a
github.com/spf13/cobra.(*Command).execute(0xc0001d3680, 0x2db8c80, 0x0, 0x0, 0xc0001d3680, 0x2db8c80)
        /home/ephelan/.gvm/pkgsets/go1.16.4/global/pkg/mod/github.com/spf13/cobra@v1.2.1/command.go:856 +0x472
github.com/spf13/cobra.(*Command).ExecuteC(0xc00032e780, 0x2057538, 0x3, 0xc00032e780)
        /home/ephelan/.gvm/pkgsets/go1.16.4/global/pkg/mod/github.com/spf13/cobra@v1.2.1/command.go:974 +0x375
github.com/spf13/cobra.(*Command).Execute(...)
        /home/ephelan/.gvm/pkgsets/go1.16.4/global/pkg/mod/github.com/spf13/cobra@v1.2.1/command.go:902
main.main()
        /home/ephelan/code/github.com/redhat-developer/app-services-cli/cmd/rhoas/main.go:43 +0x29d

@rkpattnaik780 rkpattnaik780 force-pushed the acl_convenience_admin branch 2 times, most recently from 3797b73 to 43d2c9c Compare October 20, 2021 11:16
Copy link
Contributor

@craicoverflow craicoverflow left a comment

Choose a reason for hiding this comment

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

The ACLs granted in this command do now allow me to create topics:

$ kafka-topics.sh --create --topic rhoas_2hello --bootstrap-server 
Error while executing topic command : Authorization failed.
[2021-10-20 15:14:35,800] ERROR org.apache.kafka.common.errors.TopicAuthorizationException: Authorization failed.
 (kafka.admin.TopicCommand$)

However once I create an ACL with ALLOW | ALL | TOPIC is "*"I could do it:

$ kafka-topics.sh --create --topic rhoas_2hello --bootstrap-server $(rhoas kafka describe --bootstrap-server) --command-config ./kafka-config.prod.properties
Created topic rhoas_2hello.

I recommend investagint the Kafka bin scripts, to see exactly what they would apply, we may need additonal ACLs other than CLUSTER ALTER

@rkpattnaik780
Copy link
Contributor Author

The ACLs granted in this command do now allow me to create topics:

$ kafka-topics.sh --create --topic rhoas_2hello --bootstrap-server 
Error while executing topic command : Authorization failed.
[2021-10-20 15:14:35,800] ERROR org.apache.kafka.common.errors.TopicAuthorizationException: Authorization failed.
 (kafka.admin.TopicCommand$)

However once I create an ACL with ALLOW | ALL | TOPIC is "*"I could do it:

$ kafka-topics.sh --create --topic rhoas_2hello --bootstrap-server $(rhoas kafka describe --bootstrap-server) --command-config ./kafka-config.prod.properties
Created topic rhoas_2hello.

I recommend investagint the Kafka bin scripts, to see exactly what they would apply, we may need additonal ACLs other than CLUSTER ALTER

bin scripts don't seem to have an explicit option to grant admin access, it is a common use case. The design documents mention an extra ACL rule for cluster describe, the requirements point that admin should grant only ability to add/delete ACLs, user must create an acl before doing operations.

@craicoverflow craicoverflow self-requested a review October 21, 2021 09:01
@craicoverflow
Copy link
Contributor

Great work so far!

I think we should also be displaying to the user the exact ACL(s) like we do in the grant-access commands, as we are hiding the actual ACL that is being created. This makes it difficult for the user to:

a) get a clear understanding of what is being applied
b) reverse the decision by deleting it in case of a mistake

$ ./rhoas kafka acl grant-access --service-account hello --producer --topic rhoas
The following ACL rules are to be created:

  PRINCIPAL (5)    PERMISSION   OPERATION   DESCRIPTION              
 ---------------- ------------ ----------- ------------------------- 
  hello            ALLOW        DESCRIBE    TOPIC is "rhoas"         
  hello            ALLOW        WRITE       TOPIC is "rhoas"         
  hello            ALLOW        CREATE      TOPIC is "rhoas"         
  hello            ALLOW        WRITE       TRANSACTIONAL_ID is "*"  
  hello            ALLOW        DESCRIBE    TRANSACTIONAL_ID is "*"  

? Are you sure you want to create the listed ACL rules (y/N) 

@rkpattnaik780 rkpattnaik780 changed the title feat(kafka acl): add admin command feat(kafka acl): add grant-admin command Oct 21, 2021
@rkpattnaik780 rkpattnaik780 requested review from craicoverflow and removed request for craicoverflow October 26, 2021 14:55
Comment on lines +75 to +83
// check if priincipal is provided
if userID == "" && serviceAccount == "" && !allAccounts {
return opts.localizer.MustLocalizeError("kafka.acl.common.error.noPrincipalsSelected")
}

// user and service account can't be along with "--all-accounts" flag
if allAccounts && (serviceAccount != "" || userID != "") {
return opts.localizer.MustLocalizeError("kafka.acl.common.error.allAccountsCannotBeUsedWithUserFlag")
}
Copy link
Contributor

Choose a reason for hiding this comment

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

From what I can see we are not preventing the user from passing a wilcard to the user or service-account flags. Shouldn't we be?

one = '''
# Grant access to principal for consuming messages from all topics
$ rhoas kafka acl grant-access --consumer --user user_name --topic all --group all
$ rhoas kafka acl grant-access --consumer --user user_name --topic "*" --group "*"
Copy link
Contributor

Choose a reason for hiding this comment

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

I believe we are sticking with aliases now?

Copy link
Contributor

@craicoverflow craicoverflow left a comment

Choose a reason for hiding this comment

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

A couple of questions left inline.

Copy link
Contributor

@craicoverflow craicoverflow left a comment

Choose a reason for hiding this comment

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

Looks great! I think we should have a second opinion on the cmd long and short descriptions though.

[kafka.acl.grantAdmin]

[kafka.acl.grantAdmin.cmd.shortDescription]
one = 'Give admin rights to the account'
Copy link
Contributor

Choose a reason for hiding this comment

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

Suggested change
one = 'Give admin rights to the account'
one = 'Grant an account permissions to create and delete ACLs in the Kafka instance'

The existing short description seemed a little too short and informal.

Comment on lines +270 to +274
[kafka.acl.grantAdmin.cmd.shortDescription]
one = 'Give admin rights to the account'

[kafka.acl.grantAdmin.cmd.longDescription]
one = 'This command will give specified account permission to create and delete ACLs in a Kafka instance.'
Copy link
Contributor

Choose a reason for hiding this comment

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

cc @jbyrne-redhat could review the CLI command documentation highlighted?

Copy link
Collaborator

Choose a reason for hiding this comment

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

Suggest just a couple of minor tweaks:

'This command grants a specified account permission to create and delete ACLs in a Kafka instance.'

kafkainstanceclient.ACLPERMISSIONTYPE_ALLOW,
)

rows := aclutil.MapACLsToTableRows([]kafkainstanceclient.AclBinding{*aclBindClusterAlter}, opts.localizer)
Copy link
Contributor

Choose a reason for hiding this comment

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

We could probably skip that when -y is passed.

Copy link
Contributor Author

Choose a reason for hiding this comment

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

I would prefer to keep -y for the confirmation action only and display the ACLs to be generated in both scenario.

Copy link
Contributor

Choose a reason for hiding this comment

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

That's fair. I think it needs an explanation to give context to the table though because right now it prints without info about it.

❯ ./rhoas kafka acl grant-admin --all-accounts -y
  PRINCIPAL      PERMISSION   OPERATION   DESCRIPTION                 
 -------------- ------------ ----------- ---------------------------- 
  All accounts   ALLOW        ALTER       CLUSTER is "kafka-cluster"  

✔️ Account "*" is now allowed to create and delete ACLs for Kafka instance "enda-dev"

It might be nice to add something like:

The following ACLs will be created:

...

above it.


opts.kafkaID = instanceID

// check if priincipal is provided
Copy link
Collaborator

Choose a reason for hiding this comment

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

Suggested change
// check if priincipal is provided
// check if principal is provided

Copy link
Collaborator

@wtrocki wtrocki left a comment

Choose a reason for hiding this comment

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

Reviewed and verified. Great job!

@rkpattnaik780 rkpattnaik780 merged commit e77ed09 into main Oct 28, 2021
@rkpattnaik780 rkpattnaik780 deleted the acl_convenience_admin branch October 28, 2021 06:49
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.

Support for Admin command to give another principal access to manage Kafka ACL

4 participants