mirror of https://github.com/apache/kafka.git
KAFKA-18051: Disallow creating ACLs with principals that do not contain a colon (#17883)
Kafka Principals must contain a colon. We should enforce this in createAcls. Reviewers: David Arthur <mumrah@gmail.com>
This commit is contained in:
parent
866f0cc308
commit
cd36d64535
|
@ -160,6 +160,12 @@ public class AclControlManager {
|
|||
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) {
|
||||
|
|
|
@ -114,6 +114,34 @@ public class AclControlManagerTest {
|
|||
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.
|
||||
*/
|
||||
|
|
Loading…
Reference in New Issue