Skip to content

ZOOKEEPER-5111: Scope audit logging to each runtime - #2482

Open
ikxeno wants to merge 4 commits into
apache:masterfrom
ikxeno:ZOOKEEPER-5111
Open

ikxeno wants to merge 4 commits into
apache:masterfrom
ikxeno:ZOOKEEPER-5111

Conversation

@ikxeno

@ikxeno ikxeno commented Oct 24, 2026

Copy link
Copy Markdown
Contributor

The audit provider currently shares one backend and server identity across the JVM. A client can initialize that backend before an embedded server reads its configuration, so the server's logger choice depends on what ran first.

This follows up on the runtime ownership suggestion in #2473. Each client connection and server now owns an AuditContext. Server components share their context across quorum role changes and database replacement. Clients keep theirs across JAAS retries and reconnects.

Server startup validates the audit backend before starting purge, opening storage or starting listeners. Client backend failures are logged without changing the JAAS result. Audit records keep their existing format, and serverStop still runs at JVM shutdown.

This is a breaking API change for 3.10.0. It removes ZKAuditProvider, the AuditHelper.addAuditLog overloads without a context, and the static ServerCnxnFactory.getUserName(). Code using these APIs needs to migrate and be recompiled. The AuditLogger SPI and configuration keys stay the same. The documentation includes migration steps and explains how custom server bootstraps should pass the context before configuring JAAS.

The tests cover runtime isolation, startup failures, reconnects, quorum role changes and snapshot restore. Shared fixtures and parameterized cases reduce duplication and the number of test JVMs.

Keep audit settings and the selected backend with the owning client or
server. Pass the context through JAAS and request processing, and preserve
it across reconnects, quorum role changes and database replacement.

Remove the global ZKAuditProvider API. Keep startup failures auditable and
validate the server backend before purge, storage or listeners start.
Consolidate JAAS fixtures and cover context binding and runtime isolation.
Describe when clients and servers capture audit settings and initialize
their backends. Explain the setup order for custom server bootstraps.

Document the removal of the static audit API in 3.10.0 and the replacement
methods. Clarify that serverStop still describes JVM shutdown.
@ikxeno

ikxeno commented Oct 24, 2026

Copy link
Copy Markdown
Contributor Author

Hi @kezhuw, I’ve implemented the runtime-scoped audit context we discussed in #2473. Could you take a look when you have time?

Provide disabled audit contexts in quorum mocks and the Netty connection fixture to avoid null contexts during server setup.

Set the WARN threshold explicitly in the JVM pause INFO test so scheduling delays do not divert events to the WARN counter.
A single connection can be closed with a 1% probability. Accept either outcome and verify that the reported count matches the calls to close.
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.

1 participant