pub struct AuditLog { /* private fields */ }audit only.Expand description
The audit log: the one place records are sealed.
append gives a record its chain position, the previous
record’s hash and the time, hashes it, and stores it; every few records
(see with_signer) it signs a
Checkpoint when a signer is configured.
Appends to one chain are serialised in this process. Across processes
sharing one store, the store’s refusal of a taken (chain, seq) makes the
loser re-read the head and try again, so replicas interleave on one chain
instead of forking it.
Implementations§
Source§impl AuditLog
impl AuditLog
Sourcepub fn new(store: Arc<dyn AuditStore>) -> AuditLog
pub fn new(store: Arc<dyn AuditStore>) -> AuditLog
A log over store, unsigned, recording but never refusing.
Sourcepub fn with_signer(self, signer: CheckpointSigner, every: u64) -> AuditLog
pub fn with_signer(self, signer: CheckpointSigner, every: u64) -> AuditLog
Signs a checkpoint after every every records of a chain (and on
checkpoint). Without a signer, records are still
hash-chained, but truncation of the chain’s tail cannot be detected.
Sourcepub const fn require_record(self, required: bool) -> AuditLog
pub const fn require_record(self, required: bool) -> AuditLog
Makes the log required: a call whose admission cannot be recorded is refused rather than served unrecorded.
Off by default, because it turns an outage of the audit store into an outage of the agent. Turn it on where serving an unrecorded call is the worse failure.
Sourcepub const fn is_required(&self) -> bool
pub const fn is_required(&self) -> bool
Whether require_record is on.
Sourcepub const fn is_private(&self) -> bool
pub const fn is_private(&self) -> bool
Whether what records say about people is sealed
(with_privacy, feature encryption). Always
false without the feature.
Sourcepub fn store(&self) -> &Arc<dyn AuditStore> ⓘ
pub fn store(&self) -> &Arc<dyn AuditStore> ⓘ
The store records go to.
Sourcepub fn trusted_key(&self) -> Option<TrustedKey>
pub fn trusted_key(&self) -> Option<TrustedKey>
The public key checkpoints are signed with, if any.
Sourcepub fn with_retired_key(self, key: TrustedKey) -> AuditLog
pub fn with_retired_key(self, key: TrustedKey) -> AuditLog
Also trusts key when verifying: the public key of a checkpoint
signer this log no longer signs with. After a rotation, the chain’s
earlier checkpoints carry the old key’s kid, and
verify reports them unverifiable until it is given.
Sourcepub fn trusted_keys(&self) -> Vec<TrustedKey>
pub fn trusted_keys(&self) -> Vec<TrustedKey>
Sourcepub fn failures(&self) -> u64
pub fn failures(&self) -> u64
How many records failed to be written since the log was created.
A failed append is also reported through the handler’s
Metrics::on_persistence_error
as audit_append; this counter is for deployments without metrics.
Sourcepub async fn append(&self, record: AuditRecord) -> Result<AuditRecord, A2aError>
pub async fn append(&self, record: AuditRecord) -> Result<AuditRecord, A2aError>
Seals record onto the end of its chain and stores it; returns it
sealed.
Cancellation: the chain lock is held across the store calls, and is released if this future is dropped. A drop after the store accepted the record but before this returned leaves the record stored and the chain consistent; nothing is half-written by this function.
§Errors
Returns an error when the store fails, or when the record lost the race for a position eight times in a row.
Sourcepub async fn checkpoint(&self, chain: &str) -> Result<Checkpoint, A2aError>
pub async fn checkpoint(&self, chain: &str) -> Result<Checkpoint, A2aError>
Signs a checkpoint at the current head of chain, now. Call it before
exporting, and on shutdown, so the export’s tail is covered.
§Errors
Returns an error when no signer is configured, the chain is empty, or the store fails.
Sourcepub async fn verify(&self, chain: &str) -> Result<ChainReport, A2aError>
pub async fn verify(&self, chain: &str) -> Result<ChainReport, A2aError>
Reads chain and its checkpoints back from the store and verifies
them, trusting this log’s signing key and its
retired ones.
This checks the store against itself and the key this process holds.
An auditor should verify an export with keys they hold, off this
machine: a2a audit verify.
§Errors
Returns an error when the store fails; a broken chain is a report, not an error.
Source§impl AuditLog
impl AuditLog
Sourcepub fn pending_outcomes(&self) -> usize
pub fn pending_outcomes(&self) -> usize
Records waiting for the store to take them; see
require_record.
Sourcepub fn outcomes_lost(&self) -> u64
pub fn outcomes_lost(&self) -> u64
Records a required log could not keep: the spool was full, or the
record was the one the store kept refusing. Each is a call, event or
decision whose record does not exist and which no later write will
supply; reconcile_unresolved closes
the calls among them. Zero in a healthy deployment.
Sourcepub async fn flush_pending(self: &Arc<AuditLog>) -> usize
pub async fn flush_pending(self: &Arc<AuditLog>) -> usize
Writes the spool, oldest first, until the store refuses one or none is left; returns how many remain. A drain already running counts as the records it has not yet written.
Runs in a task of its own, so dropping the caller does not stop it between the store taking a record and the spool forgetting it.
Sourcepub async fn unresolved_calls(
&self,
chain: &str,
after: u64,
older_than: Duration,
) -> Result<Vec<UnresolvedCall>, A2aError>
pub async fn unresolved_calls( &self, chain: &str, after: u64, older_than: Duration, ) -> Result<Vec<UnresolvedCall>, A2aError>
The calls of chain after position after that were admitted at least
older_than ago and have no record of how they ended.
A call is unresolved when its call.started record names a call id
that no call or call.unresolved record names, and the call is not
still running in this process or waiting in its spool. A call.started
written before call ids existed names none and is not reported.
older_than must exceed your longest request. Another replica
sharing the store may be serving a call this log cannot see, and its
start looks the same as a dead one’s until its outcome arrives.
§Errors
When the store cannot be read.
Sourcepub async fn reconcile_unresolved(
&self,
chain: &str,
after: u64,
older_than: Duration,
) -> Result<Vec<AuditRecord>, A2aError>
pub async fn reconcile_unresolved( &self, chain: &str, after: u64, older_than: Duration, ) -> Result<Vec<AuditRecord>, A2aError>
Closes every call unresolved_calls finds
with a call.unresolved record, and returns the records it wrote.
Run it at start-up, before serving, and on a schedule: it is how a crash that took records with it, or a spool that overflowed, becomes visible in the chain, so that an auditor reading it sees “the outcome of this call is not known” instead of nothing. It is safe to run twice and from several replicas: a call already closed is not closed again, and one closed twice at once reads as closed. It does not claim the call failed.
§Errors
When the store cannot be read or a record cannot be appended; the ones written before that stay written.
Source§impl AuditLog
impl AuditLog
Sourcepub fn with_privacy(self, privacy: AuditPrivacy) -> Result<AuditLog, A2aError>
pub fn with_privacy(self, privacy: AuditPrivacy) -> Result<AuditLog, A2aError>
Protects what every record written from now on says about people;
see AuditPrivacy. Records already in the store are unchanged.
§Errors
A2aError::invalid_params when the store keeps no subject keys
(AuditStore::supports_subject_keys):
records would otherwise be sealed under keys the store then loses.
Sourcepub async fn reveal(&self, record: &AuditRecord) -> Result<Revealed, A2aError>
pub async fn reveal(&self, record: &AuditRecord) -> Result<Revealed, A2aError>
record with what it seals about people opened, for an auditor.
A value under a key the store no longer holds comes back "" and is
named in Revealed::erased; that is what an erased person’s values
look like, and also what a sid altered to one no key has looks like.
A value stored in the clear is returned as it is. Neither is checked
against the chain here: verify the chain
(verify) before relying on what a record reveals.
§Errors
When the log protects nothing, the store fails, or a sealed value does not open under its person’s key: it was altered, or moved from another record or field.
Sourcepub fn digest_matches(
&self,
record: &AuditRecord,
name: &str,
content: &Value,
) -> Result<bool, A2aError>
pub fn digest_matches( &self, record: &AuditRecord, name: &str, content: &Value, ) -> Result<bool, A2aError>
Whether record’s digest named name ("message", "part.0",
"event", …) is of content, given as the JSON it was digested as.
§Errors
When the log protects nothing, the digest names an HMAC key not in
the ring, or content cannot be canonicalized.
Sourcepub async fn erase_subject(
&self,
chain: &str,
subject: &str,
by: &str,
) -> Result<Erasure, A2aError>
pub async fn erase_subject( &self, chain: &str, subject: &str, by: &str, ) -> Result<Erasure, A2aError>
Erases subject from chain at the request of by: destroys the
person’s key, so every value sealed under it stops opening, after
recording that it did (subject.erased, naming the sids and by,
itself sealed like any actor). The chain still verifies.
The record is written before the key is deleted, so a failure part
way can be retried: the key is found again and deleted, and the
erasure recorded once more. Within this process it runs under the
chain’s lock, so no append or place_hold of the
chain interleaves. Across replicas the store fences it: the keys are
deleted all together and only while no hold is placed
(AuditStore::delete_subject_keys_unless_held);
a hold another replica placed after the subject.erased record was
written is answered with a subject.erasure_refused record and an
error, and nothing is erased. Another replica’s append that had the
person’s key in hand is refused by the store and makes a new key, so a
call it records afterwards names the person under that key.
The person’s records stay linkable to each other: each carries the
same random sid. Their times, methods and ids say nothing about who
they are, but may with other data. Erasing only one chain; call it
for each tenant the person used. See AuditPrivacy for what
erasure does not reach.
§Errors
A2aError::invalid_params when the log protects nothing, or a
legal hold is placed on chain, before or during the erasure (release
it first; GDPR Art. 17(3)(e)); otherwise when the store fails.
Source§impl AuditLog
impl AuditLog
Sourcepub async fn place_hold(
&self,
chain: &str,
reason: &str,
by: &str,
) -> Result<(), A2aError>
pub async fn place_hold( &self, chain: &str, reason: &str, by: &str, ) -> Result<(), A2aError>
Places a legal hold on chain: until it is released, purge
deletes nothing from it, and erase_subject
refuses.
by is the person placing it. The hold is recorded in the chain first,
as hold.placed naming by and the reason, so a hold that was placed
is on record even if storing it then fails, and a hold on record can
be told from a chain that was only ever purged.
§Errors
Returns an error when the store fails.
Sourcepub async fn release_hold(
&self,
chain: &str,
by: &str,
) -> Result<bool, A2aError>
pub async fn release_hold( &self, chain: &str, by: &str, ) -> Result<bool, A2aError>
Releases the hold on chain; returns whether there was one.
When there was, by is recorded in the chain as hold.released
before the hold is dropped.
§Errors
Returns an error when the store fails.
Sourcepub async fn record_erasure(
&self,
chain: &str,
by: &str,
erased: Erased<'_>,
) -> Result<AuditRecord, A2aError>
pub async fn record_erasure( &self, chain: &str, by: &str, erased: Erased<'_>, ) -> Result<AuditRecord, A2aError>
Records, in chain, that by removed data from the task or
push-configuration stores, and how much.
purge_expired and erase_caller are calls on a concrete store, made
by an operator outside any request, so no audited wrapper sees them.
Call this with what they returned; the record, erasure, names by,
the scope and the counts, and for a caller the person erased in a
field that with_privacy seals under that
person’s key, so erasing the person later takes the name out of the
record too. Use the chain the product records operator actions in
(halt and erase_subject take the tenant’s).
Written after the erasure it describes, so a record is evidence that the erasure happened, not a promise that it will; a crash between the two leaves an erasure with no record, which only the operator’s own log can show.
§Errors
Returns an error when the store fails.
Sourcepub async fn purge(
&self,
retention: AuditRetention,
now_ms: i64,
) -> Result<PurgeReport, A2aError>
pub async fn purge( &self, retention: AuditRetention, now_ms: i64, ) -> Result<PurgeReport, A2aError>
Deletes, from every chain without a legal hold, the records sealed
more than retention.keep_for before now_ms (Unix milliseconds),
keeping each chain’s newest record whatever its age.
For each chain it purges, it first writes an anchor checkpoint (signed when the log has a signer) at the last record it will delete, then deletes through it. A crash between the two leaves an anchor and the records it covers, which the next purge finishes.
Purging needs a checkpoint signer. An unsigned anchor is a claim anyone who can write the store could make after deleting records themselves, so the verifier does not accept one, and a purge without a signer would leave a chain nothing can verify.
§Errors
Returns an error when the log has no signer, or when the store fails; chains already purged stay purged.
Trait Implementations§
Auto Trait Implementations§
impl !Freeze for AuditLog
impl !RefUnwindSafe for AuditLog
impl !UnwindSafe for AuditLog
impl Forget for AuditLog
impl Move for AuditLog
impl Send for AuditLog
impl Sync for AuditLog
impl Unpin for AuditLog
impl UnsafeUnpin for AuditLog
Blanket Implementations§
§impl<'a, T, E> AsTaggedExplicit<'a, E> for Twhere
T: 'a,
impl<'a, T, E> AsTaggedExplicit<'a, E> for Twhere
T: 'a,
§impl<'a, T, E> AsTaggedImplicit<'a, E> for Twhere
T: 'a,
impl<'a, T, E> AsTaggedImplicit<'a, E> for Twhere
T: 'a,
Source§impl<T> BorrowMut<T> for Twhere
T: ?Sized,
impl<T> BorrowMut<T> for Twhere
T: ?Sized,
Source§fn borrow_mut(&mut self) -> &mut T
fn borrow_mut(&mut self) -> &mut T
impl<ST, DT> CastableFrom<ST, Initialized, Initialized> for DT
impl<ST, DT> CastableFrom<ST, Uninit, Uninit> for DT
§impl<T> FutureExt for T
impl<T> FutureExt for T
§fn with_context(self, otel_cx: Context) -> WithContext<Self> ⓘ
fn with_context(self, otel_cx: Context) -> WithContext<Self> ⓘ
§fn with_current_context(self) -> WithContext<Self> ⓘ
fn with_current_context(self) -> WithContext<Self> ⓘ
§impl<T> Instrument for T
impl<T> Instrument for T
§fn instrument(self, span: Span) -> Instrumented<Self> ⓘ
fn instrument(self, span: Span) -> Instrumented<Self> ⓘ
§fn in_current_span(self) -> Instrumented<Self> ⓘ
fn in_current_span(self) -> Instrumented<Self> ⓘ
Source§impl<T> IntoEither for T
impl<T> IntoEither for T
Source§fn into_either(self, into_left: bool) -> Either<Self, Self> ⓘ
fn into_either(self, into_left: bool) -> Either<Self, Self> ⓘ
self into a Left variant of Either<Self, Self>
if into_left is true.
Converts self into a Right variant of Either<Self, Self>
otherwise. Read moreSource§fn into_either_with<F>(self, into_left: F) -> Either<Self, Self> ⓘ
fn into_either_with<F>(self, into_left: F) -> Either<Self, Self> ⓘ
self into a Left variant of Either<Self, Self>
if into_left(&self) returns true.
Converts self into a Right variant of Either<Self, Self>
otherwise. Read more§impl<T> IntoRequest<T> for T
impl<T> IntoRequest<T> for T
§fn into_request(self) -> Request<T>
fn into_request(self) -> Request<T>
T in a tonic::Request§impl<L> LayerExt<L> for L
impl<L> LayerExt<L> for L
§fn named_layer<S>(&self, service: S) -> Layered<<L as Layer<S>>::Service, S>where
L: Layer<S>,
fn named_layer<S>(&self, service: S) -> Layered<<L as Layer<S>>::Service, S>where
L: Layer<S>,
Layered].