Skip to content

Commit

Permalink
KAFKA-13651; Add audit logging to StandardAuthorizer (apache#12031)
Browse files Browse the repository at this point in the history
This patch adds audit support through the kafka.authorizer.logger logger to StandardAuthorizer. It
follows the same conventions as AclAuthorizer with a similarly formatted log message. When
logIfAllowed is set in the Action, then the log message is at DEBUG level; otherwise, we log at
trace. When logIfDenied is set, then the log message is at INFO level; otherwise, we again log at
TRACE.

Reviewers: Colin P. McCabe <cmccabe@apache.org>
  • Loading branch information
hachikuji committed Apr 13, 2022
1 parent a6d86b9 commit f976464
Show file tree
Hide file tree
Showing 5 changed files with 347 additions and 69 deletions.
2 changes: 2 additions & 0 deletions build.gradle
Original file line number Diff line number Diff line change
Expand Up @@ -1136,6 +1136,8 @@ project(':metadata') {
compileOnly libs.log4j
testImplementation libs.junitJupiter
testImplementation libs.hamcrest
testImplementation libs.mockitoCore
testImplementation libs.mockitoInline
testImplementation libs.slf4jlog4j
testImplementation project(':clients').sourceSets.test.output
testImplementation project(':raft').sourceSets.test.output
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -89,7 +89,7 @@ public ResourcePatternFilter toFilter() {

@Override
public String toString() {
return "ResourcePattern(resourceType=" + resourceType + ", name=" + ((name == null) ? "<any>" : name) + ", patternType=" + patternType + ")";
return "ResourcePattern(resourceType=" + resourceType + ", name=" + name + ", patternType=" + patternType + ")";
}

/**
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -25,6 +25,7 @@
import org.apache.kafka.common.resource.PatternType;
import org.apache.kafka.common.resource.ResourcePattern;
import org.apache.kafka.common.resource.ResourceType;
import org.apache.kafka.common.security.auth.KafkaPrincipal;

import java.util.Objects;

Expand Down Expand Up @@ -96,6 +97,17 @@ public String principal() {
return principal;
}

public KafkaPrincipal kafkaPrincipal() {
int colonIndex = principal.indexOf(":");
if (colonIndex == -1) {
throw new IllegalStateException("Could not parse principal from `" + principal + "` " +
"(no colon is present separating the principal type from the principal name)");
}
String principalType = principal.substring(0, colonIndex);
String principalName = principal.substring(colonIndex + 1);
return new KafkaPrincipal(principalType, principalName);
}

public String host() {
return host;
}
Expand Down
Loading

0 comments on commit f976464

Please sign in to comment.