Andrei Dulvac created OAK-12331:
-----------------------------------
Summary: Add an audit SPI for recording repository activity
Key: OAK-12331
URL: https://issues.apache.org/jira/browse/OAK-12331
Project: Jackrabbit Oak
Issue Type: New Feature
Components: core, core-spi, doc, security-spi
Reporter: Andrei Dulvac
Oak has no in-process mechanism for recording who called a security-relevant
API. Deployments that need a compliance trail or a SIEM feed either scrape logs
or wrap the JCR API in a layer of their own, and neither approach sees the
acting session or the commit that carried the change.
This adds a small audit SPI: an event type, a listener interface, and an
emitter service. Listeners register on the OSGi Whiteboard and are invoked
synchronously when events are produced. The SPI does not prescribe transport,
persistence, or out-of-process delivery; those stay with the listener.
Two producer paths feed one listener registry:
* Commit-attached, used by Oak-internal capture sites. Events are buffered per
session, drained after Root.commit() persists durably, and stamped with the
acting session id, user id, and commit timestamp. A failed commit drops them.
* Fire-and-forget, available to any outside bundle through the emitter service.
Events dispatch immediately on the calling thread, with no commit boundary and
no buffering.
Both converge on AuditEventListener.onEvents(...), so one listener can consume
Oak's own security events and a bundle's custom events through the same entry
point.
Scope is the SPI, the pipeline, and one set of capture sites (user-membership
changes in UserManagerImpl) to exercise it end to end. Capture sites for access
control, principals and tokens are follow-up work.
The SPI records user API calls rather than the transaction log. Changes that a
commit hook, editor or validator makes while processing a commit are not
captured. Consumers that need every node mutation should keep using
NodeStore.addObserver.
The fire-and-forget surface is open: any bundle can emit for any domain,
including Oak's own, so events are caller-asserted. Oak stamps three commit
metadata keys on the commit-attached path and strips caller-supplied values for
those same keys on dispatch, which makes their presence a reliable signal that
Oak produced the event. Allowlisting stays on the consumer side.
Module layout:
* oak-core-spi: domain-neutral SPI (event, listener, emitter, configuration
handle).
* oak-security-spi: the oak.security domain string and its type constants.
* oak-core: pipeline implementation (listener registry, per-session buffer,
drain observer, emitter, configuration component).
The pipeline sits behind a feature toggle and is off by default. With no
listener registered, capture sites short-circuit before allocating an event.
Because this is a large contribution, I will open 3 PRs in sequence:
1. Documentation: security/audit.md (consumer guide) and
security/audit-design.md (design and wiring).
2. SPI, pipeline implementation, limited oak-security capture sites and tests.
3. Full oak-security capture sites
--
This message was sent by Atlassian Jira
(v8.20.10#820010)