Skip to main content

Audit Logs

Access immutable audit logs with hash-chaining, integrity verification, and compliance-ready exports.

Overview

The immutable audit system provides cryptographically secured logging with WORM (Write Once Read Many) guarantees for compliance with financial regulations.

Source: ow-ai-backend/routes/audit_routes.py, services/immutable_audit_service.py

Compliance: SOX, HIPAA, PCI-DSS 10.2, SOC 2 AU-6, NIST AU-6/AU-7

Audit Architecture

Hash-Chaining

┌─────────────────────────────────────────────────────────────┐
│ Hash Chain Structure │
├─────────────────────────────────────────────────────────────┤
│ │
│ Record 1 Record 2 Record 3 │
│ ┌────────┐ ┌────────┐ ┌────────┐ │
│ │content │───────▶│content │───────▶│content │ │
│ │hash │ │hash │ │hash │ │
│ ├────────┤ ├────────┤ ├────────┤ │
│ │chain │───────▶│previous│───────▶│previous│ │
│ │hash │ │hash │ │hash │ │
│ └────────┘ └────────┘ └────────┘ │
│ │
│ ANY modification breaks the chain and is detectable │
└─────────────────────────────────────────────────────────────┘

Security Features

FeatureImplementation
Content HashSHA-256 of record data
Chain HashSHA-256(content_hash + previous_chain_hash)
ImmutabilityAppend-only, no updates or deletes
Integrity CheckAutomated chain verification

Viewing Audit Logs

List Audit Logs

curl "https://pilot.owkai.app/api/audit/logs?limit=100&offset=0" \
-H "Cookie: session=YOUR_SESSION_COOKIE"

Response:

{
"total": 1547,
"limit": 100,
"offset": 0,
"logs": [
{
"id": "550e8400-e29b-41d4-a716-446655440000",
"sequence_number": 1547,
"timestamp": "2025-01-15T14:30:00Z",
"event_type": "agent_action_submitted",
"actor_id": "user_123",
"resource_type": "agent_action",
"action": "create",
"risk_level": "MEDIUM"
}
]
}

Audit Log Fields

FieldDescription
idUUID primary key
sequence_numberSequential counter
timestampEvent timestamp
event_typeEvent classification
actor_idWho performed action
resource_typeWhat was affected
resource_idSpecific resource ID
actionWhat was done
outcomeSUCCESS or FAILURE
risk_levelLOW, MEDIUM, HIGH, CRITICAL
compliance_tagsApplicable frameworks

Creating Audit Entries

Log an Event

curl -X POST https://pilot.owkai.app/api/audit/log \
-H "Cookie: session=YOUR_SESSION_COOKIE" \
-H "Content-Type: application/json" \
-d '{
"event_type": "data_access",
"actor_id": "agent_financial_001",
"resource_type": "customer_data",
"resource_id": "cust_12345",
"action": "read",
"event_data": {
"fields_accessed": ["name", "email"],
"record_count": 1
},
"risk_level": "MEDIUM",
"compliance_tags": ["GDPR", "PCI"]
}'

Response:

{
"id": "550e8400-e29b-41d4-a716-446655440001",
"sequence_number": 1548,
"timestamp": "2025-01-15T14:31:00Z",
"content_hash": "a1b2c3d4e5f6...",
"status": "created"
}

Integrity Verification

Verify Chain Integrity

curl -X POST https://pilot.owkai.app/api/audit/verify-integrity \
-H "Cookie: session=YOUR_SESSION_COOKIE"

Response:

{
"id": "check_001",
"check_time": "2025-01-15T14:35:00Z",
"status": "VALID",
"total_records": 1548,
"check_duration_ms": 450,
"records_per_second": 3440
}

Verification Status

StatusDescription
VALIDAll hashes verified
TAMPEREDContent hash mismatch detected
BROKENChain hash mismatch detected

Exporting Audit Logs

Export to CSV

curl "https://pilot.owkai.app/api/audit/export/csv?\
start_date=2025-01-01T00:00:00Z&\
end_date=2025-01-31T23:59:59Z&\
event_type=agent_action_submitted" \
-H "Cookie: session=YOUR_SESSION_COOKIE" \
-o audit_export.csv

Export to PDF

curl "https://pilot.owkai.app/api/audit/export/pdf?\
start_date=2025-01-01T00:00:00Z&\
end_date=2025-01-31T23:59:59Z" \
-H "Cookie: session=YOUR_SESSION_COOKIE" \
-o audit_report.pdf

Export Filters

FilterDescriptionExample
start_dateStart timestamp (ISO)2025-01-01T00:00:00Z
end_dateEnd timestamp (ISO)2025-01-31T23:59:59Z
event_typeFilter by eventagent_action_submitted
actor_idFilter by actoruser_123
resource_typeFilter by resourcecustomer_data

CSV Columns

ColumnDescription
Sequence NumberRecord sequence
TimestampEvent time
Event TypeClassification
Actor IDWho performed
Resource TypeWhat affected
Resource IDSpecific ID
ActionWhat done
Risk LevelSeverity
Compliance TagsFrameworks
Content HashIntegrity hash
Chain HashChain integrity
Retention UntilRetention date
Legal HoldHold status
IP AddressSource IP

PDF Report Contents

  • Report metadata (generated date, user, record count)
  • Hash chain integrity status
  • Compliance framework badges
  • Formatted data table
  • Digital signature notice

Retention Policies

Compliance-Based Retention

FrameworkRetention Period
SOX7 years
HIPAA6 years
PCI-DSS1 year
GDPR6 years
CCPA3 years
FERPA5 years
Default7 years

Retention Calculation

Longest applicable period is used:

retention_until = max(
framework_retention for framework in compliance_tags
)

Audit records can be placed on legal hold:

FieldDescription
legal_holdBoolean hold status
legal_hold_byWho applied hold
legal_hold_reasonWhy held

Records on legal hold:

  • Cannot be deleted
  • Retention period extended indefinitely
  • Marked in exports

Event Types

System Events

EventDescription
user_loginUser authentication
user_logoutUser session end
user_invitedNew user added
user_removedUser disabled
user_role_updatedPermission change

Agent Events

EventDescription
agent_registeredNew agent added
agent_action_submittedAction submitted
agent_action_approvedAction approved
agent_action_deniedAction denied
agent_suspendedAgent disabled

Security Events

EventDescription
api_key_generatedNew key created
api_key_revokedKey disabled
mfa_enabledMFA activated
mfa_disabledMFA removed
policy_violationRule triggered

API Reference

EndpointMethodDescription
/api/audit/healthGETAudit system health
/api/audit/logPOSTCreate audit entry
/api/audit/logsGETList audit logs
/api/audit/verify-integrityPOSTVerify chain
/api/audit/export/csvGETExport CSV
/api/audit/export/pdfGETExport PDF

Source: ow-ai-backend/routes/audit_routes.py

Best Practices

  1. Regular verification: Run integrity checks weekly
  2. Export backups: Archive exports to cold storage
  3. Monitor anomalies: Alert on unusual event patterns
  4. Apply legal holds: Hold records for litigation
  5. Document retention: Map frameworks to data types
  6. Review exports: Verify export completeness

Troubleshooting

Integrity check shows BROKEN

Cause: Database corruption or manual modification.

Action:

  1. Identify first broken sequence number
  2. Investigate database logs
  3. Contact support for remediation

Export timeout

Cause: Large date range or high record count.

Solution: Use narrower date ranges; filter by event type.

Missing audit entries

Cause: Service interruption during event.

Solution: Check application logs; events should be idempotent.


Source: audit_routes.py, immutable_audit_service.py