Class RbacAuditStore
- Namespace
- Excalibur.AuditLogging
- Assembly
- Excalibur.AuditLogging.dll
Decorator that enforces role-based access control on audit store operations.
public sealed class RbacAuditStore : IAuditStore, IAuditWriter, IAuditQuery, IServiceProvider
- Inheritance
-
RbacAuditStore
- Implements
- Inherited Members
Remarks
This decorator implements segregation of duties for audit log access: - None/Developer: No access - SecurityAnalyst: Security events only - ComplianceOfficer: All events, read-only - Administrator: Full access including export
This decorator also implements meta-auditing - logging who accessed the audit logs.
Constructors
RbacAuditStore(IAuditStore, IServiceScopeFactory, ILogger<RbacAuditStore>)
Initializes a new instance of the RbacAuditStore class.
public RbacAuditStore(IAuditStore innerStore, IServiceScopeFactory scopeFactory, ILogger<RbacAuditStore> logger)
Parameters
innerStoreIAuditStoreThe underlying audit store to wrap.
scopeFactoryIServiceScopeFactoryThe factory this store opens a scope from on every operation, to resolve the caller's role, identity and meta-audit logger. Those three are per-caller state and are deliberately NOT constructor parameters: this store is registered with the lifetime of the store it wraps, which is a singleton, so anything held in a field here answers for one caller for the life of the process. Taking them by constructor made every meta-audit record name the first caller and made the role check -- an access control -- decide on that caller's role, and under scope validation it refused to start at all.
loggerILogger<RbacAuditStore>The logger for diagnostic output.
Remarks
A provider that reads ambient state -- claims, an IHttpContextAccessor, an async-local -- is
resolved correctly from the scope opened here, because that state flows with the call rather than
with the container scope. A provider whose identity is instead written into the caller's DI scope by
host middleware cannot be reached from a singleton at all, and reports its unattributed default here
rather than another caller's identity.
Methods
CountAsync(AuditQuery, CancellationToken)
Gets the count of audit events matching the query criteria.
public Task<long> CountAsync(AuditQuery query, CancellationToken cancellationToken)
Parameters
queryAuditQueryThe query parameters (MaxResults and Skip are ignored).
cancellationTokenCancellationTokenA token to cancel the operation.
Returns
Remarks
Confined the same way as QueryAsync(AuditQuery, CancellationToken): the count reflects only the caller's own tenant's matching events, so it does not disclose another tenant's audit volume.
A zero means no stored event matched, and carries the same obligation as an empty list from QueryAsync(AuditQuery, CancellationToken): an unservable filter throws rather than counting to zero.
Exceptions
- NotSupportedException
Thrown on the same terms as QueryAsync(AuditQuery, CancellationToken).
- UnauthorizedAccessException
Thrown when the current user lacks permission.
GetByIdAsync(string, CancellationToken)
Retrieves an audit event by its ID.
public Task<AuditEvent?> GetByIdAsync(string eventId, CancellationToken cancellationToken)
Parameters
eventIdstringThe unique identifier of the event.
cancellationTokenCancellationTokenA token to cancel the operation.
Returns
- Task<AuditEvent>
The audit event, or null if not found.
Remarks
Confined to the ambient tenant established for this store instance when the implementing IAuditStore presents ITenantScopingCapability<TContract>: an event stored under another tenant is reported as not found, never resolved. See IAuditStore for the full confinement statement.
Exceptions
- UnauthorizedAccessException
Thrown when the current user lacks permission.
GetLastEventAsync(CancellationToken)
Gets the last recorded event (for chain linking).
public Task<AuditEvent?> GetLastEventAsync(CancellationToken cancellationToken)
Parameters
cancellationTokenCancellationTokenA token to cancel the operation.
Returns
- Task<AuditEvent>
The last audit event, or null if no events exist.
Remarks
Confined the same way as QueryAsync(AuditQuery, CancellationToken): the result is the last event within the ambient tenant established for this store instance (or the untenanted partition when no tenant is resolved), never another tenant's most recent event. This member previously accepted a caller- supplied tenant id; every implementation resolved confinement from ambient state regardless of what was passed, so the parameter was removed rather than left to teach a caller a scoping belief the call never honoured.
Exceptions
- UnauthorizedAccessException
Thrown when the current user lacks permission.
QueryAsync(AuditQuery, CancellationToken)
Queries audit events based on the specified criteria.
public Task<IReadOnlyList<AuditEvent>> QueryAsync(AuditQuery query, CancellationToken cancellationToken)
Parameters
queryAuditQueryThe query parameters.
cancellationTokenCancellationTokenA token to cancel the operation.
Returns
- Task<IReadOnlyList<AuditEvent>>
A list of matching audit events.
Remarks
Confined to the ambient tenant established for this store instance when the implementing
IAuditStore presents ITenantScopingCapability<TContract>: returns none
of another tenant's audit events and every one of the caller's own that matches
query. See IAuditStore for the full confinement statement.
An empty list means no stored event matched. It never means the implementation was unable to apply a filter -- that case throws; see the remarks on IAuditQuery.
Exceptions
- NotSupportedException
Thrown when
queryfilters on a field this implementation cannot compare, naming the field.- UnauthorizedAccessException
Thrown when the current user lacks permission.
StoreAsync(AuditEvent, CancellationToken)
Stores an audit event with hash chain linking.
public Task<AuditEventId> StoreAsync(AuditEvent auditEvent, CancellationToken cancellationToken)
Parameters
auditEventAuditEventThe audit event to store.
cancellationTokenCancellationTokenA token to cancel the operation.
Returns
- Task<AuditEventId>
The stored event with assigned ID, hash, and sequence number.
Remarks
Confined to the ambient tenant established for this store instance when the implementing IAuditStore presents ITenantScopingCapability<TContract>: the stored event lands in the caller's own partition and can neither be observed by, nor collide with, another tenant's chain. See IAuditStore for the full confinement statement.
VerifyChainIntegrityAsync(DateTimeOffset, DateTimeOffset, CancellationToken)
Verifies the hash chain integrity for events in the specified range.
public Task<AuditIntegrityResult> VerifyChainIntegrityAsync(DateTimeOffset startDate, DateTimeOffset endDate, CancellationToken cancellationToken)
Parameters
startDateDateTimeOffsetThe start of the verification period.
endDateDateTimeOffsetThe end of the verification period.
cancellationTokenCancellationTokenA token to cancel the operation.
Returns
- Task<AuditIntegrityResult>
The integrity verification result.
Remarks
Verification scope is a property of the store, not of this contract. The SQL Server and PostgreSQL stores verify the chain estate-wide, enumerating each tenant-and-application partition that falls in the range. The in-memory store verifies only the ambient tenant's chain.
A result from an estate-wide store must therefore not be presented to a single tenant as evidence about that tenant's own data. A passing result states that every partition the store enumerated is intact; it does not by itself state which partitions those were.
Exceptions
- UnauthorizedAccessException
Thrown when the current user lacks permission.