import A from"@contractspec/lib.ui-link";import{ChevronRight as B}from"lucide-react";import{jsx as q,jsxs as z}from"react/jsx-runtime";function F(){return z("div",{className:"space-y-8",children:[z("div",{className:"space-y-4",children:[q("h1",{className:"font-bold text-4xl",children:"Audit Logs"}),z("p",{className:"text-muted-foreground",children:["An ",q("strong",{children:"audit log"})," (also called an audit trail) is a chronological record of system activities. According to"," ",q("a",{href:"https://www.sumologic.com/glossary/audit-log/",target:"_blank",rel:"noopener noreferrer",className:"text-violet-400 hover:text-violet-300",children:"Sumo Logic"}),', audit logs "provide a detailed record of events and changes within a system, enabling organizations to track user actions, system changes, and access to sensitive data."']})]}),z("div",{className:"space-y-4",children:[q("h2",{className:"font-bold text-2xl",children:"Why audit logs matter"}),z("div",{className:"space-y-3",children:[z("div",{children:[q("h3",{className:"font-semibold text-lg",children:"Accountability"}),q("p",{className:"text-muted-foreground",children:'Audit logs answer the question "who did what, when?" This is essential for holding users and administrators accountable for their actions. If data is deleted or modified, the audit log shows exactly who made the change.'})]}),z("div",{children:[q("h3",{className:"font-semibold text-lg",children:"Security"}),q("p",{className:"text-muted-foreground",children:"Audit logs help detect and investigate security incidents. For example, if an attacker gains unauthorized access, the logs reveal which resources they accessed and what actions they performed. This information is critical for incident response and forensics."})]}),z("div",{children:[q("h3",{className:"font-semibold text-lg",children:"Compliance"}),q("p",{className:"text-muted-foreground",children:"Many regulations (GDPR, HIPAA, SOC 2, PCI DSS) require organizations to maintain audit logs. These logs must be tamper-evident, retained for a specified period, and available for inspection by auditors."})]}),z("div",{children:[q("h3",{className:"font-semibold text-lg",children:"Debugging"}),q("p",{className:"text-muted-foreground",children:"When something goes wrong in production, audit logs provide a detailed timeline of events leading up to the failure. This makes it much easier to diagnose and fix issues."})]})]})]}),z("div",{className:"space-y-4",children:[q("h2",{className:"font-bold text-2xl",children:"What ContractSpec logs"}),q("p",{className:"text-muted-foreground",children:"ContractSpec automatically logs every significant operation, including:"}),z("ul",{className:"list-inside list-disc space-y-2 text-muted-foreground",children:[z("li",{children:[q("strong",{children:"API calls"})," – Every invocation of a capability, including inputs, outputs, and the user who made the call."]}),z("li",{children:[q("strong",{children:"Policy decisions"})," – Every decision made by the"," ",q(A,{href:"/docs/safety/pdp",className:"text-violet-400 hover:text-violet-300",children:"Policy Decision Point"}),", including the rule that matched and the reason for the decision."]}),z("li",{children:[q("strong",{children:"Data access"})," – Every query to a data view, including which fields were accessed and whether any were redacted."]}),z("li",{children:[q("strong",{children:"Workflow execution"})," – Every step in a workflow, including retries, compensations, and failures."]}),z("li",{children:[q("strong",{children:"Administrative actions"})," – Spec deployments, configuration changes, user role assignments, and other privileged operations."]}),z("li",{children:[q("strong",{children:"Authentication events"})," – Login attempts, password resets, and session expirations."]})]})]}),z("div",{className:"space-y-4",children:[q("h2",{className:"font-bold text-2xl",children:"Audit log format"}),q("p",{className:"text-muted-foreground",children:"Each audit log entry is a structured JSON object containing:"}),q("div",{className:"overflow-x-auto rounded-lg border border-border bg-background/50 p-4 font-mono text-muted-foreground text-sm",children:q("pre",{children:`{
  "timestamp": "2025-11-13T14:32:15.123Z",
  "eventId": "evt_abc123",
  "eventType": "capability.invoked",
  "actor": {
    "userId": "user_xyz789",
    "role": "admin",
    "ipAddress": "203.0.113.42"
  },
  "resource": {
    "type": "capability",
    "id": "transferFunds",
    "version": "1.2.0"
  },
  "action": "execute",
  "result": "success",
  "metadata": {
    "inputs": {
      "recipient": "user_def456",
      "amount": 100.00
    },
    "outputs": {
      "transactionId": "txn_ghi789",
      "timestamp": "2025-11-13T14:32:15.456Z"
    }
  },
  "policyDecision": {
    "decision": "PERMIT",
    "ruleId": "allow-admin-transfers",
    "reason": "User has admin role"
  }
}`})})]}),z("div",{className:"space-y-4",children:[q("h2",{className:"font-bold text-2xl",children:"Storage and retention"}),q("p",{className:"text-muted-foreground",children:"Audit logs are stored in a tamper-evident append-only log. Once written, entries cannot be modified or deleted. This ensures the integrity of the audit trail."}),q("p",{className:"text-muted-foreground",children:"ContractSpec supports multiple storage backends:"}),z("ul",{className:"list-inside list-disc space-y-2 text-muted-foreground",children:[z("li",{children:[q("strong",{children:"Local file system"})," – For development and testing."]}),z("li",{children:[q("strong",{children:"Cloud object storage"})," – S3, GCS, or Azure Blob Storage for production."]}),z("li",{children:[q("strong",{children:"SIEM integration"})," – Forward logs to Splunk, Datadog, or other security information and event management systems."]})]}),q("p",{className:"text-muted-foreground",children:"You can configure retention policies to automatically archive or delete old logs after a specified period (e.g., 7 years for GDPR compliance)."})]}),z("div",{className:"space-y-4",children:[q("h2",{className:"font-bold text-2xl",children:"Querying audit logs"}),q("p",{className:"text-muted-foreground",children:"ContractSpec provides a query API for searching audit logs. You can filter by:"}),z("ul",{className:"list-inside list-disc space-y-2 text-muted-foreground",children:[q("li",{children:"Time range"}),q("li",{children:"Event type"}),q("li",{children:"Actor (user ID, role, IP address)"}),q("li",{children:"Resource (capability, data view, workflow)"}),q("li",{children:"Result (success, failure, denied)"})]}),q("p",{className:"text-muted-foreground",children:'Example query: "Show all failed login attempts from IP address 203.0.113.42 in the last 24 hours."'})]}),z("div",{className:"space-y-4",children:[q("h2",{className:"font-bold text-2xl",children:"Best practices"}),z("ul",{className:"list-inside list-disc space-y-2 text-muted-foreground",children:[z("li",{children:[q("strong",{children:"Review logs regularly"})," – Set up alerts for suspicious activity (e.g., repeated failed login attempts, unauthorized access attempts)."]}),z("li",{children:[q("strong",{children:"Protect log access"})," – Only authorized personnel should be able to view audit logs. Use role-based access control to restrict access."]}),z("li",{children:[q("strong",{children:"Retain logs long enough"})," – Check your compliance requirements and configure retention policies accordingly."]}),z("li",{children:[q("strong",{children:"Test log integrity"})," – Periodically verify that logs have not been tampered with by checking cryptographic signatures."]})]})]}),z("div",{className:"flex items-center gap-4 pt-4",children:[q(A,{href:"/docs/safety/pdp",className:"btn-ghost",children:"Previous: Policy Decision Points"}),z(A,{href:"/docs/safety/migrations",className:"btn-primary",children:["Next: Migrations ",q(B,{size:16})]})]})]})}export{F as SafetyAuditingPage};
