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

KAFKA-18051: Disallow creating ACLs with principals that do not contain a colon #17883

Open
wants to merge 1 commit into
base: trunk
Choose a base branch
from
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
Original file line number Diff line number Diff line change
Expand Up @@ -160,6 +160,12 @@ static void validateNewAcl(AclBinding binding) {
if (binding.pattern().name() == null || binding.pattern().name().isEmpty()) {
throw new InvalidRequestException("Resource name should not be empty");
}
int colonIndex = binding.entry().principal().indexOf(":");
if (colonIndex == -1) {
throw new InvalidRequestException("Could not parse principal from `" +
binding.entry().principal() + "` " + "(no colon is present separating the " +
"principal type from the principal name)");
}
}

ControllerResult<List<AclDeleteResult>> deleteAcls(List<AclBindingFilter> filters) {
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -114,6 +114,34 @@ public void testValidateNewAcl() {
getMessage());
}

/**
* Verify that validateNewAcl catches invalid ACLs with principals that do not contain a colon.
*/
@Test
public void testValidateAclWithBadPrincipal() {
assertEquals("Could not parse principal from `invalid` (no colon is present " +
"separating the principal type from the principal name)",
assertThrows(InvalidRequestException.class, () ->
AclControlManager.validateNewAcl(new AclBinding(
new ResourcePattern(TOPIC, "*", LITERAL),
new AccessControlEntry("invalid", "*", ALTER, ALLOW)))).
getMessage());
}

/**
* Verify that validateNewAcl catches invalid ACLs with principals that do not contain a colon.
*/
@Test
public void testValidateAclWithEmptyPrincipal() {
assertEquals("Could not parse principal from `` (no colon is present " +
"separating the principal type from the principal name)",
assertThrows(InvalidRequestException.class, () ->
AclControlManager.validateNewAcl(new AclBinding(
new ResourcePattern(TOPIC, "*", LITERAL),
new AccessControlEntry("", "*", ALTER, ALLOW)))).
getMessage());
}

/**
* Verify that validateFilter catches invalid filters.
*/
Expand Down