You are viewing a plain text version of this content. The canonical link for it is here.
Posted to notifications@zookeeper.apache.org by "ikxeno (via GitHub)" <gi...@apache.org> on 2026/10/12 08:41:46 UTC
[PR] ZOOKEEPER-4922: Audit JAAS login, logout and Kerberos ticket renewal [zookeeper]
ikxeno opened a new pull request, #2473:
URL: https://github.com/apache/zookeeper/pull/2473
### Problem
ZooKeeper audits znode operations and server startup and shutdown, but JAAS login, logout and Kerberos ticket renewal are missing from the audit log. Authentication and renewal failures have no audit event identifying the principal involved.
### Fix
Add `login`, `logout` and `ticketRenewal` events through the existing audit provider, enabled by `zookeeper.audit.enable`.
- Events are written in the JVM performing the JAAS operation and contain `user`, `operation` and `result`. The user comes from the authenticated Kerberos principal, a configured JAAS principal or the OS user. Failed renewals keep the identity from the last successful login.
- Ticket cache refresh failures and failed re-logins produce renewal failure events; skipped renewals produce none. Logout during re-login is also audited. Stopping the refresh thread alone does not emit a logout event.
- `RuntimeException` and `LinkageError` from logger initialization or writes are logged without changing the JAAS result or replacing the original `LoginException`.
- The logger remains fixed per JVM. Disabled client logins do not initialize it. An embedded server now rejects a different logger class after selection; configuring the same class again is allowed.
The audit documentation describes the events and logger configuration timing, marked new in 3.10.0.
### Tests
- `LoginAuditTest` checks principal selection, event ordering, failed renewal retries, skipped attempts, logger write failures and conflicting embedded server configuration.
- The other `LoginAudit*Test` classes exercise disabled auditing, a client login before embedded server startup, failed logger initialization and configuration during initialization.
--
This is an automated message from the Apache Git Service.
To respond to the message, please log on to GitHub and use the
URL above to go to the specific comment.
To unsubscribe, e-mail: notifications-unsubscribe@zookeeper.apache.org
For queries about this service, please contact Infrastructure at:
users@infra.apache.org
Re: [PR] ZOOKEEPER-4922: Audit JAAS login, logout and Kerberos ticket renewal [zookeeper]
Posted by "ikxeno (via GitHub)" <gi...@apache.org>.
ikxeno commented on code in PR #2473:
URL: https://github.com/apache/zookeeper/pull/2473#discussion_r4323241157
##########
zookeeper-server/src/main/java/org/apache/zookeeper/audit/ZKAuditProvider.java:
##########
@@ -25,29 +25,60 @@
import org.slf4j.LoggerFactory;
public class ZKAuditProvider {
- static final String AUDIT_ENABLE = "zookeeper.audit.enable";
+ /**
+ * System property that enables audit logging.
+ */
+ public static final String AUDIT_ENABLE = "zookeeper.audit.enable";
static final String AUDIT_IMPL_CLASS = "zookeeper.audit.impl.class";
private static final Logger LOG = LoggerFactory.getLogger(ZKAuditProvider.class);
- // By default audit logging is disabled
- private static boolean auditEnabled;
- private static AuditLogger auditLogger;
+ private static String selectedAuditLoggerClass;
- static {
- auditEnabled = Boolean.getBoolean(AUDIT_ENABLE);
- if (auditEnabled) {
- //initialise only when audit logging is enabled
- auditLogger = getAuditLogger();
- LOG.info("ZooKeeper audit is enabled.");
- } else {
- LOG.info("ZooKeeper audit is disabled.");
+ // Parsing server configuration must not initialize the audit logger.
+ private static class AuditState {
+ private static final boolean auditEnabled;
+ private static final AuditLogger auditLogger;
+ private static final RuntimeException initializationFailure;
+
+ static {
+ String loggerClass = null;
+ synchronized (ZKAuditProvider.class) {
Review Comment:
The shared lock coordinates `AuditState` initialization with `configureAuditLogger()` on the outer class. Without it, I reproduced B being accepted while the actual logger was A.
<details>
<summary>Reproduction results</summary>
These are the results from fresh JVMs on Java 17 and 25.
```text
temurin-17.jdk / ORIGINAL
RESULT rejected=true; actual=A; property=A
temurin-17.jdk / WITHOUT_SELECTION_LOCK
RESULT rejected=false; actual=A; property=B
jdk-25.jdk / ORIGINAL
RESULT rejected=true; actual=A; property=A
jdk-25.jdk / WITHOUT_SELECTION_LOCK
RESULT rejected=false; actual=A; property=B
```
</details>
<details>
<summary>Reproduction code</summary>
Tested on Java 17 and 25 against `26e1b7297`, then against a copy with only the `synchronized (ZKAuditProvider.class)` wrapper removed from `AuditState`.
The overridden property read pauses initialization after reading A, before recording the selection. This forces the interleaving; it doesn't measure how often it happens in production.
Save as `AuditConfigurationRaceProbe.java`:
```java
import java.lang.management.LockInfo;
import java.lang.management.ManagementFactory;
import java.lang.management.ThreadInfo;
import java.lang.management.ThreadMXBean;
import java.util.Properties;
import java.util.concurrent.CountDownLatch;
import java.util.concurrent.TimeUnit;
import java.util.concurrent.atomic.AtomicInteger;
import java.util.concurrent.atomic.AtomicReference;
import org.apache.zookeeper.audit.AuditEvent;
import org.apache.zookeeper.audit.AuditLogger;
import org.apache.zookeeper.audit.ZKAuditProvider;
public class AuditConfigurationRaceProbe {
private static final String AUDIT_LOGGER_PROPERTY = "zookeeper.audit.impl.class";
private static final long WAIT_TIMEOUT_SECONDS = 5;
private static final long STATE_POLL_MILLIS = 1;
private static final AtomicInteger initializedA = new AtomicInteger();
private static final AtomicInteger initializedB = new AtomicInteger();
enum Variant { ORIGINAL, WITHOUT_SELECTION_LOCK }
public static class LoggerA implements AuditLogger {
public void initialize() { initializedA.incrementAndGet(); }
public void logAuditEvent(AuditEvent event) { }
}
public static class LoggerB implements AuditLogger {
public void initialize() { initializedB.incrementAndGet(); }
public void logAuditEvent(AuditEvent event) { }
}
private static void check(boolean condition, String message) {
if (!condition) {
throw new AssertionError(message);
}
}
private static void await(CountDownLatch latch) {
try {
check(latch.await(WAIT_TIMEOUT_SECONDS, TimeUnit.SECONDS), "Property-read gate timed out");
} catch (InterruptedException failure) {
Thread.currentThread().interrupt();
throw new AssertionError(failure);
}
}
private static void awaitConfigurationOutcome(Thread thread) throws InterruptedException {
ThreadMXBean threads = ManagementFactory.getThreadMXBean();
long deadline = System.nanoTime() + TimeUnit.SECONDS.toNanos(WAIT_TIMEOUT_SECONDS);
while (thread.isAlive()) {
ThreadInfo state = threads.getThreadInfo(thread.getId());
LockInfo lock = state == null ? null : state.getLockInfo();
if (state != null && state.getThreadState() == Thread.State.BLOCKED && lock != null
&& lock.getClassName().equals(Class.class.getName())
&& lock.getIdentityHashCode() == System.identityHashCode(ZKAuditProvider.class)) {
return;
}
check(System.nanoTime() < deadline, "Configuration neither finished nor blocked on provider monitor");
Thread.sleep(STATE_POLL_MILLIS);
}
}
public static void main(String[] args) throws Exception {
Variant variant = Variant.valueOf(args[0]);
Properties previous = System.getProperties();
CountDownLatch propertyRead = new CountDownLatch(1);
CountDownLatch releaseRead = new CountDownLatch(1);
Properties gated = new Properties() {
@Override
public String getProperty(String key, String fallback) {
String value = super.getProperty(key, fallback);
if (key.equals(AUDIT_LOGGER_PROPERTY)) {
propertyRead.countDown();
await(releaseRead);
}
return value;
}
};
gated.putAll(previous);
gated.setProperty(ZKAuditProvider.AUDIT_ENABLE, "true");
gated.setProperty(AUDIT_LOGGER_PROPERTY, LoggerA.class.getName());
AtomicReference<Throwable> initializationFailure = new AtomicReference<>();
AtomicReference<Throwable> configurationFailure = new AtomicReference<>();
Thread initialize = new Thread(() -> {
try {
check(ZKAuditProvider.isAuditEnabled(), "Audit unexpectedly disabled");
} catch (Throwable failure) {
initializationFailure.set(failure);
}
}, "initialize-audit");
Thread configure = new Thread(() -> {
try {
ZKAuditProvider.configureAuditLogger(LoggerB.class.getName());
} catch (Throwable failure) {
configurationFailure.set(failure);
}
}, "configure-audit");
System.setProperties(gated);
try {
try {
initialize.start();
await(propertyRead);
configure.start();
awaitConfigurationOutcome(configure);
} finally {
releaseRead.countDown();
initialize.join(TimeUnit.SECONDS.toMillis(WAIT_TIMEOUT_SECONDS));
configure.join(TimeUnit.SECONDS.toMillis(WAIT_TIMEOUT_SECONDS));
}
check(!initialize.isAlive() && !configure.isAlive(), "Worker thread did not terminate");
check(initializationFailure.get() == null, "Initialization failed: " + initializationFailure.get());
boolean rejected = variant == Variant.ORIGINAL;
Throwable failure = configurationFailure.get();
if (rejected) {
check(failure instanceof IllegalArgumentException, "Missing conflict exception: " + failure);
String message = failure.getMessage();
check(message != null && message.contains(LoggerA.class.getName())
&& message.contains(LoggerB.class.getName()), "Wrong conflict: " + failure);
} else {
check(failure == null, "Unexpected configuration failure: " + failure);
}
check(initializedA.get() == 1 && initializedB.get() == 0, "Wrong logger initialized");
String expectedProperty = rejected ? LoggerA.class.getName() : LoggerB.class.getName();
check(expectedProperty.equals(System.getProperty(AUDIT_LOGGER_PROPERTY)), "Wrong configured class");
System.out.println("RESULT rejected=" + rejected + "; actual=A; property=" + (rejected ? "A" : "B"));
} finally {
System.setProperties(previous);
}
}
}
```
Set `ZK_CP` to the tested build's server classes and runtime dependencies. Compile and run in a fresh JVM:
```sh
javac -cp "$ZK_CP" -d repro-classes AuditConfigurationRaceProbe.java
java -cp "repro-classes:$ZK_CP" AuditConfigurationRaceProbe ORIGINAL
```
Remove only the wrapper, rebuild the provider, and update `ZK_CP` to that build. Then run:
```sh
java -cp "repro-classes:$ZK_CP" AuditConfigurationRaceProbe WITHOUT_SELECTION_LOCK
```
The argument selects the expected assertions; it doesn't modify the provider.
</details>
--
This is an automated message from the Apache Git Service.
To respond to the message, please log on to GitHub and use the
URL above to go to the specific comment.
To unsubscribe, e-mail: notifications-unsubscribe@zookeeper.apache.org
For queries about this service, please contact Infrastructure at:
users@infra.apache.org
Re: [PR] ZOOKEEPER-4922: Audit JAAS login, logout and Kerberos ticket renewal [zookeeper]
Posted by "ikxeno (via GitHub)" <gi...@apache.org>.
ikxeno commented on PR #2473:
URL: https://github.com/apache/zookeeper/pull/2473#issuecomment-6287550082
> We should create pending issue to solve those new `ZKAuditProvider.isAuditEnabled` checks.
I've fixed those here, but I can move the change to a separate ticket and PR if you'd prefer.
--
This is an automated message from the Apache Git Service.
To respond to the message, please log on to GitHub and use the
URL above to go to the specific comment.
To unsubscribe, e-mail: notifications-unsubscribe@zookeeper.apache.org
For queries about this service, please contact Infrastructure at:
users@infra.apache.org
Re: [PR] ZOOKEEPER-4922: Audit JAAS login, logout and Kerberos ticket renewal [zookeeper]
Posted by "anmolnar (via GitHub)" <gi...@apache.org>.
anmolnar commented on PR #2473:
URL: https://github.com/apache/zookeeper/pull/2473#issuecomment-6178230077
Backports are not necessarily a problem, but I think other points are worth to think about. Especially with package-private fields you can easily make the tests more lightweight. It's a common practice across the code.
--
This is an automated message from the Apache Git Service.
To respond to the message, please log on to GitHub and use the
URL above to go to the specific comment.
To unsubscribe, e-mail: notifications-unsubscribe@zookeeper.apache.org
For queries about this service, please contact Infrastructure at:
users@infra.apache.org
Re: [PR] ZOOKEEPER-4922: Audit JAAS login, logout and Kerberos ticket renewal [zookeeper]
Posted by "kezhuw (via GitHub)" <gi...@apache.org>.
kezhuw commented on code in PR #2473:
URL: https://github.com/apache/zookeeper/pull/2473#discussion_r4307409257
##########
zookeeper-server/src/main/java/org/apache/zookeeper/audit/ZKAuditProvider.java:
##########
@@ -25,29 +25,60 @@
import org.slf4j.LoggerFactory;
public class ZKAuditProvider {
- static final String AUDIT_ENABLE = "zookeeper.audit.enable";
+ /**
+ * System property that enables audit logging.
+ */
+ public static final String AUDIT_ENABLE = "zookeeper.audit.enable";
static final String AUDIT_IMPL_CLASS = "zookeeper.audit.impl.class";
private static final Logger LOG = LoggerFactory.getLogger(ZKAuditProvider.class);
- // By default audit logging is disabled
- private static boolean auditEnabled;
- private static AuditLogger auditLogger;
+ private static String selectedAuditLoggerClass;
- static {
- auditEnabled = Boolean.getBoolean(AUDIT_ENABLE);
- if (auditEnabled) {
- //initialise only when audit logging is enabled
- auditLogger = getAuditLogger();
- LOG.info("ZooKeeper audit is enabled.");
- } else {
- LOG.info("ZooKeeper audit is disabled.");
+ // Parsing server configuration must not initialize the audit logger.
+ private static class AuditState {
+ private static final boolean auditEnabled;
+ private static final AuditLogger auditLogger;
+ private static final RuntimeException initializationFailure;
+
+ static {
+ String loggerClass = null;
+ synchronized (ZKAuditProvider.class) {
Review Comment:
This is not necessary. class level `static` block is enough.
##########
zookeeper-server/src/main/java/org/apache/zookeeper/audit/ZKAuditProvider.java:
##########
@@ -61,14 +92,20 @@ private static AuditLogger getAuditLogger() {
/**
* @return true if audit log is enabled
+ * @throws IllegalStateException if the audit logger could not be initialized
*/
public static boolean isAuditEnabled() {
- return auditEnabled;
+ if (AuditState.initializationFailure != null) {
Review Comment:
I think it is a good for a dedicated method to check audit state but not this `is` method.
##########
zookeeper-server/src/main/java/org/apache/zookeeper/audit/ZKAuditProvider.java:
##########
@@ -25,29 +25,60 @@
import org.slf4j.LoggerFactory;
public class ZKAuditProvider {
- static final String AUDIT_ENABLE = "zookeeper.audit.enable";
+ /**
+ * System property that enables audit logging.
+ */
+ public static final String AUDIT_ENABLE = "zookeeper.audit.enable";
static final String AUDIT_IMPL_CLASS = "zookeeper.audit.impl.class";
private static final Logger LOG = LoggerFactory.getLogger(ZKAuditProvider.class);
- // By default audit logging is disabled
- private static boolean auditEnabled;
- private static AuditLogger auditLogger;
+ private static String selectedAuditLoggerClass;
- static {
- auditEnabled = Boolean.getBoolean(AUDIT_ENABLE);
- if (auditEnabled) {
- //initialise only when audit logging is enabled
- auditLogger = getAuditLogger();
- LOG.info("ZooKeeper audit is enabled.");
- } else {
- LOG.info("ZooKeeper audit is disabled.");
+ // Parsing server configuration must not initialize the audit logger.
+ private static class AuditState {
+ private static final boolean auditEnabled;
+ private static final AuditLogger auditLogger;
+ private static final RuntimeException initializationFailure;
+
+ static {
+ String loggerClass = null;
+ synchronized (ZKAuditProvider.class) {
+ auditEnabled = Boolean.getBoolean(AUDIT_ENABLE);
+ if (auditEnabled) {
+ loggerClass = System.getProperty(AUDIT_IMPL_CLASS, Slf4jAuditLogger.class.getName());
+ selectedAuditLoggerClass = loggerClass;
+ }
+ }
+ AuditLogger logger = null;
+ RuntimeException failure = null;
+ if (auditEnabled) {
+ try {
+ logger = getAuditLogger(loggerClass);
+ LOG.info("ZooKeeper audit is enabled.");
+ } catch (RuntimeException | LinkageError e) {
+ failure = new IllegalStateException("Couldn't initialize audit logger " + loggerClass, e);
+ }
+ } else {
+ LOG.info("ZooKeeper audit is disabled.");
+ }
+ auditLogger = logger;
+ initializationFailure = failure;
}
}
- private static AuditLogger getAuditLogger() {
- String auditLoggerClass = System.getProperty(AUDIT_IMPL_CLASS);
- if (auditLoggerClass == null) {
- auditLoggerClass = Slf4jAuditLogger.class.getName();
+ /**
+ * Configures the audit logger class without initializing the logger.
Review Comment:
This is not ture! The initialization hapens inside class level `static` block which happens before call to this due to reference to `ZKAuditProvider`.
--
This is an automated message from the Apache Git Service.
To respond to the message, please log on to GitHub and use the
URL above to go to the specific comment.
To unsubscribe, e-mail: notifications-unsubscribe@zookeeper.apache.org
For queries about this service, please contact Infrastructure at:
users@infra.apache.org
Re: [PR] ZOOKEEPER-4922: Audit JAAS login, logout and Kerberos ticket renewal [zookeeper]
Posted by "ikxeno (via GitHub)" <gi...@apache.org>.
ikxeno commented on code in PR #2473:
URL: https://github.com/apache/zookeeper/pull/2473#discussion_r4323318071
##########
zookeeper-server/src/main/java/org/apache/zookeeper/audit/ZKAuditProvider.java:
##########
@@ -61,14 +92,20 @@ private static AuditLogger getAuditLogger() {
/**
* @return true if audit log is enabled
+ * @throws IllegalStateException if the audit logger could not be initialized
*/
public static boolean isAuditEnabled() {
- return auditEnabled;
+ if (AuditState.initializationFailure != null) {
Review Comment:
Agreed. I've added checkAuditState() for validation and switched all four startup checks to it.
--
This is an automated message from the Apache Git Service.
To respond to the message, please log on to GitHub and use the
URL above to go to the specific comment.
To unsubscribe, e-mail: notifications-unsubscribe@zookeeper.apache.org
For queries about this service, please contact Infrastructure at:
users@infra.apache.org
Re: [PR] ZOOKEEPER-4922: Audit JAAS login, logout and Kerberos ticket renewal [zookeeper]
Posted by "kezhuw (via GitHub)" <gi...@apache.org>.
kezhuw commented on code in PR #2473:
URL: https://github.com/apache/zookeeper/pull/2473#discussion_r4323765876
##########
zookeeper-server/src/main/java/org/apache/zookeeper/audit/ZKAuditProvider.java:
##########
@@ -25,29 +25,60 @@
import org.slf4j.LoggerFactory;
public class ZKAuditProvider {
- static final String AUDIT_ENABLE = "zookeeper.audit.enable";
+ /**
+ * System property that enables audit logging.
+ */
+ public static final String AUDIT_ENABLE = "zookeeper.audit.enable";
static final String AUDIT_IMPL_CLASS = "zookeeper.audit.impl.class";
private static final Logger LOG = LoggerFactory.getLogger(ZKAuditProvider.class);
- // By default audit logging is disabled
- private static boolean auditEnabled;
- private static AuditLogger auditLogger;
+ private static String selectedAuditLoggerClass;
- static {
- auditEnabled = Boolean.getBoolean(AUDIT_ENABLE);
- if (auditEnabled) {
- //initialise only when audit logging is enabled
- auditLogger = getAuditLogger();
- LOG.info("ZooKeeper audit is enabled.");
- } else {
- LOG.info("ZooKeeper audit is disabled.");
+ // Parsing server configuration must not initialize the audit logger.
+ private static class AuditState {
+ private static final boolean auditEnabled;
+ private static final AuditLogger auditLogger;
+ private static final RuntimeException initializationFailure;
+
+ static {
+ String loggerClass = null;
+ synchronized (ZKAuditProvider.class) {
+ auditEnabled = Boolean.getBoolean(AUDIT_ENABLE);
+ if (auditEnabled) {
+ loggerClass = System.getProperty(AUDIT_IMPL_CLASS, Slf4jAuditLogger.class.getName());
+ selectedAuditLoggerClass = loggerClass;
+ }
+ }
+ AuditLogger logger = null;
+ RuntimeException failure = null;
+ if (auditEnabled) {
+ try {
+ logger = getAuditLogger(loggerClass);
+ LOG.info("ZooKeeper audit is enabled.");
+ } catch (RuntimeException | LinkageError e) {
+ failure = new IllegalStateException("Couldn't initialize audit logger " + loggerClass, e);
+ }
+ } else {
+ LOG.info("ZooKeeper audit is disabled.");
+ }
+ auditLogger = logger;
+ initializationFailure = failure;
}
}
- private static AuditLogger getAuditLogger() {
- String auditLoggerClass = System.getProperty(AUDIT_IMPL_CLASS);
- if (auditLoggerClass == null) {
- auditLoggerClass = Slf4jAuditLogger.class.getName();
+ /**
+ * Configures the audit logger class without initializing the logger.
Review Comment:
Thank you! I messed up here.
--
This is an automated message from the Apache Git Service.
To respond to the message, please log on to GitHub and use the
URL above to go to the specific comment.
To unsubscribe, e-mail: notifications-unsubscribe@zookeeper.apache.org
For queries about this service, please contact Infrastructure at:
users@infra.apache.org
Re: [PR] ZOOKEEPER-4922: Audit JAAS login, logout and Kerberos ticket renewal [zookeeper]
Posted by "anmolnar (via GitHub)" <gi...@apache.org>.
anmolnar merged PR #2473:
URL: https://github.com/apache/zookeeper/pull/2473
--
This is an automated message from the Apache Git Service.
To respond to the message, please log on to GitHub and use the
URL above to go to the specific comment.
To unsubscribe, e-mail: notifications-unsubscribe@zookeeper.apache.org
For queries about this service, please contact Infrastructure at:
users@infra.apache.org
Re: [PR] ZOOKEEPER-4922: Audit JAAS login, logout and Kerberos ticket renewal [zookeeper]
Posted by "anmolnar (via GitHub)" <gi...@apache.org>.
anmolnar commented on PR #2473:
URL: https://github.com/apache/zookeeper/pull/2473#issuecomment-6274602330
Looks like no more reviews are pending, so once the CI completes, I'll merge the patch.
--
This is an automated message from the Apache Git Service.
To respond to the message, please log on to GitHub and use the
URL above to go to the specific comment.
To unsubscribe, e-mail: notifications-unsubscribe@zookeeper.apache.org
For queries about this service, please contact Infrastructure at:
users@infra.apache.org
Re: [PR] ZOOKEEPER-4922: Audit JAAS login, logout and Kerberos ticket renewal [zookeeper]
Posted by "ikxeno (via GitHub)" <gi...@apache.org>.
ikxeno commented on code in PR #2473:
URL: https://github.com/apache/zookeeper/pull/2473#discussion_r4323261763
##########
zookeeper-server/src/main/java/org/apache/zookeeper/audit/ZKAuditProvider.java:
##########
@@ -25,29 +25,60 @@
import org.slf4j.LoggerFactory;
public class ZKAuditProvider {
- static final String AUDIT_ENABLE = "zookeeper.audit.enable";
+ /**
+ * System property that enables audit logging.
+ */
+ public static final String AUDIT_ENABLE = "zookeeper.audit.enable";
static final String AUDIT_IMPL_CLASS = "zookeeper.audit.impl.class";
private static final Logger LOG = LoggerFactory.getLogger(ZKAuditProvider.class);
- // By default audit logging is disabled
- private static boolean auditEnabled;
- private static AuditLogger auditLogger;
+ private static String selectedAuditLoggerClass;
- static {
- auditEnabled = Boolean.getBoolean(AUDIT_ENABLE);
- if (auditEnabled) {
- //initialise only when audit logging is enabled
- auditLogger = getAuditLogger();
- LOG.info("ZooKeeper audit is enabled.");
- } else {
- LOG.info("ZooKeeper audit is disabled.");
+ // Parsing server configuration must not initialize the audit logger.
+ private static class AuditState {
+ private static final boolean auditEnabled;
+ private static final AuditLogger auditLogger;
+ private static final RuntimeException initializationFailure;
+
+ static {
+ String loggerClass = null;
+ synchronized (ZKAuditProvider.class) {
+ auditEnabled = Boolean.getBoolean(AUDIT_ENABLE);
+ if (auditEnabled) {
+ loggerClass = System.getProperty(AUDIT_IMPL_CLASS, Slf4jAuditLogger.class.getName());
+ selectedAuditLoggerClass = loggerClass;
+ }
+ }
+ AuditLogger logger = null;
+ RuntimeException failure = null;
+ if (auditEnabled) {
+ try {
+ logger = getAuditLogger(loggerClass);
+ LOG.info("ZooKeeper audit is enabled.");
+ } catch (RuntimeException | LinkageError e) {
+ failure = new IllegalStateException("Couldn't initialize audit logger " + loggerClass, e);
+ }
+ } else {
+ LOG.info("ZooKeeper audit is disabled.");
+ }
+ auditLogger = logger;
+ initializationFailure = failure;
}
}
- private static AuditLogger getAuditLogger() {
- String auditLoggerClass = System.getProperty(AUDIT_IMPL_CLASS);
- if (auditLoggerClass == null) {
- auditLoggerClass = Slf4jAuditLogger.class.getName();
+ /**
+ * Configures the audit logger class without initializing the logger.
Review Comment:
This initializes the outer `ZKAuditProvider`, but not its nested `AuditState`. I checked through `QuorumPeerConfig`: the backend initializes on the first audit access, after parsing.
<details>
<summary>Reproduction results</summary>
Both property iteration orders were tested in fresh JVMs on Java 17 and 25.
```text
temurin-17.jdk / IMPL_FIRST
RESULT afterParse=0; enabled=true; afterQuery=1
temurin-17.jdk / ENABLE_FIRST
RESULT afterParse=0; enabled=true; afterQuery=1
jdk-25.jdk / IMPL_FIRST
RESULT afterParse=0; enabled=true; afterQuery=1
jdk-25.jdk / ENABLE_FIRST
RESULT afterParse=0; enabled=true; afterQuery=1
```
</details>
<details>
<summary>Reproduction code</summary>
Tested on Java 17 and 25 through the actual `QuorumPeerConfig.parseProperties()` method in `26e1b7297`.
The test controls property iteration order explicitly. It doesn't assume that line order in `zoo.cfg` determines processing order.
Save as `AuditInitializationProbe.java`:
```java
import java.nio.file.Path;
import java.util.AbstractMap;
import java.util.LinkedHashSet;
import java.util.List;
import java.util.Map;
import java.util.Properties;
import java.util.Set;
import org.apache.zookeeper.audit.AuditEvent;
import org.apache.zookeeper.audit.AuditLogger;
import org.apache.zookeeper.audit.Slf4jAuditLogger;
import org.apache.zookeeper.audit.ZKAuditProvider;
import org.apache.zookeeper.server.quorum.QuorumPeerConfig;
public class AuditInitializationProbe {
private static final String AUDIT_ENABLE_CONFIG = "audit.enable";
private static final String AUDIT_LOGGER_CONFIG = "audit.impl.class";
private static final String AUDIT_LOGGER_PROPERTY = "zookeeper." + AUDIT_LOGGER_CONFIG;
private static int initialized;
enum Variant { ORIGINAL, OUTER_STATIC_BLOCK }
enum Order { IMPL_FIRST, ENABLE_FIRST }
public static class Backend implements AuditLogger {
public void initialize() { initialized++; }
public void logAuditEvent(AuditEvent event) { }
}
private static void check(boolean condition, String message) {
if (!condition) {
throw new AssertionError(message);
}
}
public static void main(String[] args) throws Exception {
Variant variant = Variant.valueOf(args[0]);
Order order = Order.valueOf(args[1]);
List<String> auditKeys = order == Order.IMPL_FIRST
? List.of(AUDIT_LOGGER_CONFIG, AUDIT_ENABLE_CONFIG)
: List.of(AUDIT_ENABLE_CONFIG, AUDIT_LOGGER_CONFIG);
System.clearProperty(ZKAuditProvider.AUDIT_ENABLE);
System.clearProperty(AUDIT_LOGGER_PROPERTY);
Properties properties = new Properties() {
@Override
public Set<Map.Entry<Object, Object>> entrySet() {
Set<Map.Entry<Object, Object>> entries = new LinkedHashSet<>();
for (String key : auditKeys) {
entries.add(new AbstractMap.SimpleImmutableEntry<>(key, getProperty(key)));
}
for (Map.Entry<Object, Object> entry : super.entrySet()) {
if (!auditKeys.contains(entry.getKey())) {
entries.add(entry);
}
}
return entries;
}
};
properties.setProperty("dataDir", Path.of(args[2]).toString());
properties.setProperty(AUDIT_ENABLE_CONFIG, "true");
properties.setProperty(AUDIT_LOGGER_CONFIG, Backend.class.getName());
IllegalArgumentException parseFailure = null;
try {
new QuorumPeerConfig().parseProperties(properties);
} catch (IllegalArgumentException failure) {
parseFailure = failure;
}
if (variant == Variant.OUTER_STATIC_BLOCK && order == Order.ENABLE_FIRST) {
check(parseFailure != null, "Configuration unexpectedly accepted custom backend");
String message = parseFailure.getMessage();
check(message != null
&& message.contains("Audit logger is already selected as " + Slf4jAuditLogger.class.getName())
&& message.contains("cannot configure " + Backend.class.getName()),
"Unexpected parser failure: " + parseFailure);
check(initialized == 0, "Rejected custom backend was initialized");
check(ZKAuditProvider.isAuditEnabled(), "Default audit backend was not enabled");
System.out.println("RESULT parser rejected custom backend; selected=Slf4jAuditLogger");
return;
}
check(parseFailure == null, "Unexpected parser failure: " + parseFailure);
check(initialized == 0, "Parser initialized custom backend prematurely");
check(Backend.class.getName().equals(System.getProperty(AUDIT_LOGGER_PROPERTY)), "Wrong configured backend");
boolean enabled = ZKAuditProvider.isAuditEnabled();
if (variant == Variant.ORIGINAL) {
check(enabled && initialized == 1, "Configured audit backend was not initialized");
check(ZKAuditProvider.isAuditEnabled() && initialized == 1, "Audit backend initialized more than once");
} else {
check(!enabled && initialized == 0, "Outer static block did not freeze disabled state");
}
System.out.println("RESULT afterParse=0; enabled=" + enabled + "; afterQuery=" + initialized);
}
}
```
With `ZK_CP` pointing to the original build's server classes and runtime dependencies, compile and run each case in a fresh JVM. The final argument is a directory for test data.
```sh
javac -cp "$ZK_CP" -d repro-classes AuditInitializationProbe.java
java -cp "repro-classes:$ZK_CP" AuditInitializationProbe ORIGINAL IMPL_FIRST /tmp/audit-impl-first
java -cp "repro-classes:$ZK_CP" AuditInitializationProbe ORIGINAL ENABLE_FIRST /tmp/audit-enable-first
```
</details>
--
This is an automated message from the Apache Git Service.
To respond to the message, please log on to GitHub and use the
URL above to go to the specific comment.
To unsubscribe, e-mail: notifications-unsubscribe@zookeeper.apache.org
For queries about this service, please contact Infrastructure at:
users@infra.apache.org
Re: [PR] ZOOKEEPER-4922: Audit JAAS login, logout and Kerberos ticket renewal [zookeeper]
Posted by "anmolnar (via GitHub)" <gi...@apache.org>.
anmolnar commented on PR #2473:
URL: https://github.com/apache/zookeeper/pull/2473#issuecomment-6295631441
Merged to master. Thank y'all for the great work!
--
This is an automated message from the Apache Git Service.
To respond to the message, please log on to GitHub and use the
URL above to go to the specific comment.
To unsubscribe, e-mail: notifications-unsubscribe@zookeeper.apache.org
For queries about this service, please contact Infrastructure at:
users@infra.apache.org
Re: [PR] ZOOKEEPER-4922: Audit JAAS login, logout and Kerberos ticket renewal [zookeeper]
Posted by "ikxeno (via GitHub)" <gi...@apache.org>.
ikxeno commented on code in PR #2473:
URL: https://github.com/apache/zookeeper/pull/2473#discussion_r4323256383
##########
zookeeper-server/src/main/java/org/apache/zookeeper/audit/ZKAuditProvider.java:
##########
@@ -25,29 +25,60 @@
import org.slf4j.LoggerFactory;
public class ZKAuditProvider {
- static final String AUDIT_ENABLE = "zookeeper.audit.enable";
+ /**
+ * System property that enables audit logging.
+ */
+ public static final String AUDIT_ENABLE = "zookeeper.audit.enable";
static final String AUDIT_IMPL_CLASS = "zookeeper.audit.impl.class";
private static final Logger LOG = LoggerFactory.getLogger(ZKAuditProvider.class);
- // By default audit logging is disabled
- private static boolean auditEnabled;
- private static AuditLogger auditLogger;
+ private static String selectedAuditLoggerClass;
- static {
- auditEnabled = Boolean.getBoolean(AUDIT_ENABLE);
- if (auditEnabled) {
- //initialise only when audit logging is enabled
- auditLogger = getAuditLogger();
- LOG.info("ZooKeeper audit is enabled.");
- } else {
- LOG.info("ZooKeeper audit is disabled.");
+ // Parsing server configuration must not initialize the audit logger.
+ private static class AuditState {
+ private static final boolean auditEnabled;
+ private static final AuditLogger auditLogger;
+ private static final RuntimeException initializationFailure;
+
+ static {
+ String loggerClass = null;
+ synchronized (ZKAuditProvider.class) {
+ auditEnabled = Boolean.getBoolean(AUDIT_ENABLE);
+ if (auditEnabled) {
+ loggerClass = System.getProperty(AUDIT_IMPL_CLASS, Slf4jAuditLogger.class.getName());
+ selectedAuditLoggerClass = loggerClass;
+ }
+ }
+ AuditLogger logger = null;
+ RuntimeException failure = null;
+ if (auditEnabled) {
+ try {
+ logger = getAuditLogger(loggerClass);
+ LOG.info("ZooKeeper audit is enabled.");
+ } catch (RuntimeException | LinkageError e) {
+ failure = new IllegalStateException("Couldn't initialize audit logger " + loggerClass, e);
+ }
+ } else {
+ LOG.info("ZooKeeper audit is disabled.");
+ }
+ auditLogger = logger;
+ initializationFailure = failure;
}
}
- private static AuditLogger getAuditLogger() {
- String auditLoggerClass = System.getProperty(AUDIT_IMPL_CLASS);
- if (auditLoggerClass == null) {
- auditLoggerClass = Slf4jAuditLogger.class.getName();
+ /**
+ * Configures the audit logger class without initializing the logger.
Review Comment:
This initializes the outer `ZKAuditProvider`, but not its nested `AuditState`. I checked through `QuorumPeerConfig`: the backend initializes on the first audit access, after parsing.
<details>
<summary>Reproduction results</summary>
Both property iteration orders were tested in fresh JVMs on Java 17 and 25.
```text
temurin-17.jdk / IMPL_FIRST
RESULT afterParse=0; enabled=true; afterQuery=1
temurin-17.jdk / ENABLE_FIRST
RESULT afterParse=0; enabled=true; afterQuery=1
jdk-25.jdk / IMPL_FIRST
RESULT afterParse=0; enabled=true; afterQuery=1
jdk-25.jdk / ENABLE_FIRST
RESULT afterParse=0; enabled=true; afterQuery=1
```
</details>
<details>
<summary>Reproduction code</summary>
Tested on Java 17 and 25 through the actual `QuorumPeerConfig.parseProperties()` method in `26e1b7297`.
The test controls property iteration order explicitly. It doesn't assume that line order in `zoo.cfg` determines processing order.
Save as `AuditInitializationProbe.java`:
```java
import java.nio.file.Path;
import java.util.AbstractMap;
import java.util.LinkedHashSet;
import java.util.List;
import java.util.Map;
import java.util.Properties;
import java.util.Set;
import org.apache.zookeeper.audit.AuditEvent;
import org.apache.zookeeper.audit.AuditLogger;
import org.apache.zookeeper.audit.Slf4jAuditLogger;
import org.apache.zookeeper.audit.ZKAuditProvider;
import org.apache.zookeeper.server.quorum.QuorumPeerConfig;
public class AuditInitializationProbe {
private static final String AUDIT_ENABLE_CONFIG = "audit.enable";
private static final String AUDIT_LOGGER_CONFIG = "audit.impl.class";
private static final String AUDIT_LOGGER_PROPERTY = "zookeeper." + AUDIT_LOGGER_CONFIG;
private static int initialized;
enum Variant { ORIGINAL, OUTER_STATIC_BLOCK }
enum Order { IMPL_FIRST, ENABLE_FIRST }
public static class Backend implements AuditLogger {
public void initialize() { initialized++; }
public void logAuditEvent(AuditEvent event) { }
}
private static void check(boolean condition, String message) {
if (!condition) {
throw new AssertionError(message);
}
}
public static void main(String[] args) throws Exception {
Variant variant = Variant.valueOf(args[0]);
Order order = Order.valueOf(args[1]);
List<String> auditKeys = order == Order.IMPL_FIRST
? List.of(AUDIT_LOGGER_CONFIG, AUDIT_ENABLE_CONFIG)
: List.of(AUDIT_ENABLE_CONFIG, AUDIT_LOGGER_CONFIG);
System.clearProperty(ZKAuditProvider.AUDIT_ENABLE);
System.clearProperty(AUDIT_LOGGER_PROPERTY);
Properties properties = new Properties() {
@Override
public Set<Map.Entry<Object, Object>> entrySet() {
Set<Map.Entry<Object, Object>> entries = new LinkedHashSet<>();
for (String key : auditKeys) {
entries.add(new AbstractMap.SimpleImmutableEntry<>(key, getProperty(key)));
}
for (Map.Entry<Object, Object> entry : super.entrySet()) {
if (!auditKeys.contains(entry.getKey())) {
entries.add(entry);
}
}
return entries;
}
};
properties.setProperty("dataDir", Path.of(args[2]).toString());
properties.setProperty(AUDIT_ENABLE_CONFIG, "true");
properties.setProperty(AUDIT_LOGGER_CONFIG, Backend.class.getName());
IllegalArgumentException parseFailure = null;
try {
new QuorumPeerConfig().parseProperties(properties);
} catch (IllegalArgumentException failure) {
parseFailure = failure;
}
if (variant == Variant.OUTER_STATIC_BLOCK && order == Order.ENABLE_FIRST) {
check(parseFailure != null, "Configuration unexpectedly accepted custom backend");
String message = parseFailure.getMessage();
check(message != null
&& message.contains("Audit logger is already selected as " + Slf4jAuditLogger.class.getName())
&& message.contains("cannot configure " + Backend.class.getName()),
"Unexpected parser failure: " + parseFailure);
check(initialized == 0, "Rejected custom backend was initialized");
check(ZKAuditProvider.isAuditEnabled(), "Default audit backend was not enabled");
System.out.println("RESULT parser rejected custom backend; selected=Slf4jAuditLogger");
return;
}
check(parseFailure == null, "Unexpected parser failure: " + parseFailure);
check(initialized == 0, "Parser initialized custom backend prematurely");
check(Backend.class.getName().equals(System.getProperty(AUDIT_LOGGER_PROPERTY)), "Wrong configured backend");
boolean enabled = ZKAuditProvider.isAuditEnabled();
if (variant == Variant.ORIGINAL) {
check(enabled && initialized == 1, "Configured audit backend was not initialized");
check(ZKAuditProvider.isAuditEnabled() && initialized == 1, "Audit backend initialized more than once");
} else {
check(!enabled && initialized == 0, "Outer static block did not freeze disabled state");
}
System.out.println("RESULT afterParse=0; enabled=" + enabled + "; afterQuery=" + initialized);
}
}
```
With `ZK_CP` pointing to the original build's server classes and runtime dependencies, compile and run each case in a fresh JVM. The final argument is a directory for test data.
```sh
javac -cp "$ZK_CP" -d repro-classes AuditInitializationProbe.java
java -cp "repro-classes:$ZK_CP" AuditInitializationProbe ORIGINAL IMPL_FIRST /tmp/audit-impl-first
java -cp "repro-classes:$ZK_CP" AuditInitializationProbe ORIGINAL ENABLE_FIRST /tmp/audit-enable-first
```
</details>
--
This is an automated message from the Apache Git Service.
To respond to the message, please log on to GitHub and use the
URL above to go to the specific comment.
To unsubscribe, e-mail: notifications-unsubscribe@zookeeper.apache.org
For queries about this service, please contact Infrastructure at:
users@infra.apache.org
Re: [PR] ZOOKEEPER-4922: Audit JAAS login, logout and Kerberos ticket renewal [zookeeper]
Posted by "anmolnar (via GitHub)" <gi...@apache.org>.
anmolnar commented on code in PR #2473:
URL: https://github.com/apache/zookeeper/pull/2473#discussion_r4275988530
##########
zookeeper-server/src/main/java/org/apache/zookeeper/audit/ZKAuditProvider.java:
##########
@@ -25,29 +25,52 @@
import org.slf4j.LoggerFactory;
public class ZKAuditProvider {
- static final String AUDIT_ENABLE = "zookeeper.audit.enable";
+ /**
+ * System property that enables audit logging.
+ */
+ public static final String AUDIT_ENABLE = "zookeeper.audit.enable";
static final String AUDIT_IMPL_CLASS = "zookeeper.audit.impl.class";
private static final Logger LOG = LoggerFactory.getLogger(ZKAuditProvider.class);
- // By default audit logging is disabled
- private static boolean auditEnabled;
- private static AuditLogger auditLogger;
+ private static String selectedAuditLoggerClass;
+
+ // Parsing server configuration must not initialize the audit logger.
Review Comment:
Why?
> An embedded server now rejects a different logger class after selection; configuring the same class again is allowed.
Is this issue covered by the original ticket or do you address it in this patch as an extra?
--
This is an automated message from the Apache Git Service.
To respond to the message, please log on to GitHub and use the
URL above to go to the specific comment.
To unsubscribe, e-mail: notifications-unsubscribe@zookeeper.apache.org
For queries about this service, please contact Infrastructure at:
users@infra.apache.org
Re: [PR] ZOOKEEPER-4922: Audit JAAS login, logout and Kerberos ticket renewal [zookeeper]
Posted by "ikxeno (via GitHub)" <gi...@apache.org>.
ikxeno commented on code in PR #2473:
URL: https://github.com/apache/zookeeper/pull/2473#discussion_r4277264037
##########
zookeeper-server/src/main/java/org/apache/zookeeper/audit/ZKAuditProvider.java:
##########
@@ -25,29 +25,52 @@
import org.slf4j.LoggerFactory;
public class ZKAuditProvider {
- static final String AUDIT_ENABLE = "zookeeper.audit.enable";
+ /**
+ * System property that enables audit logging.
+ */
+ public static final String AUDIT_ENABLE = "zookeeper.audit.enable";
static final String AUDIT_IMPL_CLASS = "zookeeper.audit.impl.class";
private static final Logger LOG = LoggerFactory.getLogger(ZKAuditProvider.class);
- // By default audit logging is disabled
- private static boolean auditEnabled;
- private static AuditLogger auditLogger;
+ private static String selectedAuditLoggerClass;
+
+ // Parsing server configuration must not initialize the audit logger.
Review Comment:
This isn't explicitly requested by the ticket. I added it for the client-before-embedded-server scenario covered by the tests. With this patch, an audited client login can select the JVM’s logger before the server reads its config. If the server then requests a different audit.impl.class, that setting would be silently ignored. The check reports that conflict; configuring the same class still works.
--
This is an automated message from the Apache Git Service.
To respond to the message, please log on to GitHub and use the
URL above to go to the specific comment.
To unsubscribe, e-mail: notifications-unsubscribe@zookeeper.apache.org
For queries about this service, please contact Infrastructure at:
users@infra.apache.org
Re: [PR] ZOOKEEPER-4922: Audit JAAS login, logout and Kerberos ticket renewal [zookeeper]
Posted by "ikxeno (via GitHub)" <gi...@apache.org>.
ikxeno commented on PR #2473:
URL: https://github.com/apache/zookeeper/pull/2473#issuecomment-6288658981
> We probably should make audit logger an field of some runtime env to eliminate those dirty checks. It is a good anyway.
Good suggestion, I can pick that up in the next few days. Thanks for the review🙏
--
This is an automated message from the Apache Git Service.
To respond to the message, please log on to GitHub and use the
URL above to go to the specific comment.
To unsubscribe, e-mail: notifications-unsubscribe@zookeeper.apache.org
For queries about this service, please contact Infrastructure at:
users@infra.apache.org
Re: [PR] ZOOKEEPER-4922: Audit JAAS login, logout and Kerberos ticket renewal [zookeeper]
Posted by "ikxeno (via GitHub)" <gi...@apache.org>.
ikxeno commented on PR #2473:
URL: https://github.com/apache/zookeeper/pull/2473#issuecomment-6197231604
Thanks, Andor, for your time and the careful review.
I've updated the description to match the reduced tests. I kept the tests as they are: both exception types exercise the same handler, and the embedded-server test checks logger configuration, so build() is enough for that case.
The startup error-path fix can go separately, since it also affects master.
--
This is an automated message from the Apache Git Service.
To respond to the message, please log on to GitHub and use the
URL above to go to the specific comment.
To unsubscribe, e-mail: notifications-unsubscribe@zookeeper.apache.org
For queries about this service, please contact Infrastructure at:
users@infra.apache.org
Re: [PR] ZOOKEEPER-4922: Audit JAAS login, logout and Kerberos ticket renewal [zookeeper]
Posted by "ikxeno (via GitHub)" <gi...@apache.org>.
ikxeno commented on PR #2473:
URL: https://github.com/apache/zookeeper/pull/2473#issuecomment-6213924166
I ended up including the exit-code fix here after all. While checking it, I found that autopurge could delete old snapshots before startup failed on a broken audit logger. That ordering predates this PR. Both CLI and embedded startup now check auditing before starting purge.
--
This is an automated message from the Apache Git Service.
To respond to the message, please log on to GitHub and use the
URL above to go to the specific comment.
To unsubscribe, e-mail: notifications-unsubscribe@zookeeper.apache.org
For queries about this service, please contact Infrastructure at:
users@infra.apache.org
Re: [PR] ZOOKEEPER-4922: Audit JAAS login, logout and Kerberos ticket renewal [zookeeper]
Posted by "anmolnar (via GitHub)" <gi...@apache.org>.
anmolnar commented on PR #2473:
URL: https://github.com/apache/zookeeper/pull/2473#issuecomment-6195952737
Thanks for the quick response. Here're a few new comments, but all of them are nitpicks, we can merge w/o addressing them:
**New issue**
- **The failure-path audit call can throw.** QuorumPeerMain.main and ZooKeeperServerMain.main catch the startup exception and then call ZKAuditProvider.addServerStartFailureAuditLog(). That method calls isAuditEnabled(), which now throws again inside the catch block. As a result, requestSystemExit(ExitCode...) is skipped and main ends with an uncaught exception instead of the intended exit code. It’s only cosmetic: the JVM still exits non-zero and the cause gets logged twice. Master had the same problem in a different form (ExceptionInInitializerError escaping main), so this isn’t a regression. Still, wrapping addServerStartFailureAuditLog() in a try/catch is a one-line fix.
**Test nits**
- The `LinkageError` parameterization was dropped from the failure-path tests (failed login, logout and renewal). Only the successful-login test still checks it. The code path is the same, so the risk is low, but it is less coverage than the PR description claims.
- `testEmbeddedServerAcceptsSelectedAuditLogger` lost its serverStart assertion. It now only checks that build() doesn’t throw.
--
This is an automated message from the Apache Git Service.
To respond to the message, please log on to GitHub and use the
URL above to go to the specific comment.
To unsubscribe, e-mail: notifications-unsubscribe@zookeeper.apache.org
For queries about this service, please contact Infrastructure at:
users@infra.apache.org
Re: [PR] ZOOKEEPER-4922: Audit JAAS login, logout and Kerberos ticket renewal [zookeeper]
Posted by "anmolnar (via GitHub)" <gi...@apache.org>.
anmolnar commented on PR #2473:
URL: https://github.com/apache/zookeeper/pull/2473#issuecomment-6178156474
Claude's comments on the patch:
**1. Scope may not match what auditors expect.**
These events record the local process logging in with its own keytab or JAAS section. They don’t cover inbound client or learner SASL authentication failures on the server. Someone reading “authentication failures have no audit event” will probably assume they now get failed-client-auth auditing, and they won’t. The PR description and docs should say so explicitly.
**2. The user field is misleading for non-Kerberos logins.**
With DigestLoginModule (quorum or client DIGEST-MD5), the subject has no KerberosPrincipal, so the event logs the OS user (Login.SYSTEM_USER), not the JAAS username. LoginAuditInitializationTest asserts exactly this. An audit line that names someone other than the identity that authenticated is worse than no name. I’d either use the digest username or log something like <os-user> explicitly.
**3. Failures in the audit logger now surface later and less clearly.**
Before, a broken audit.impl.class failed the server at startup with “Couldn’t instantiate X”. Now, if a client Login in the same JVM triggers initialization first, the ExceptionInInitializerError is swallowed and logged. Every later isAuditEnabled() call then throws NoClassDefFoundError, including the calls in AuditHelper on the request path. This only affects embedded-server setups, but the resulting error is hard to diagnose. Consider remembering the initialization failure and rethrowing a clear exception from isAuditEnabled() or at server start.
**4. Renewal events are counted per attempt, not per renewal.**
The kinit loop audits every failed attempt, retries included. A single renewal that fails three times before succeeding produces three failure lines and one success line. It’s documented, but SIEM-style alerting may read that as four separate renewals. Worth agreeing on deliberately.
**5. Relogin produces a pair of events.**
A successful relogin emits logout success followed by ticketRenewal success. The docs explain this, but anyone counting logouts will be thrown off. An alternative is to drop the inner logout event during relogin.
**6. Backports aren’t trivial.**
The pattern-matching instanceof requires Java 16+, which is fine on master (release 17) but won’t compile on branch-3.9. The new public API (configureAuditLogger, public log(user, op, result), public AUDIT_ENABLE) is also a 3.10-only surface to keep in mind.
**7. The tests are heavy.** The tests use reflection on the private reLogin(), static mutable flags in the test login module and logger, and a 10-second latch in the concurrency test. They’re thorough, but some could probably be simplified with a package-private hook.
--
This is an automated message from the Apache Git Service.
To respond to the message, please log on to GitHub and use the
URL above to go to the specific comment.
To unsubscribe, e-mail: notifications-unsubscribe@zookeeper.apache.org
For queries about this service, please contact Infrastructure at:
users@infra.apache.org
Re: [PR] ZOOKEEPER-4922: Audit JAAS login, logout and Kerberos ticket renewal [zookeeper]
Posted by "ikxeno (via GitHub)" <gi...@apache.org>.
ikxeno commented on PR #2473:
URL: https://github.com/apache/zookeeper/pull/2473#issuecomment-6180614918
@anmolnar Thanks for checking this with Claude. I've made the fixes.
1. Agreed, the wording was too broad. The docs now explicitly limit this to local JAAS events, excluding incoming SASL failures.
2. Fixed DIGEST: the code now also reads the subject's username.
3. Fixed the holder issue: initialization failures are retained, and later calls and server startup report the original cause.
4. I kept per-attempt failures. Failed attempts are still useful to see when a retry succeeds.
5. I kept logout too, since re-login actually logs out of JAAS. The docs already distinguish this from a client disconnect.
7. Removed reflection, isolated JAAS test state, and trimmed 40 cases to 34. The latch was already a timeout
--
This is an automated message from the Apache Git Service.
To respond to the message, please log on to GitHub and use the
URL above to go to the specific comment.
To unsubscribe, e-mail: notifications-unsubscribe@zookeeper.apache.org
For queries about this service, please contact Infrastructure at:
users@infra.apache.org
Re: [PR] ZOOKEEPER-4922: Audit JAAS login, logout and Kerberos ticket renewal [zookeeper]
Posted by "ikxeno (via GitHub)" <gi...@apache.org>.
ikxeno commented on PR #2473:
URL: https://github.com/apache/zookeeper/pull/2473#issuecomment-6221451454
Could someone rerun the failed CI job? The [previous run](https://github.com/apache/zookeeper/actions/runs/38652593878) passed. `SaslAuthFailFipsModeTest` hit the same race seen in [#2469](https://github.com/apache/zookeeper/actions/runs/37344960164), similar to [ZOOKEEPER-1799](https://issues.apache.org/jira/browse/ZOOKEEPER-1799). I’ll file a ticket for this test.
--
This is an automated message from the Apache Git Service.
To respond to the message, please log on to GitHub and use the
URL above to go to the specific comment.
To unsubscribe, e-mail: notifications-unsubscribe@zookeeper.apache.org
For queries about this service, please contact Infrastructure at:
users@infra.apache.org
Re: [PR] ZOOKEEPER-4922: Audit JAAS login, logout and Kerberos ticket renewal [zookeeper]
Posted by "ikxeno (via GitHub)" <gi...@apache.org>.
ikxeno commented on code in PR #2473:
URL: https://github.com/apache/zookeeper/pull/2473#discussion_r4323261763
##########
zookeeper-server/src/main/java/org/apache/zookeeper/audit/ZKAuditProvider.java:
##########
@@ -25,29 +25,60 @@
import org.slf4j.LoggerFactory;
public class ZKAuditProvider {
- static final String AUDIT_ENABLE = "zookeeper.audit.enable";
+ /**
+ * System property that enables audit logging.
+ */
+ public static final String AUDIT_ENABLE = "zookeeper.audit.enable";
static final String AUDIT_IMPL_CLASS = "zookeeper.audit.impl.class";
private static final Logger LOG = LoggerFactory.getLogger(ZKAuditProvider.class);
- // By default audit logging is disabled
- private static boolean auditEnabled;
- private static AuditLogger auditLogger;
+ private static String selectedAuditLoggerClass;
- static {
- auditEnabled = Boolean.getBoolean(AUDIT_ENABLE);
- if (auditEnabled) {
- //initialise only when audit logging is enabled
- auditLogger = getAuditLogger();
- LOG.info("ZooKeeper audit is enabled.");
- } else {
- LOG.info("ZooKeeper audit is disabled.");
+ // Parsing server configuration must not initialize the audit logger.
+ private static class AuditState {
+ private static final boolean auditEnabled;
+ private static final AuditLogger auditLogger;
+ private static final RuntimeException initializationFailure;
+
+ static {
+ String loggerClass = null;
+ synchronized (ZKAuditProvider.class) {
+ auditEnabled = Boolean.getBoolean(AUDIT_ENABLE);
+ if (auditEnabled) {
+ loggerClass = System.getProperty(AUDIT_IMPL_CLASS, Slf4jAuditLogger.class.getName());
+ selectedAuditLoggerClass = loggerClass;
+ }
+ }
+ AuditLogger logger = null;
+ RuntimeException failure = null;
+ if (auditEnabled) {
+ try {
+ logger = getAuditLogger(loggerClass);
+ LOG.info("ZooKeeper audit is enabled.");
+ } catch (RuntimeException | LinkageError e) {
+ failure = new IllegalStateException("Couldn't initialize audit logger " + loggerClass, e);
+ }
+ } else {
+ LOG.info("ZooKeeper audit is disabled.");
+ }
+ auditLogger = logger;
+ initializationFailure = failure;
}
}
- private static AuditLogger getAuditLogger() {
- String auditLoggerClass = System.getProperty(AUDIT_IMPL_CLASS);
- if (auditLoggerClass == null) {
- auditLoggerClass = Slf4jAuditLogger.class.getName();
+ /**
+ * Configures the audit logger class without initializing the logger.
Review Comment:
This initializes the outer `ZKAuditProvider`, but not its nested `AuditState`. I checked through `QuorumPeerConfig`: the backend initializes on the first audit access, after parsing.
<details>
<summary>Reproduction results</summary>
Both property iteration orders were tested in fresh JVMs on Java 17 and 25.
```text
temurin-17.jdk / IMPL_FIRST
RESULT afterParse=0; enabled=true; afterQuery=1
temurin-17.jdk / ENABLE_FIRST
RESULT afterParse=0; enabled=true; afterQuery=1
jdk-25.jdk / IMPL_FIRST
RESULT afterParse=0; enabled=true; afterQuery=1
jdk-25.jdk / ENABLE_FIRST
RESULT afterParse=0; enabled=true; afterQuery=1
```
</details>
<details>
<summary>Reproduction code</summary>
Tested on Java 17 and 25 through the actual `QuorumPeerConfig.parseProperties()` method in `26e1b7297`.
The test controls property iteration order explicitly. It doesn't assume that line order in `zoo.cfg` determines processing order.
Save as `AuditInitializationProbe.java`:
```java
import java.nio.file.Path;
import java.util.AbstractMap;
import java.util.LinkedHashSet;
import java.util.List;
import java.util.Map;
import java.util.Properties;
import java.util.Set;
import org.apache.zookeeper.audit.AuditEvent;
import org.apache.zookeeper.audit.AuditLogger;
import org.apache.zookeeper.audit.Slf4jAuditLogger;
import org.apache.zookeeper.audit.ZKAuditProvider;
import org.apache.zookeeper.server.quorum.QuorumPeerConfig;
public class AuditInitializationProbe {
private static final String AUDIT_ENABLE_CONFIG = "audit.enable";
private static final String AUDIT_LOGGER_CONFIG = "audit.impl.class";
private static final String AUDIT_LOGGER_PROPERTY = "zookeeper." + AUDIT_LOGGER_CONFIG;
private static int initialized;
enum Variant { ORIGINAL, OUTER_STATIC_BLOCK }
enum Order { IMPL_FIRST, ENABLE_FIRST }
public static class Backend implements AuditLogger {
public void initialize() { initialized++; }
public void logAuditEvent(AuditEvent event) { }
}
private static void check(boolean condition, String message) {
if (!condition) {
throw new AssertionError(message);
}
}
public static void main(String[] args) throws Exception {
Variant variant = Variant.valueOf(args[0]);
Order order = Order.valueOf(args[1]);
List<String> auditKeys = order == Order.IMPL_FIRST
? List.of(AUDIT_LOGGER_CONFIG, AUDIT_ENABLE_CONFIG)
: List.of(AUDIT_ENABLE_CONFIG, AUDIT_LOGGER_CONFIG);
System.clearProperty(ZKAuditProvider.AUDIT_ENABLE);
System.clearProperty(AUDIT_LOGGER_PROPERTY);
Properties properties = new Properties() {
@Override
public Set<Map.Entry<Object, Object>> entrySet() {
Set<Map.Entry<Object, Object>> entries = new LinkedHashSet<>();
for (String key : auditKeys) {
entries.add(new AbstractMap.SimpleImmutableEntry<>(key, getProperty(key)));
}
for (Map.Entry<Object, Object> entry : super.entrySet()) {
if (!auditKeys.contains(entry.getKey())) {
entries.add(entry);
}
}
return entries;
}
};
properties.setProperty("dataDir", Path.of(args[2]).toString());
properties.setProperty(AUDIT_ENABLE_CONFIG, "true");
properties.setProperty(AUDIT_LOGGER_CONFIG, Backend.class.getName());
IllegalArgumentException parseFailure = null;
try {
new QuorumPeerConfig().parseProperties(properties);
} catch (IllegalArgumentException failure) {
parseFailure = failure;
}
if (variant == Variant.OUTER_STATIC_BLOCK && order == Order.ENABLE_FIRST) {
check(parseFailure != null, "Configuration unexpectedly accepted custom backend");
String message = parseFailure.getMessage();
check(message != null
&& message.contains("Audit logger is already selected as " + Slf4jAuditLogger.class.getName())
&& message.contains("cannot configure " + Backend.class.getName()),
"Unexpected parser failure: " + parseFailure);
check(initialized == 0, "Rejected custom backend was initialized");
check(ZKAuditProvider.isAuditEnabled(), "Default audit backend was not enabled");
System.out.println("RESULT parser rejected custom backend; selected=Slf4jAuditLogger");
return;
}
check(parseFailure == null, "Unexpected parser failure: " + parseFailure);
check(initialized == 0, "Parser initialized custom backend prematurely");
check(Backend.class.getName().equals(System.getProperty(AUDIT_LOGGER_PROPERTY)), "Wrong configured backend");
boolean enabled = ZKAuditProvider.isAuditEnabled();
if (variant == Variant.ORIGINAL) {
check(enabled && initialized == 1, "Configured audit backend was not initialized");
check(ZKAuditProvider.isAuditEnabled() && initialized == 1, "Audit backend initialized more than once");
} else {
check(!enabled && initialized == 0, "Outer static block did not freeze disabled state");
}
System.out.println("RESULT afterParse=0; enabled=" + enabled + "; afterQuery=" + initialized);
}
}
```
With `ZK_CP` pointing to the original build's server classes and runtime dependencies, compile and run each case in a fresh JVM. The final argument is a directory for test data.
```sh
javac -cp "$ZK_CP" -d repro-classes AuditInitializationProbe.java
java -cp "repro-classes:$ZK_CP" AuditInitializationProbe ORIGINAL IMPL_FIRST /tmp/audit-impl-first
java -cp "repro-classes:$ZK_CP" AuditInitializationProbe ORIGINAL ENABLE_FIRST /tmp/audit-enable-first
```
</details>
--
This is an automated message from the Apache Git Service.
To respond to the message, please log on to GitHub and use the
URL above to go to the specific comment.
To unsubscribe, e-mail: notifications-unsubscribe@zookeeper.apache.org
For queries about this service, please contact Infrastructure at:
users@infra.apache.org