最終更新: 2026/07/09 17:54
JIIMA 審査用データ来歴説明書 (audit_log)
JIIMA 認証審査 (ADR-0206 スキャナ保存 · 電子取引 2 スキーム並行申請) における「削除経路の audit 完全性」設問への説明資料。audit_log 表の来歴 (列追加時期・back-fill 処理・caller 遷移) を時系列で記録する。
audit_log 表の履歴
| 時期 | イベント | 変更内容 | 根拠 ADR |
|---|---|---|---|
| ~ 2026-07-08 | Phase 0 開始前 (schema.sql 初版時) | 8 列凍結 DDL (id / tenant_id / occurred_at / actor / action / target_type / target_id / payload_json) | ADR-0203 §3.3 |
| 2026-07-08 (ADR-0225 受理) | phase / caller 2 列追加 | phase (varchar(8) NOT NULL CHECK IN ('pre-0','0','1')) + caller (text NOT NULL) + 複合 index idx_audit_log_phase_caller_action | ADR-0225 §3.3 |
| 2026-07-08 (ADR-0225 受理 · 既存行 back-fill) | 列追加時 DEFAULT で自動補正 | 既存 audit_log 行の phase='pre-0' · caller='sweep.ts' に自動補正 → 直後に DROP DEFAULT で新規 INSERT の DEFAULT 依存を封じる | ADR-0225 §3.3 |
| 2026-07-09 (ADR-0229 受理 段階分割 (a)) | audit_log の追記専用性を DB レベル強制 | REVOKE UPDATE/DELETE/TRUNCATE FROM vlt_app + FORCE ROW LEVEL SECURITY + POLICY 2 個 (SELECT/INSERT のみ許容) + role 定義 (vlt_app / vlt_schema_owner) | ADR-0229 §11 段階分割 (a) |
caller 遷移 (Phase 0 → Phase 1)
audit_log の caller 列は削除経路の実装場所を追跡する:
| 期間 | caller | 実装 file | 意味論 |
|---|---|---|---|
| ~ ADR-0225 受理以前 (Phase 0 早期) | sweep.ts | vlt/src/db/sweep.ts (ADR-0225 Phase B で削除) | all-in-one sweep 実装が INSERT していた既存行 · 列追加時 back-fill で補正 |
| ADR-0225 Phase 0 期間 | lock-transaction-boundary | vlt/src/retention-manager/lock-transaction-boundary.ts | 5 module 統合 pipeline の per-receipt tx boundary が INSERT (ADR-0225 §3.3) |
| ADR-0225 Phase 1 移送後 | event-emitter | vlt/src/audit-log/event-emitter/* (実装 SoT は ADR-0222) | VLT_AUDIT_LOG_ENABLED=true 切替と同一 PR で lock-transaction-boundary から event-emitter へ完全移送 (ADR-0225 §8 撤退条件 1) |
列追加以前の既存行の扱い: ADR-0225 §3.3 の DDL Step 1 で DEFAULT 付き ALTER で phase='pre-0' · caller='sweep.ts' に自動補正済。Step 2 で DROP DEFAULT を適用しているため、新規 INSERT (Phase 0 期間中の lock-transaction-boundary 経路 · Phase 1 移送後の event-emitter 経路) は phase / caller を明示指定する義務があり、指定漏れは DB 制約エラー (NOT NULL 違反) で即時検出される。
監査 SQL
JIIMA 審査時に来歴を証明する SQL クエリ例:
caller 分布の確認
SELECT phase, caller, COUNT(*) AS insert_count,
MIN(occurred_at) AS first_occurred_at,
MAX(occurred_at) AS last_occurred_at
FROM audit_log
WHERE action IN ('retention_sweep_delete', 'delete')
AND target_type = 'receipt'
GROUP BY phase, caller
ORDER BY first_occurred_at;
期待結果:
phase='pre-0'/caller='sweep.ts': ADR-0225 列追加以前の back-fill 済行 (occurred_at ≤ 2026-07-08 想定)phase='0'/caller='lock-transaction-boundary': ADR-0225 受理後 · Phase 0 期間中の新規 INSERTphase='1'/caller='event-emitter': Phase 1 移送 (VLT_AUDIT_LOG_ENABLED=true) 後の新規 INSERT
削除経路の完全性 (孤立検出)
-- deletion_events (retention_expired) と audit_log (retention_sweep_delete) の 1:1 対応
SELECT de.receipt_id, de.reason, de.created_at,
al.action, al.phase, al.caller
FROM deletion_events de
LEFT JOIN audit_log al
ON al.target_id = de.receipt_id
AND al.action = 'retention_sweep_delete'
WHERE de.reason = 'retention_expired'
AND al.id IS NULL; -- 孤立行 (削除記録あり · audit 記録なし) は 0 件期待
関連 SSoT
- ADR-0203 (receipts と audit_log の schema 基礎): 8 列凍結 DDL の SoT
- ADR-0225 (sweep boundary に audit_log を同梱): phase / caller 列追加 + Phase 0 経路の SoT
- ADR-0222 (append-only 監査ログ物理担保): Phase 1 event-emitter 経路の SoT
- ADR-0229 (audit_log の追記専用性 DB REVOKE + FORCE RLS): §11 段階分割 (a) の SoT
- ADR-0206 (JIIMA 認証並行申請): 本ドキュメントの consumer