Skip to main content

AuditLog

Struct AuditLog 

Source
pub struct AuditLog { /* private fields */ }
Available on crate feature 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

Source

pub fn new(store: Arc<dyn AuditStore>) -> AuditLog

A log over store, unsigned, recording but never refusing.

Source

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.

Source

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.

Source

pub const fn is_required(&self) -> bool

Whether require_record is on.

Source

pub const fn is_private(&self) -> bool

Whether what records say about people is sealed (with_privacy, feature encryption). Always false without the feature.

Source

pub fn store(&self) -> &Arc<dyn AuditStore> ⓘ

The store records go to.

Source

pub fn trusted_key(&self) -> Option<TrustedKey>

The public key checkpoints are signed with, if any.

Source

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.

Source

pub fn trusted_keys(&self) -> Vec<TrustedKey>

The keys verify trusts: the signer’s, then each retired one.

Source

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.

Source

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.

Source

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.

Source

pub async fn export(&self, chain: &str) -> Result<Vec<AuditRecord>, A2aError>

Every record of chain, in order.

§Errors

Returns an error when the store fails.

Source

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

Source

pub fn pending_outcomes(&self) -> usize

Records waiting for the store to take them; see require_record.

Source

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.

Source

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.

Source

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.

Source

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

Source

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.

Source

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.

Source

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.

Source

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

Source

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.

Source

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.

Source

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.

Source

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§

Source§

impl Debug for AuditLog

Source§

fn fmt(&self, f: &mut Formatter<'_>) -> Result<(), Error>

Formats the value using the given formatter. Read more

Auto Trait Implementations§

Blanket Implementations§

Source§

impl<T> Any for T
where T: 'static + ?Sized,

Source§

fn type_id(&self) -> TypeId

Gets the TypeId of self. Read more
§

impl<'a, T, E> AsTaggedExplicit<'a, E> for T
where T: 'a,

§

fn explicit(self, class: Class, tag: u32) -> TaggedParser<'a, Explicit, Self, E>

§

impl<'a, T, E> AsTaggedImplicit<'a, E> for T
where T: 'a,

§

fn implicit( self, class: Class, constructed: bool, tag: u32, ) -> TaggedParser<'a, Implicit, Self, E>

Source§

impl<T> Borrow<T> for T
where T: ?Sized,

Source§

fn borrow(&self) -> &T

Immutably borrows from an owned value. Read more
Source§

impl<T> BorrowMut<T> for T
where T: ?Sized,

Source§

fn borrow_mut(&mut self) -> &mut T

Mutably borrows from an owned value. Read more
§

impl<ST, DT> CastableFrom<ST, Initialized, Initialized> for DT
where ST: ?Sized, DT: ?Sized,

§

impl<ST, DT> CastableFrom<ST, Uninit, Uninit> for DT
where ST: ?Sized, DT: ?Sized,

Source§

impl<T> From<T> for T

Source§

fn from(t: T) -> T

Returns the argument unchanged.

§

impl<T> FutureExt for T

§

fn with_context(self, otel_cx: Context) -> WithContext<Self> ⓘ

Attaches the provided Context to this type, returning a WithContext wrapper. Read more
§

fn with_current_context(self) -> WithContext<Self> ⓘ

Attaches the current Context to this type, returning a WithContext wrapper. Read more
§

impl<T> Instrument for T

§

fn instrument(self, span: Span) -> Instrumented<Self> ⓘ

Instruments this type with the provided [Span], returning an Instrumented wrapper. Read more
§

fn in_current_span(self) -> Instrumented<Self> ⓘ

Instruments this type with the current Span, returning an Instrumented wrapper. Read more
Source§

impl<T, U> Into<U> for T
where U: From<T>,

Source§

fn into(self) -> U

Calls U::from(self).

That is, this conversion is whatever the implementation of From<T> for U chooses to do.

Source§

impl<T> IntoEither for T

Source§

fn into_either(self, into_left: bool) -> Either<Self, Self> ⓘ

Converts 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 more
Source§

fn into_either_with<F>(self, into_left: F) -> Either<Self, Self> ⓘ
where F: FnOnce(&Self) -> bool,

Converts 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

§

fn into_request(self) -> Request<T>

Wrap the input message T in a tonic::Request
§

impl<L> LayerExt<L> for L

§

fn named_layer<S>(&self, service: S) -> Layered<<L as Layer<S>>::Service, S>
where L: Layer<S>,

Applies the layer to a service and wraps it in [Layered].
§

impl<T> Read<Exclusive, BecauseExclusive> for T
where T: ?Sized,

Source§

impl<T> Same for T

Source§

type Output = T

Should always be Self
Source§

impl<T, U> TryFrom<U> for T
where U: Into<T>,

Source§

type Error = !

The type returned in the event of a conversion error.
Source§

fn try_from(value: U) -> Result<T, !>

Performs the conversion.
Source§

impl<T, U> TryInto<U> for T
where U: TryFrom<T>,

Source§

type Error = <U as TryFrom<T>>::Error

The type returned in the event of a conversion error.
Source§

fn try_into(self) -> Result<U, <U as TryFrom<T>>::Error>

Performs the conversion.
§

impl<V, T> VZip<V> for T
where V: MultiLane<T>,

§

fn vzip(self) -> V

§

impl<T> WithSubscriber for T

§

fn with_subscriber<S>(self, subscriber: S) -> WithDispatch<Self> ⓘ
where S: Into<Dispatch>,

Attaches the provided Subscriber to this type, returning a [WithDispatch] wrapper. Read more
§

fn with_current_subscriber(self) -> WithDispatch<Self> ⓘ

Attaches the current default Subscriber to this type, returning a [WithDispatch] wrapper. Read more