Skip to content

feat(kafka acl grant-access): add --all-accounts flag#1222

Merged
rkpattnaik780 merged 1 commit intomainfrom
acl_convenience_all_principals
Oct 19, 2021
Merged

feat(kafka acl grant-access): add --all-accounts flag#1222
rkpattnaik780 merged 1 commit intomainfrom
acl_convenience_all_principals

Conversation

@rkpattnaik780
Copy link
Contributor

@rkpattnaik780 rkpattnaik780 commented Oct 14, 2021

--all-accounts flag to grant permissions to all users and service accounts (substitute for --user "*" and --service-account "*").

Closes #1197

Verification Steps

  1. The following command should grant access to all users for consuming messages from topic "my-topic"
rhoas kafka acl grant-permissions --consumer --all-accounts --topic my-topic --group my-group

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

@wtrocki
Copy link
Collaborator

wtrocki commented Oct 14, 2021

See dicussion in #1197

userArg = buildPrincipal(acl.Wildcard)
}

if opts.svcAccount != "" {
Copy link
Contributor

Choose a reason for hiding this comment

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

We need to throw an error if user or service-account value is all. I have not tested whether it does this but I cannot see this.

Copy link
Contributor Author

Choose a reason for hiding this comment

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

Working on it. I am not sure if we should throw an error.

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 think passing all should be left as it is?

Copy link
Contributor

Choose a reason for hiding this comment

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

If no error, what do you think should happen?

Copy link
Contributor Author

@rkpattnaik780 rkpattnaik780 Oct 14, 2021

Choose a reason for hiding this comment

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

it should be processed as a simple identifier?
user is literal "all"

Copy link
Contributor

Choose a reason for hiding this comment

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

The user of the CLI will think running --user=all will limit the wildcard to users, not service accounts, but in fact it will apply it to all. That IMO is dangerous as it will give a false sense of security.

@rkpattnaik780 rkpattnaik780 force-pushed the acl_convenience_all_principals branch from bbad6e1 to 610ec81 Compare October 18, 2021 07:05
@craicoverflow
Copy link
Contributor

I'm wondering if we should call it --all-accounts instead? This is how we describe it in the ACL list table, and it feel more natural to me.

[kafka.acl.common.flag.groupPrefix.description]
one = 'Prefix name for groups to be selected'

[kafka.acl.common.flag.allPrincipals]
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
[kafka.acl.common.flag.allPrincipals]
[kafka.acl.common.flag.allPrincipals.description]

Pattern has been {flagName}.description

@rkpattnaik780
Copy link
Contributor Author

I'm wondering if we should call it --all-accounts instead? This is how we describe it in the ACL list table, and it feel more natural to me.

Sticking to --all-accounts, UI uses accounts as well.

@craicoverflow craicoverflow changed the title feat(kafka acl grant-permissions): add --all-principals flag feat(kafka acl grant-permissions): add --all-accounts flag Oct 18, 2021
allAccounts bool
}

// NewGrantPermissionsACLCommand creates a series of ACL rules
Copy link
Contributor

Choose a reason for hiding this comment

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

Should be NewGrantAccess now.

Comment on lines 147 to 148
if opts.user != "" {
user := getArgumentFromAlias(opts.user)
userArg = buildPrincipal(user)
if opts.user == acl.All {
return opts.localizer.MustLocalizeError("kafka.acl.common.error.allNotAllowed", localize.NewEntry("Flag", "user"))
}
userArg = buildPrincipal(opts.user)
}

if opts.allAccounts {
userArg = buildPrincipal(acl.Wildcard)
}
Copy link
Contributor

Choose a reason for hiding this comment

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

nit: I like the pattern of where opts only has principal value and you do not need to carry out this logic to determine which one to select (as you must then repeat these checks every time you want to reference the principal to use.

A cleaner approach might be to figure out the principal from the flags and assign it to opts in the input validation stage, like this:

if userID != "" {
opts.principal = userID
} else if serviceAccount != "" {
opts.principal = serviceAccount
}

@rkpattnaik780 rkpattnaik780 changed the title feat(kafka acl grant-permissions): add --all-accounts flag feat(kafka acl grant-access): add --all-accounts flag Oct 19, 2021
Comment on lines +317 to 312
if userID == "" && serviceAccount == "" && !allAccounts {
return opts.localizer.MustLocalizeError("kafka.acl.grantPermissions.error.noPrincipalsSelected")
}

// user and service account should not be provided together
if opts.user != "" && opts.svcAccount != "" {
if userID != "" && serviceAccount != "" {
return opts.localizer.MustLocalizeError("kafka.acl.grantPermissions.error.bothPrincipalsSelected")
}
Copy link
Contributor

Choose a reason for hiding this comment

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

nit: these checks could go before the logic of assigning the correct principal to opts.principal

Copy link
Contributor Author

Choose a reason for hiding this comment

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

these checks are executed before assignment, it is the function definition here.

@rkpattnaik780 rkpattnaik780 force-pushed the acl_convenience_all_principals branch from 3f5a596 to 5fa07be Compare October 19, 2021 14:43
@rkpattnaik780 rkpattnaik780 merged commit d9fcb54 into main Oct 19, 2021
@rkpattnaik780 rkpattnaik780 deleted the acl_convenience_all_principals branch October 19, 2021 15:20
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.

Add --all-principals flag to convinience commands

3 participants