openapi: 3.1.0 info: title: Dexwize Audit Service version: 1.0.0 description: > Durable, per-tenant, hash-chained audit log (ADR-0008). Every request needs a bearer token with a tenant context. Writes are service-to-service only (audit_writer workload role, AuditWrite permission; no human role holds it). Reads need AuditRead and always return the caller's own tenant chain. servers: - url: https://api.dexwize.example security: - bearer: [] paths: /v1/audit/events: post: summary: Append an event to the caller tenant's chain (services only) operationId: appendAuditEvent parameters: - name: Idempotency-Key in: header required: false description: UUID; a retried append with the same key returns the original event with 200. schema: { type: string, format: uuid } requestBody: required: true content: application/json: schema: { $ref: '#/components/schemas/AuditEntry' } responses: '201': description: Appended content: application/json: schema: { $ref: '#/components/schemas/AuditEvent' } '200': description: Already appended under this idempotency key content: application/json: schema: { $ref: '#/components/schemas/AuditEvent' } '400': { description: 'Validation problem (field lengths, idempotency key)' } '401': { description: Missing or invalid token } '403': { description: Caller lacks AuditWrite } get: summary: Read the caller tenant's chain, oldest first, paged by sequence operationId: readAuditEvents parameters: - { name: afterSequence, in: query, required: false, schema: { type: integer, minimum: 0 } } - { name: limit, in: query, required: false, schema: { type: integer, minimum: 1, maximum: 500, default: 100 } } responses: '200': description: One page of events content: application/json: schema: { $ref: '#/components/schemas/AuditPage' } '401': { description: Missing or invalid token } '403': { description: Caller lacks AuditRead } /v1/audit/verify: get: summary: Verify the caller tenant's hash chain operationId: verifyAuditChain responses: '200': description: Verification result content: application/json: schema: { $ref: '#/components/schemas/VerifyResult' } '403': { description: Caller lacks AuditRead } /v1/audit/anchors: get: summary: Daily chain-head anchors for export to WORM storage operationId: listAuditAnchors parameters: - { name: from, in: query, required: false, description: Defaults to 30 days ago, schema: { type: string, format: date } } - { name: to, in: query, required: false, description: Defaults to today, schema: { type: string, format: date } } responses: '200': description: Anchors in the range content: application/json: schema: { type: array, items: { $ref: '#/components/schemas/AuditAnchor' } } '403': { description: Caller lacks AuditRead } /v1/audit/export: get: summary: SIEM export of the caller tenant's events (JSON lines or CEF) operationId: exportAuditEvents parameters: - { name: format, in: query, required: false, schema: { type: string, enum: [jsonl, cef], default: jsonl } } - { name: afterSequence, in: query, required: false, schema: { type: integer, minimum: 0 } } - { name: limit, in: query, required: false, schema: { type: integer, minimum: 1, maximum: 500, default: 500 } } responses: '200': description: One event per line content: application/x-ndjson: schema: { type: string } text/plain: schema: { type: string, description: CEF lines } '400': { description: Unknown format } '403': { description: Caller lacks AuditRead } /v1/audit/jit-sessions: get: summary: Just-in-time operator sessions recorded on the caller tenant (newest first) operationId: listJitSessions responses: '200': description: One summary per grant content: application/json: schema: type: array items: { $ref: '#/components/schemas/JitSessionSummary' } '403': { description: Caller lacks AuditRead } /v1/audit/jit-sessions/{grantId}: get: summary: Timeline of one JIT grant on the caller tenant operationId: getJitSession parameters: - { name: grantId, in: path, required: true, schema: { type: string, format: uuid } } responses: '200': description: Calls in order (method, route template, status, duration, request id; no bodies) content: application/json: schema: { $ref: '#/components/schemas/JitSessionTimeline' } '403': { description: Caller lacks AuditRead } '404': { description: No calls recorded for this grant on this tenant } /v1/audit/platform/tenants/{tenantId}/jit-sessions/{grantId}: get: summary: Operator console view of one grant timeline (platform session without JIT only) operationId: getPlatformJitSession parameters: - { name: tenantId, in: path, required: true, schema: { type: string, format: uuid } } - { name: grantId, in: path, required: true, schema: { type: string, format: uuid } } responses: '200': description: Calls in order content: application/json: schema: { $ref: '#/components/schemas/JitSessionTimeline' } '403': { description: Caller lacks PlatformOperate or holds a JIT token } '404': { description: No calls recorded } components: securitySchemes: bearer: { type: http, scheme: bearer, bearerFormat: JWT } schemas: JitSessionSummary: type: object required: [grantId, operator, firstCall, lastCall, calls, failures] properties: grantId: { type: string, format: uuid } operator: { type: string } firstCall: { type: string, format: date-time } lastCall: { type: string, format: date-time } calls: { type: integer } failures: { type: integer, description: Calls that returned 400 or above } JitSessionTimeline: type: object required: [tenantId, grantId, operator, calls] properties: tenantId: { type: string, format: uuid } grantId: { type: string, format: uuid } operator: { type: string } calls: type: array items: type: object required: [sequence, at, method, pathTemplate, status, durationMs, requestId] properties: sequence: { type: integer, format: int64 } at: { type: string, format: date-time } method: { type: string } pathTemplate: { type: string, description: Route template, never the raw path or query } status: { type: integer } durationMs: { type: integer, format: int64 } requestId: { type: string } AuditEntry: type: object required: [tenantId, actor, actorType, action, target] properties: tenantId: { type: string, format: uuid, description: Tenant whose chain receives the event (set by the calling service) } actor: { type: string, maxLength: 512 } actorType: { type: string, enum: [user, agent, ai, operator, system] } action: { type: string, maxLength: 512 } target: { type: string, maxLength: 512 } AuditEvent: type: object required: [id, tenantId, sequence, actor, actorType, action, target, timestamp, prevHash, hash] properties: id: { type: string, format: uuid } tenantId: { type: string, format: uuid } sequence: { type: integer, minimum: 1 } actor: { type: string } actorType: { type: string } action: { type: string } target: { type: string } timestamp: { type: string, format: date-time } prevHash: { type: string, pattern: '^[0-9a-f]{64}$' } hash: { type: string, pattern: '^[0-9a-f]{64}$', description: 'SHA-256 over prevHash and the length-prefixed canonical fields' } AuditPage: type: object required: [items] properties: items: { type: array, items: { $ref: '#/components/schemas/AuditEvent' } } nextAfterSequence: { type: [integer, 'null'], description: Pass as afterSequence for the next page; null at the end } VerifyResult: type: object required: [tenantId, count, intact] properties: tenantId: { type: string, format: uuid } count: { type: integer } intact: { type: boolean } firstBrokenIndex: { type: [integer, 'null'] } AuditAnchor: type: object required: [tenantId, day, sequence, headHash] properties: tenantId: { type: string, format: uuid } day: { type: string, format: date } sequence: { type: integer } headHash: { type: string, pattern: '^[0-9a-f]{64}$' }