Skip to main content

Crate astrid_audit

Crate astrid_audit 

Source
Expand description

Astrid Audit - Chain-linked cryptographic audit logging.

This crate provides:

  • Cryptographically signed audit entries
  • Chain-linked entries (each contains hash of previous)
  • Persistent storage with SurrealKV
  • Chain integrity verification

§Security Model

Every audit entry is:

  • Signed by an ed25519 key
  • Linked to the previous entry via content hash
  • Timestamped
  • Indexed by session

The chain linking provides tamper evidence - any modification to historical entries breaks the chain and is detectable.

§Entry formats

Format v1 (the default) signs a mixed binary/JSON layout with the runtime key and is verified against the key embedded in each entry. Format v2 (entry_v2) signs a canonical CBOR body covering every field with a dedicated audit key, carries a per-chain sequence number, and is verified against a cross-signed key registry, so a rewritten chain signed under some other key no longer verifies. AuditLog::enable_entry_v2 switches a log to v2; v1 history stays as it is and is hash-linked into the v2 chains that follow it.

§Example

use astrid_audit::{AuditLog, AuditAction, AuditOutcome, AuthorizationProof};
use astrid_core::SessionId;
use astrid_crypto::KeyPair;

// Create an in-memory audit log
let runtime_key = KeyPair::generate();
let user_id = runtime_key.key_id();
let log = AuditLog::in_memory(runtime_key);

// Start a session
let session_id = SessionId::new();

// The read/write surface is async; drive it on a current-thread runtime.
// Record an action
let entry_id = log.append(
    session_id.clone(),
    AuditAction::SessionStarted {
        user_id,
        platform: "cli".to_string(),
    },
    AuthorizationProof::System {
        reason: "session start".to_string(),
    },
    AuditOutcome::success(),
).await.unwrap();

// Verify chain integrity
let result = log.verify_chain(&session_id).await.unwrap();
assert!(result.valid);

Re-exports§

pub use entry_v2::AuditActor;
pub use entry_v2::ChainStart;
pub use entry_v2::ChainVerifier;
pub use entry_v2::EntryV2Seal;
pub use entry_v2::KeyRegistry;
pub use entry_v2::KeyRegistryRecord;
pub use entry_v2::KeyRole;

Modules§

entry_v2
Audit entry format v2: canonical, fully signed entries verified against a key registry.
host_call
Host-call records written by the kernel’s host-audit lane.
prelude
Prelude module - commonly used types for convenient import.

Structs§

AuditAnchorMarkResult
Result of AuditLog::mark_anchored.
AuditAnchorWatermark
A chain’s anchored watermark.
AuditChainAnchorStatus
One chain’s anchoring state, as listed by AuditLog::anchor_status.
AuditChainHead
Committed head of one audit chain, as read by AuditLog::heads_snapshot.
AuditChainPruneState
Latest prune receipt of one chain.
AuditChainStats
Bounded O(1) accounting for the active segment of one audit chain.
AuditEntry
A single audit log entry.
AuditEntryId
Unique identifier for an audit entry (used for linking).
AuditGlobalStats
O(1) system-wide audit accounting and retention state.
AuditLog
Audit log for recording and verifying security events.
AuditPruneReceipt
Signed receipt for an omitted archive prefix.
AuditRetentionPolicy
Operator-selected bounded retention for one audit chain.
CapsuleActor
Code identity of the capsule a host-observed entry is attributed to.
ChainVerificationResult
Result of chain verification.
EntryV2Config
How to sign format-v2 entries.
LegacyAuditImportReport
Result of importing a legacy principal-home audit database.
ProviderRequestId
A provider request id taken from an HTTP response header.

Enums§

ApprovalScope
Scope of an approval.
AuditAction
Actions that can be audited.
AuditEntryFormat
Signed layout of an audit entry.
AuditError
Errors that can occur with audit logging.
AuditOutcome
Outcome of an audited action.
AuthorizationProof
How an action was authorized.
ChainIssue
An issue found during chain verification.

Traits§

AuditArchiveWriter
One archive being written.
AuditArchiver
Receives the entries a prune removes, before the prune deletes any.
AuditCapacityProvider
Supplies media-native free capacity for destructive legacy audit imports.
PrincipalUidResolver
Resolves a principal alias to its durable UID for v2 chain ids.

Type Aliases§

AuditResult
Result type for audit operations.