{
  "id": "tutorial-audit-trail",
  "title": "Keep a tamper-proof audit trail: sign, export and verify a project's audit log",
  "description": "From an empty project to an independently verified export: grant the Audit permission, declare who holds the signing key, produce audit events, page the signed batches, manifests and checkpoints out of the Audit Log API, and check every hash and signature offline, against keys you fetched and kept yourself.",
  "category": "Audit Log",
  "order": 30,
  "image": "/assets/images/categories/card-audit.svg",
  "summary": "Follow the chapters in order to understand the chain model (events, batches, manifests, checkpoints, keys), set up an Application Agent with the Audit permission, declare the signing key through the Config API or Terraform, generate events with Capture and configuration changes, export the trail with curl and jq, verify it with a short Python script, and run it day to day: key rotation, archiving, SIEM feeds and troubleshooting.",
  "body": "<p class=\"notion pdf-download\">Download the whole tutorial, all seven chapters, as a PDF: <a href=\"/assets/downloads/tutorial-audit-trail.pdf\" class=\"fancy-link\" target=\"_blank\">tutorial-audit-trail.pdf</a>.</p>\n\n<p class=\"notion\">Every call your applications make to IndyKite leaves an <strong>audit event</strong>: a node captured, a configuration changed, a token introspected, an authorization decided, a query executed. This tutorial is about what the platform does with those events afterwards, and what you can do with them. Once a project has an Audit Signing configuration and an Event Sink that delivers its events, the platform collects them into <strong>batches</strong>, hashes and signs each batch, links the batches into a <strong>chain</strong> with signed <strong>manifests</strong>, and fixes the chain's head at intervals with signed <strong>checkpoints</strong>. The <strong>Audit Log API</strong> pages all of that out, and publishes the public keys that signed it. An export taken with it can be handed to an auditor who has no IndyKite account and checked line by line.</p>\n<p class=\"notion\">The tutorial uses nothing but <code class=\"notion\">curl</code>, <code class=\"notion\">jq</code> and a short Python script, against the regional REST API. Terraform is shown where it applies. Nothing here needs the Hub beyond the credentials you download from it.</p>\n\n<h3 class=\"\">What you will have at the end</h3>\n<ol type=\"1\" class=\"numbered-list\" start=\"1\">\n<li>A working mental model of the chain: what a batch, a manifest, a checkpoint and a <code class=\"notion\">kid</code> are, and what \"tamper-proof\" does and does not promise.</li>\n<li>An <strong>Application Agent</strong> holding the <code class=\"notion\">Audit</code> and <code class=\"notion\">Capture</code> API permissions, with a credential.</li>\n<li>An <strong>Audit Signing</strong> configuration declaring who holds the signing key, created with the Config API and declared again in Terraform, and the knowledge of what a customer-managed key in Google Cloud KMS, AWS KMS or Azure Key Vault must look like.</li>\n<li>A handful of real audit events in the project's chain: Capture upserts and the configuration changes you made.</li>\n<li>A self-contained <strong>export</strong> on disk: <code class=\"notion\">jwks.json</code>, <code class=\"notion\">manifests.jsonl</code>, <code class=\"notion\">logs.jsonl</code> and <code class=\"notion\">checkpoints.jsonl</code>.</li>\n<li>A <strong>verifier</strong> you ran yourself, which recomputed every hash, followed every link and checked every signature against the published keys.</li>\n<li>The operating habits: when to rotate a key, how to archive, how to feed a SIEM, and what each error means.</li>\n</ol>\n\n<h3 class=\"\">Prerequisites</h3>\n<ul class=\"bulleted-list\">\n<li style=\"list-style-type:disc\">An IndyKite <strong>project</strong> in the EU or US region and its GID, with a <strong>Service Account</strong> credential for the Config API. The <a href=\"/guides/guide-environment\" class=\"fancy-link\">Environment guide</a> and the <a href=\"/resources/environment-1\" class=\"fancy-link\">environment resource</a> cover creating them; chapter 2 adds what this tutorial needs on top.</li>\n<li style=\"list-style-type:disc\"><code class=\"notion\">curl</code>, <code class=\"notion\">jq</code>, and Python 3 with the <code class=\"notion\">cryptography</code> package for chapter 6.</li>\n<li style=\"list-style-type:disc\">Optional: Terraform with the IndyKite provider 0.43.0 or later for chapter 3 (0.46.0 or later for the <code class=\"notion\">Audit</code> value of <code class=\"notion\">api_permissions</code> in chapter 2), and a signing key in your own cloud KMS if you want to try a customer-managed key.</li>\n</ul>\n\n<h3 class=\"\">Who this tutorial is for</h3>\n<p class=\"notion\">Platform and security engineers who have to answer \"can we prove this log was not altered?\", compliance teams preparing an evidence package, and developers wiring IndyKite audit data into an archive or a SIEM. If you only need the API reference, the <a href=\"/guides/guide-audit-log\" class=\"fancy-link\">Audit Log API guide</a> and the <a href=\"/guides/guide-audit-signing\" class=\"fancy-link\">Audit Signing guide</a> are the shorter read; this tutorial walks the same ground end to end on a real project.</p>",
  "chapterCount": 7,
  "chapters": [
    {
      "chapter": 1,
      "title": "What a tamper-proof audit trail is",
      "description": "The chain model behind the Audit Log API: events, batches, manifests, checkpoints and signing keys, and what tamper-evidence promises.",
      "body": "<h2 class=\"\">Chapter 1: What a tamper-proof audit trail is</h2>\n\n<p class=\"notion\">A plain log can be edited after the fact: a line removed, a timestamp changed, a record inserted. An audit trail meant as evidence has to make such changes <em>detectable</em>, by someone who does not run the system and does not trust it. The IndyKite audit trail does this with three well-known ingredients: hashing, a hash chain, and digital signatures with keys whose public halves are published.</p>\n\n<h3 class=\"\">The pieces, in the order they are built</h3>\n<table class=\"simple-table\">\n<tbody>\n<tr>\n<td class=\"simple-table-header-color\"><strong>Piece</strong></td>\n<td class=\"simple-table-header-color\"><strong>What it is</strong></td>\n<td class=\"simple-table-header-color\"><strong>What it protects against</strong></td>\n</tr>\n<tr><td class=\"\"><strong>Event</strong></td><td class=\"\">One thing that happened in your project, as a JSON object with an <code class=\"notion\">eventType</code> such as <code class=\"notion\">indykite.audit.capture.upsert.node</code>, a <code class=\"notion\">time</code>, who caused it, and a typed <code class=\"notion\">data</code> payload.</td><td class=\"\">Nothing on its own. It is the raw material.</td></tr>\n<tr><td class=\"\"><strong>Batch</strong></td><td class=\"\">A JSON array of events of one project, in the order the platform received them, cut by size or by time. Its SHA-256 is the batch <code class=\"notion\">hash</code>, and that digest is signed.</td><td class=\"\">Any change inside the batch: the hash no longer matches and the signature no longer verifies.</td></tr>\n<tr><td class=\"\"><strong>Manifest</strong></td><td class=\"\">One small record per batch: the batch's <code class=\"notion\">sequence</code> (1, 2, 3, …), its <code class=\"notion\">data_hash</code>, the previous manifest's head as <code class=\"notion\">prev_hash</code>, and the new <code class=\"notion\">head_hash</code> computed from all of them. The head is signed.</td><td class=\"\">A batch removed, inserted, reordered or replaced: the chain of <code class=\"notion\">prev_hash</code> to <code class=\"notion\">head_hash</code> links breaks at that point.</td></tr>\n<tr><td class=\"\"><strong>Checkpoint</strong></td><td class=\"\">A signed statement, written at intervals: \"at this time the chain had reached this <code class=\"notion\">sequence</code> with this <code class=\"notion\">head_hash</code>\".</td><td class=\"\">The chain being quietly truncated and regrown from an earlier point: the old checkpoint still names the head that existed.</td></tr>\n<tr><td class=\"\"><strong>Key id (<code class=\"notion\">kid</code>)</strong></td><td class=\"\">The identifier of the key that made a signature, stamped on every batch, manifest and checkpoint. The public keys are served as a JWK Set.</td><td class=\"\">A forged signature: without the private key nobody can produce one that the published public key accepts.</td></tr>\n</tbody>\n</table>\n\n<p class=\"notion\">Read as a picture, the chain of one project looks like this. The orange links are the mechanism: each manifest carries the previous head as its <code class=\"notion\">prev_hash</code>, so no batch can be removed, inserted or reordered without breaking a link.</p>\n<figure class=\"image\"><img src=\"/assets/images/audit-chain.svg\" alt=\"Events are cut into batches 1, 2, 3; each batch is hashed and signed; manifest 1 has an empty prev_hash, manifest 2's prev_hash is manifest 1's head_hash, and so on; a checkpoint signs the head at sequence 3; the JWK Set publishes the public key for every kid\"/></figure>\n\n<h3 class=\"\">What \"tamper-proof\" promises</h3>\n<ul class=\"bulleted-list\">\n<li style=\"list-style-type:disc\"><strong>Detection, not prevention.</strong> Nothing stops a privileged actor from changing stored bytes. What the chain guarantees is that a change inside the exported chain shows up when it is verified: a hash mismatch, a broken link, or a signature that fails. What a valid chain does not prove is that it is complete: a chain whose tail was removed is still a valid prefix. Detecting that needs something you kept independently, such as the newest sequence and head of your previous export, or a checkpoint fetched at another time, to compare against.</li>\n<li style=\"list-style-type:disc\"><strong>Offline verification.</strong> Verification needs the export, the public keys, and the rules in chapter 6. It does not need a connection to the platform or an IndyKite account. It does need keys you trust: a party that hands you an export and the keys together could have signed both, so authenticate the JWKS independently, for example by fetching it from the API yourself and keeping it, rather than taking it from whoever supplied the export.</li>\n<li style=\"list-style-type:disc\"><strong>Lossless, for what the chain covers.</strong> The chain holds the events an Event Sink of the project delivered, in a project with an Audit Signing configuration (chapters 3 and 4 set both up); an event no sink received is not chained. Within that scope an accepted event is never dropped, and it is written to the chain once. A duplicate is possible only when a delivery is replayed long after the original, and it is then byte for byte the same; chapter 7 shows how to deduplicate.</li>\n<li style=\"list-style-type:disc\"><strong>Not a chronological guarantee.</strong> Batches are ordered by sequence, and the events inside a batch are in the order the platform received them, which is not always the order in which they happened. Every event carries its own <code class=\"notion\">time</code>, and that timestamp is what you sort by when it matters.</li>\n</ul>\n\n<h3 class=\"\">What it is not</h3>\n<table class=\"simple-table\">\n<tbody>\n<tr>\n<td class=\"simple-table-header-color\"><strong>If you want to…</strong></td>\n<td class=\"simple-table-header-color\"><strong>Use</strong></td>\n</tr>\n<tr><td class=\"\">Receive the same events as they happen, in your own Kafka, Pub/Sub, Event Grid or Service Bus</td><td class=\"\"><a href=\"/guides/guide-outbound-events\" class=\"fancy-link\">Outbound Events</a>. Same <code class=\"notion\">indykite.audit.*</code> events, pushed, unsigned, as a stream.</td></tr>\n<tr><td class=\"\">Read the decisions of a self-hosted Agent Gateway or Token Service</td><td class=\"\">Their own audit records, written to a file or webhook you configure; see the <a href=\"/guides/guide-agent-gateway#audit\" class=\"fancy-link\">Agent Gateway guide</a>.</td></tr>\n<tr><td class=\"\">Keep, export and prove the project's trail</td><td class=\"\">The <strong>Audit Log API</strong> and the <strong>Audit Signing</strong> configuration. This tutorial.</td></tr>\n</tbody>\n</table>\n\n<h3 class=\"\">The two APIs you will use</h3>\n<ul class=\"bulleted-list\">\n<li style=\"list-style-type:disc\"><strong>Config API</strong>, <code class=\"notion\">/configs/v1/audit-signings</code>, with a Service Account token: declares who manages the signing key (chapter 3).</li>\n<li style=\"list-style-type:disc\"><strong>Audit Log API</strong>, <code class=\"notion\">/audit/v1/logs</code>, <code class=\"notion\">/audit/v1/manifests</code>, <code class=\"notion\">/audit/v1/checkpoints</code> and <code class=\"notion\">/audit/.well-known/jwks.json</code>, with an Application Agent credential holding the <code class=\"notion\">Audit</code> permission: reads the trail (chapter 5).</li>\n</ul>\n<p class=\"notion\">Both live on the regional base URL of your project, <code class=\"notion\">https://eu.api.indykite.com</code> or <code class=\"notion\">https://us.api.indykite.com</code>.</p>",
      "links": {
        "html": "/tutorials/tutorial-audit-trail#chapter-1",
        "markdown": "/tutorials/tutorial-audit-trail/1.md"
      }
    },
    {
      "chapter": 2,
      "title": "Set up the agent that reads the trail",
      "description": "Create an Application Agent with the Audit and Capture permissions, mint its credential, and keep the three values every later chapter uses.",
      "body": "<h2 class=\"\">Chapter 2: Set up the agent that reads the trail</h2>\n\n<p class=\"notion\">Reading the trail is an Application Agent operation, gated by its own API permission. Writing the Audit Signing configuration is a Service Account operation. You need both credentials; this chapter makes sure you have them and records the values the rest of the tutorial reuses.</p>\n<figure class=\"image\"><img src=\"/assets/images/audit-credentials.svg\" alt=\"A Service Account token writes the Audit Signing configuration through the Config API; an Application Agent credential with the Audit permission reads its own project's logs, manifests and checkpoints and gets 403 for any other project; anyone fetches the JWK Set with no credential\"/></figure>\n\n<h3 class=\"\">Step 1: Three values for the whole tutorial</h3>\n<pre class=\"code\"><code class=\"language-Bash\">API_URL=https://eu.api.indykite.com        # or https://us.api.indykite.com, the project's region\nPROJECT_ID=\"gid:YOUR_PROJECT_GID\"\nSA_TOKEN=\"&lt;service account bearer token&gt;\"   # Config API calls</code></pre>\n<p class=\"notion\">The project GID and the Service Account token come from the environment you already have (the <a href=\"/guides/guide-environment\" class=\"fancy-link\">Environment guide</a>, or the <a href=\"/resources/environment-1\" class=\"fancy-link\">environment resource</a> if you are starting from nothing). A Service Account credential file carries a ready-to-use <code class=\"notion\">token</code> only when it was created with an expiry of at most two years; otherwise you sign the token yourself, as the <a href=\"/guides/guide-credentials\" class=\"fancy-link\">Credentials guide</a> describes.</p>\n\n<h3 class=\"\">Step 2: Create an agent with the Audit permission</h3>\n<p class=\"notion\"><code class=\"notion\">Audit</code> is a separate API permission. It is not part of any existing agent until you add it. The agent below also gets <code class=\"notion\">Capture</code>, so chapter 4 can produce events with the same credential:</p>\n<pre class=\"code\"><code class=\"language-Bash\">curl -sS -X POST \"$API_URL/configs/v1/application-agents\" \\\n  -H \"Authorization: Bearer $SA_TOKEN\" -H \"Content-Type: application/json\" \\\n  -d '{\n    \"application_id\": \"gid:YOUR_APPLICATION_GID\",\n    \"name\": \"audit-tutorial-agent\",\n    \"display_name\": \"Audit tutorial agent\",\n    \"api_permissions\": [\"Audit\", \"Capture\"]\n  }'</code></pre>\n<pre class=\"code\"><code class=\"language-JSON\">{\n  \"id\": \"gid:YOUR_APP_AGENT_GID\",\n  \"create_time\": \"2026-10-07T09:12:40Z\",\n  \"created_by\": \"gid:YOUR_SERVICE_ACCOUNT_GID\",\n  \"update_time\": \"2026-10-07T09:12:40Z\",\n  \"updated_by\": \"gid:YOUR_SERVICE_ACCOUNT_GID\"\n}</code></pre>\n<p class=\"notion\">To add the permission to an agent you already have, <code class=\"notion\">PUT /configs/v1/application-agents/{id}</code> with the full <code class=\"notion\">api_permissions</code> list, including <code class=\"notion\">Audit</code>. In Terraform it is the <code class=\"notion\">api_permissions</code> argument of <code class=\"notion\">indykite_application_agent</code>.</p>\n\n<h3 class=\"\">Step 3: Mint a credential</h3>\n<pre class=\"code\"><code class=\"language-Bash\">umask 077                                 # the file created below holds the agent's credential\ncurl -sS -X POST \"$API_URL/configs/v1/application-agent-credentials\" \\\n  -H \"Authorization: Bearer $SA_TOKEN\" -H \"Content-Type: application/json\" \\\n  -d '{\n    \"application_agent_id\": \"gid:YOUR_APP_AGENT_GID\",\n    \"display_name\": \"audit tutorial\",\n    \"expire_time\": \"2027-10-07T00:00:00Z\"\n  }' | jq -r '.application_agent_config.token' &gt; client.key\nCLIENT_KEY=$(cat client.key)\nexport API_URL PROJECT_ID CLIENT_KEY      # chapter 5 runs a script that reads these</code></pre>\n<p class=\"notion\">With an <code class=\"notion\">expire_time</code> within two years the response carries the token in <code class=\"notion\">application_agent_config.token</code>, ready for the <code class=\"notion\">X-IK-ClientKey</code> header. Treat the file like a password: the <code class=\"notion\">umask</code> makes it readable by you alone. The three values are exported because the export script in chapter 5 runs as a separate process and reads them from the environment.</p>\n\n<h3 class=\"\">Step 4: Prove the permission works</h3>\n<pre class=\"code\"><code class=\"language-Bash\">curl -sS \"$API_URL/audit/v1/manifests?project_id=$PROJECT_ID&amp;pagesize=1\" \\\n  -H \"X-IK-ClientKey: $CLIENT_KEY\"</code></pre>\n<pre class=\"code\"><code class=\"language-JSON\">{\"next_cursor\": \"\", \"has_more\": false, \"items\": []}</code></pre>\n<p class=\"notion\">An empty page with status <code class=\"notion\">200</code> is the expected answer on a fresh project: the chain has nothing in it yet. Two other answers are worth recognising now:</p>\n<table class=\"simple-table\">\n<tbody>\n<tr>\n<td class=\"simple-table-header-color\"><strong>Answer</strong></td>\n<td class=\"simple-table-header-color\"><strong>Meaning</strong></td>\n</tr>\n<tr><td class=\"\"><code class=\"notion\">401</code> <code class=\"notion\">insufficient API access level for appAgent</code></td><td class=\"\">The agent does not hold <code class=\"notion\">Audit</code>, or was granted it a moment ago. The grant is applied asynchronously; wait a little and retry before changing anything.</td></tr>\n<tr><td class=\"\"><code class=\"notion\">403</code> <code class=\"notion\">the authenticated credential does not have access to this project</code></td><td class=\"\"><code class=\"notion\">project_id</code> is not the project the credential belongs to. Every credential reads exactly one project's trail.</td></tr>\n</tbody>\n</table>\n<p class=\"notion\">The JWKS endpoint is the one call that needs no credential at all, since public keys are public by design:</p>\n<pre class=\"code\"><code class=\"language-Bash\">curl -sS \"$API_URL/audit/.well-known/jwks.json?project_id=$PROJECT_ID\" | jq '.keys[].kid'</code></pre>\n<p class=\"notion\">Keep <code class=\"notion\">API_URL</code>, <code class=\"notion\">PROJECT_ID</code>, <code class=\"notion\">SA_TOKEN</code> and <code class=\"notion\">CLIENT_KEY</code> in your shell; every command from here on uses them.</p>",
      "links": {
        "html": "/tutorials/tutorial-audit-trail#chapter-2",
        "markdown": "/tutorials/tutorial-audit-trail/2.md"
      }
    },
    {
      "chapter": 3,
      "title": "Declare who holds the signing key",
      "description": "Create the one Audit Signing configuration a project holds with the Config API, platform-managed first, then switch it to your own KMS key, read it back, declare it in Terraform, and understand what the kid on every record tells you.",
      "body": "<h2 class=\"\">Chapter 3: Declare who holds the signing key</h2>\n\n<p class=\"notion\">The <strong>Audit Signing</strong> configuration answers one question for a project: who manages the key that signs its audit records? Either the platform does, or you do, with a key that never leaves your Google Cloud KMS, AWS KMS or Azure Key Vault. It is a Config API object like Token Introspect or an event sink, so it is written with the Service Account token and can be declared in Terraform.</p>\n<p class=\"notion\">One thing to know before you start: today the platform-managed key signs every record. A customer-managed configuration is stored and validated for the upcoming customer-managed key support, and records will carry its <code class=\"notion\">kid</code> once it is used for signing. The records you export later in this tutorial therefore carry the platform key's <code class=\"notion\">kid</code>, whichever configuration you create here.</p>\n<figure class=\"image\"><img src=\"/assets/images/audit-signing-key.svg\" alt=\"Platform-managed versus customer-managed signing: in both cases the platform signs a digest and the record carries kid, alg and signature; with a customer-managed provider the digest goes to your KMS or Key Vault and only the signature comes back\"/></figure>\n\n<h3 class=\"\">Step 1: Start platform-managed</h3>\n<pre class=\"code\"><code class=\"language-Bash\">curl -sS -D headers.txt -X POST \"$API_URL/configs/v1/audit-signings\" \\\n  -H \"Authorization: Bearer $SA_TOKEN\" -H \"Content-Type: application/json\" \\\n  -d '{\n    \"name\": \"audit-signing-tutorial\",\n    \"display_name\": \"Audit signing, tutorial\",\n    \"project_id\": \"'\"$PROJECT_ID\"'\",\n    \"provider\": \"PLATFORM_MANAGED\"\n  }'\nETAG=$(awk 'tolower($1) == \"etag:\" {sub(/\\r$/, \"\", $2); print $2}' headers.txt)</code></pre>\n<pre class=\"code\"><code class=\"language-JSON\">{\n  \"id\": \"gid:YOUR_AUDIT_SIGNING_GID\",\n  \"create_time\": \"2026-10-07T09:20:05Z\",\n  \"created_by\": \"gid:YOUR_SERVICE_ACCOUNT_GID\",\n  \"update_time\": \"2026-10-07T09:20:05Z\",\n  \"updated_by\": \"gid:YOUR_SERVICE_ACCOUNT_GID\"\n}</code></pre>\n<p class=\"notion\">Three fields are enough: <code class=\"notion\">name</code> (lowercase letters, digits and hyphens, starting with a letter, immutable), <code class=\"notion\">project_id</code> and <code class=\"notion\">provider</code>. There is no default provider, so <code class=\"notion\">provider</code> is required on every create and update. Save the <code class=\"notion\">etag</code> response header: updates and deletes send it back in <code class=\"notion\">If-Match</code> so that two people editing the same configuration cannot overwrite each other.</p>\n<p class=\"notion\">This create is itself an audit event, <code class=\"notion\">indykite.audit.config.create</code>, and will be the first thing you find in the chain in chapter 5.</p>\n\n<h3 class=\"\">Step 2: Read it back</h3>\n<pre class=\"code\"><code class=\"language-Bash\">curl -sS \"$API_URL/configs/v1/audit-signings/audit-signing-tutorial?project_id=$PROJECT_ID\" \\\n  -H \"Authorization: Bearer $SA_TOKEN\" | jq .</code></pre>\n<pre class=\"code\"><code class=\"language-JSON\">{\n  \"id\": \"gid:YOUR_AUDIT_SIGNING_GID\",\n  \"name\": \"audit-signing-tutorial\",\n  \"display_name\": \"Audit signing, tutorial\",\n  \"description\": \"\",\n  \"create_time\": \"2026-10-07T09:20:05Z\",\n  \"created_by\": \"gid:YOUR_SERVICE_ACCOUNT_GID\",\n  \"update_time\": \"2026-10-07T09:20:05Z\",\n  \"updated_by\": \"gid:YOUR_SERVICE_ACCOUNT_GID\",\n  \"organization_id\": \"gid:YOUR_ORGANIZATION_GID\",\n  \"project_id\": \"gid:YOUR_PROJECT_GID\",\n  \"provider\": \"PLATFORM_MANAGED\",\n  \"key_resource\": \"\",\n  \"kid\": \"\"\n}</code></pre>\n<p class=\"notion\">A read by name needs <code class=\"notion\">project_id</code>; a read by GID does not. For a platform-managed configuration <code class=\"notion\">key_resource</code> and <code class=\"notion\">kid</code> are empty and there is no <code class=\"notion\">auth_params</code>. Listing with <code class=\"notion\">GET /configs/v1/audit-signings?project_id=…&amp;full_fetch=true</code> returns the same objects in a <code class=\"notion\">data</code> array; without <code class=\"notion\">full_fetch</code> only the metadata comes back.</p>\n\n<h3 class=\"\">Step 3: A customer-managed key</h3>\n<p class=\"notion\">Audit records are signed with ECDSA on the P-256 curve over SHA-256 digests. A key of your own therefore has to be an asymmetric EC P-256 signing key, and the platform needs permission to sign with it and read its public key. The private half never leaves your key store. Creating the configuration stores it for the upcoming support; it does not change which key signs today.</p>\n<table class=\"simple-table\">\n<tbody>\n<tr>\n<td class=\"simple-table-header-color\"><strong>Provider</strong></td>\n<td class=\"simple-table-header-color\"><strong>Create the key as</strong></td>\n<td class=\"simple-table-header-color\"><strong><code class=\"notion\">key_resource</code></strong></td>\n</tr>\n<tr><td class=\"\"><code class=\"notion\">CUSTOMER_GCP_KMS</code></td><td class=\"\">Asymmetric sign, <code class=\"notion\">EC_SIGN_P256_SHA256</code>; grant <code class=\"notion\">cloudkms.cryptoKeyVersions.useToSign</code> and <code class=\"notion\">cloudkms.cryptoKeyVersions.viewPublicKey</code></td><td class=\"\">The crypto key <strong>version</strong> name: <code class=\"notion\">projects/my-project/locations/europe-west1/keyRings/audit/cryptoKeys/signing/cryptoKeyVersions/1</code></td></tr>\n<tr><td class=\"\"><code class=\"notion\">CUSTOMER_AWS_KMS</code></td><td class=\"\">Asymmetric, <code class=\"notion\">ECC_NIST_P256</code>, sign and verify, <code class=\"notion\">ECDSA_SHA_256</code>; grant <code class=\"notion\">kms:Sign</code> and <code class=\"notion\">kms:GetPublicKey</code>, preferably to an IAM role with an external ID rather than long-term access keys</td><td class=\"\">The key ARN, whose region segment names the KMS region: <code class=\"notion\">arn:aws:kms:eu-west-1:123456789012:key/1234abcd-…</code>. Prefer the ARN to an alias.</td></tr>\n<tr><td class=\"\"><code class=\"notion\">CUSTOMER_AZURE_KEY_VAULT</code></td><td class=\"\">EC, curve P-256, <code class=\"notion\">sign</code> permitted for a service principal in the vault's tenant</td><td class=\"\">The key identifier URI: <code class=\"notion\">https://my-vault.vault.azure.net/keys/audit-signing</code> (latest version when no version segment)</td></tr>\n</tbody>\n</table>\n<p class=\"notion\">With the key in place, the configuration gains <code class=\"notion\">key_resource</code>, a <code class=\"notion\">kid</code> of your choosing, and the access material in <code class=\"notion\">auth_params</code>. Both <code class=\"notion\">key_resource</code> and <code class=\"notion\">kid</code> are required for every customer-managed provider. A project holds exactly one Audit Signing configuration: a second <code class=\"notion\">POST</code> in the same project, whatever its name, answers <code class=\"notion\">409</code> with <code class=\"notion\">audit signing config already exists in project</code>. Moving to your own key is therefore an update of the configuration from step 1, guarded by the ETag you saved there. The AWS form:</p>\n<pre class=\"code\"><code class=\"language-Bash\">curl -sS -D headers.txt -X PUT \"$API_URL/configs/v1/audit-signings/gid:YOUR_AUDIT_SIGNING_GID\" \\\n  -H \"Authorization: Bearer $SA_TOKEN\" -H \"Content-Type: application/json\" \\\n  -H \"If-Match: $ETAG\" \\\n  -d '{\n    \"display_name\": \"Audit signing with our AWS KMS key\",\n    \"provider\": \"CUSTOMER_AWS_KMS\",\n    \"key_resource\": \"arn:aws:kms:eu-west-1:123456789012:key/1234abcd-12ab-34cd-56ef-1234567890ab\",\n    \"kid\": \"audit-2026-q4\",\n    \"auth_params\": {\n      \"role_arn\": \"arn:aws:iam::123456789012:role/indykite-audit-signer\",\n      \"external_id\": \"a-value-you-generated\"\n    }\n  }'\nETAG=$(awk 'tolower($1) == \"etag:\" {sub(/\\r$/, \"\", $2); print $2}' headers.txt)</code></pre>\n<p class=\"notion\">The update replaces the whole configuration, so <code class=\"notion\">provider</code> is sent again, and the response carries a new ETag that the line above saves for step 5. Leave <code class=\"notion\">key_resource</code> out and the answer is <code class=\"notion\">422</code> with <code class=\"notion\">key_resource is required for customer-managed providers</code> in the <code class=\"notion\">errors</code> array; the same for <code class=\"notion\">kid</code>. <code class=\"notion\">auth_params</code> is write-only: read the configuration back and every value is an empty string, while the keys are preserved so you can see what was set. The key names themselves are not prescribed by the platform: this tutorial uses the IAM role pattern AWS recommends for third-party access, and the <a href=\"/guides/guide-audit-signing\" class=\"fancy-link\">Audit Signing guide</a> lists the equivalents for Google Cloud and Azure. Choose the <code class=\"notion\">kid</code> deliberately. It is the name a record signed with this key carries, and what a verifier will look for in the JWK Set, so a name that encodes the key's purpose and period, like <code class=\"notion\">audit-2026-q4</code>, pays off at rotation time.</p>\n\n<h3 class=\"\">Step 4: The same declaration in Terraform</h3>\n<p class=\"notion\">The <code class=\"notion\">indykite_audit_signing</code> resource (provider 0.43.0 or later) takes the same fields, with the provider enum in <code class=\"notion\">key_provider</code> and the project GID in <code class=\"notion\">project_id</code>:</p>\n<pre class=\"code\"><code class=\"language-HCL\"># the project's single configuration, as it stands after step 3;\n# before step 3 the same block held only name, display_name, project_id\n# and key_provider = \"PLATFORM_MANAGED\"\nresource \"indykite_audit_signing\" \"tutorial\" {\n  name         = \"audit-signing-tutorial\"\n  display_name = \"Audit signing with our AWS KMS key\"\n  project_id   = \"gid:YOUR_PROJECT_GID\"\n  key_provider = \"CUSTOMER_AWS_KMS\"\n  key_resource = \"arn:aws:kms:eu-west-1:123456789012:key/1234abcd-12ab-34cd-56ef-1234567890ab\"\n  kid          = \"audit-2026-q4\"\n  auth_params = {\n    role_arn    = var.audit_signer_role_arn\n    external_id = var.audit_signer_external_id\n  }\n}</code></pre>\n<p class=\"notion\">Because the API never returns <code class=\"notion\">auth_params</code> values, Terraform keeps the configured values in state and reconciles only the set of keys; keep them in sensitive variables. The full file, with the Google Cloud KMS form and the <code class=\"notion\">indykite_audit_signings</code> data source, is the <a href=\"/terraform/terraform-8\" class=\"fancy-link\">Audit Signing Terraform example</a>. If you created the configuration with curl in step 1 and want Terraform to own it from now on, import it by GID rather than creating it twice: a project holds one configuration and a second create answers <code class=\"notion\">409</code> with <code class=\"notion\">audit signing config already exists in project</code>. Switching providers later is an edit of this one block, never a second resource in the same project.</p>\n\n<h3 class=\"\">Step 5: Rotating, and what the trail tells you</h3>\n<p class=\"notion\">The JWK Set keeps a retired key next to the new one, so records signed before a rotation stay checkable from the API. Still keep the set that names the current key before any rotation, so your exports verify without the API. The export in chapter 5 does this for you; if you have not run it yet, fetch the set now and keep the file with your exports:</p>\n<pre class=\"code\"><code class=\"language-Bash\">curl -sS \"$API_URL/audit/.well-known/jwks.json?project_id=$PROJECT_ID\" -o \"jwks-before-rotation-$(date -u +%Y%m%dT%H%M%SZ).json\"</code></pre>\n<p class=\"notion\">Once customer-managed keys are in use, rotating one is an update: point <code class=\"notion\">key_resource</code> at the new key version and change the <code class=\"notion\">kid</code>, guarded by the configuration's current ETag. If the one saved in step 3 is gone, read the configuration again first:</p>\n<pre class=\"code\"><code class=\"language-Bash\">curl -fsS -D headers.txt -o /dev/null \\\n  -H \"Authorization: Bearer $SA_TOKEN\" \\\n  \"$API_URL/configs/v1/audit-signings/gid:YOUR_AUDIT_SIGNING_GID\"\nETAG=$(awk 'tolower($1) == \"etag:\" {sub(/\\r$/, \"\", $2); print $2}' headers.txt)\ncurl -sS -X PUT \"$API_URL/configs/v1/audit-signings/gid:YOUR_AUDIT_SIGNING_GID\" \\\n  -H \"Authorization: Bearer $SA_TOKEN\" -H \"Content-Type: application/json\" \\\n  -H \"If-Match: $ETAG\" \\\n  -d '{\n    \"provider\": \"CUSTOMER_AWS_KMS\",\n    \"key_resource\": \"arn:aws:kms:eu-west-1:123456789012:key/5678efgh-56ef-78gh-90ij-5678901234ef\",\n    \"kid\": \"audit-2027-q1\",\n    \"auth_params\": { \"role_arn\": \"arn:aws:iam::123456789012:role/indykite-audit-signer\", \"external_id\": \"a-value-you-generated\" }\n  }'</code></pre>\n<p class=\"notion\">A stale ETag answers <code class=\"notion\">412 Precondition Failed</code>: re-read, take the new ETag, retry. The update replaces the whole configuration, so <code class=\"notion\">provider</code> and the <code class=\"notion\">auth_params</code> values have to be sent again.</p>\n<p class=\"notion\">One principle to carry into the next chapters: <strong>a verifier selects the key by the <code class=\"notion\">kid</code> each record carries.</strong> Every batch, manifest and checkpoint names the key that signed it, and the JWKS endpoint publishes the public keys for those <code class=\"notion\">kid</code> values; chapter 5 reads them from the trail and chapter 6 resolves them.</p>",
      "links": {
        "html": "/tutorials/tutorial-audit-trail#chapter-3",
        "markdown": "/tutorials/tutorial-audit-trail/3.md"
      }
    },
    {
      "chapter": 4,
      "title": "Put some events into the chain",
      "description": "Produce real audit events with the Capture API and the configuration changes already made, and learn to read an event's shape before exporting hundreds of them.",
      "body": "<h2 class=\"\">Chapter 4: Put some events into the chain</h2>\n\n<p class=\"notion\">A chain with nothing in it cannot be verified, so this chapter produces a few events with calls you would make anyway. Chapter 3 already contributed configuration events; here the agent from chapter 2 captures a small graph.</p>\n\n<h3 class=\"\">Before you start: an Event Sink</h3>\n<p class=\"notion\">The chain holds exactly the events your Event Sinks received: an event is chained only after an <a href=\"/guides/guide-outbound-events\" class=\"fancy-link\">Event Sink</a> of the project delivered it to at least one destination, and only in a project with the Audit Signing configuration of chapter 3. Without a sink the calls below leave nothing on the trail. If the project has none yet, create one with a route on every audit event, to any destination you own; the example uses Kafka, the Outbound Events guide shows the Pub/Sub, Event Grid and Service Bus forms.</p>\n<pre class=\"code\"><code class=\"language-Bash\">curl -sS -X POST \"$API_URL/configs/v1/event-sinks\" \\\n  -H \"Authorization: Bearer $SA_TOKEN\" -H \"Content-Type: application/json\" \\\n  -d '{\n    \"project_id\": \"'\"$PROJECT_ID\"'\",\n    \"name\": \"audit-trail-sink\",\n    \"providers\": {\n      \"audit-kafka\": {\n        \"kafka\": {\n          \"brokers\": [\"broker.example.com:9094\"],\n          \"topic\": \"indykite-audit\",\n          \"username\": \"your-user\",\n          \"password\": \"'\"$KAFKA_PASSWORD\"'\"\n        }\n      }\n    },\n    \"routes\": [\n      {\n        \"provider_id\": \"audit-kafka\",\n        \"event_type_key_values_filter\": { \"event_type\": \"indykite.audit.*\", \"context_key_value\": [] }\n      }\n    ],\n    \"include_cdc_events\": false\n  }'</code></pre>\n<p class=\"notion\">The destination must accept the deliveries: a sink whose provider fails (see <code class=\"notion\">last_error</code> in the Outbound Events guide) stops feeding the chain as well as the sink. Events produced before the sink existed are not chained after the fact.</p>\n\n<h3 class=\"\">Step 1: Capture a small dataset</h3>\n<p class=\"notion\">The two files below describe a car rental company: five <code class=\"notion\">Customer</code> identity nodes, three <code class=\"notion\">Car</code> nodes, and the <code class=\"notion\">RENT</code> relationships between them. They are the request bodies the <a href=\"/guides/guide-data-schema\" class=\"fancy-link\">Data Schema guide</a> uses as its playground.</p>\n<ul class=\"bulleted-list\">\n<li style=\"list-style-type:disc\"><a href=\"/assets/downloads/simple-dataset-nodes.json\" class=\"fancy-link\" download=\"simple-dataset-nodes.json\">simple-dataset-nodes.json</a>, the body for <code class=\"notion\">POST /capture/v1/nodes</code></li>\n<li style=\"list-style-type:disc\"><a href=\"/assets/downloads/simple-dataset-relationships.json\" class=\"fancy-link\" download=\"simple-dataset-relationships.json\">simple-dataset-relationships.json</a>, the body for <code class=\"notion\">POST /capture/v1/relationships</code></li>\n</ul>\n<pre class=\"code\"><code class=\"language-Bash\">curl -sS -X POST \"$API_URL/capture/v1/nodes\" \\\n  -H \"X-IK-ClientKey: $CLIENT_KEY\" -H \"Content-Type: application/json\" \\\n  --data @simple-dataset-nodes.json\ncurl -sS -X POST \"$API_URL/capture/v1/relationships\" \\\n  -H \"X-IK-ClientKey: $CLIENT_KEY\" -H \"Content-Type: application/json\" \\\n  --data @simple-dataset-relationships.json</code></pre>\n<p class=\"notion\">Nodes first, then relationships, since a relationship names its two ends by type and <code class=\"notion\">external_id</code>. Both calls are upserts: re-posting the files is harmless to the graph, and each re-post adds another round of audit events, which is useful if you want a longer chain to page through later.</p>\n\n<h3 class=\"\">Step 2: What each call left behind</h3>\n<p class=\"notion\">Each captured node becomes one <code class=\"notion\">indykite.audit.capture.upsert.node</code> event, each relationship one <code class=\"notion\">indykite.audit.capture.upsert.relationship</code> event. Since the project's graph is observed by change data capture, the same writes also show up as <code class=\"notion\">indykite.audit.cdc.node.create</code> and <code class=\"notion\">indykite.audit.cdc.relationship.create</code> events. And chapter 3 left <code class=\"notion\">indykite.audit.config.create</code> events for the Audit Signing configurations, plus <code class=\"notion\">indykite.audit.config.update</code> if you rotated. The families you can expect in a project's trail:</p>\n<table class=\"simple-table\">\n<tbody>\n<tr>\n<td class=\"simple-table-header-color\"><strong>Family</strong></td>\n<td class=\"simple-table-header-color\"><strong>Recorded when</strong></td>\n<td class=\"simple-table-header-color\"><strong>Examples</strong></td>\n</tr>\n<tr><td class=\"\"><code class=\"notion\">indykite.audit.capture.*</code></td><td class=\"\">The Capture API writes or deletes graph data</td><td class=\"\"><code class=\"notion\">capture.upsert.node</code>, <code class=\"notion\">capture.upsert.relationship</code>, <code class=\"notion\">capture.delete.node</code>, <code class=\"notion\">capture.delete.node.property</code></td></tr>\n<tr><td class=\"\"><code class=\"notion\">indykite.audit.cdc.*</code></td><td class=\"\">The graph changes, whatever caused it</td><td class=\"\"><code class=\"notion\">cdc.node.create</code>, <code class=\"notion\">cdc.node.update</code>, <code class=\"notion\">cdc.node.delete</code>, <code class=\"notion\">cdc.relationship.create</code></td></tr>\n<tr><td class=\"\"><code class=\"notion\">indykite.audit.config.*</code></td><td class=\"\">A configuration object is created, read, updated, deleted or listed, or a permission assigned. A delete carries the object's state right before deletion as <code class=\"notion\">before</code>; a list carries the IDs it returned</td><td class=\"\"><code class=\"notion\">config.create</code>, <code class=\"notion\">config.update</code>, <code class=\"notion\">config.delete</code>, <code class=\"notion\">config.list</code>, <code class=\"notion\">config.permission.assign</code></td></tr>\n<tr><td class=\"\"><code class=\"notion\">indykite.audit.authorization.*</code></td><td class=\"\">An AuthZEN decision or search is made</td><td class=\"\"><code class=\"notion\">authorization.evaluation</code>, <code class=\"notion\">authorization.evaluations</code>, <code class=\"notion\">authorization.searchresource</code></td></tr>\n<tr><td class=\"\"><code class=\"notion\">indykite.audit.ciq.execute</code></td><td class=\"\">A ContX IQ Knowledge Query is executed</td><td class=\"\"><code class=\"notion\">ciq.execute</code></td></tr>\n<tr><td class=\"\"><code class=\"notion\">indykite.audit.credentials.*</code></td><td class=\"\">An end-user token is introspected</td><td class=\"\"><code class=\"notion\">credentials.token.introspected</code></td></tr>\n</tbody>\n</table>\n<p class=\"notion\">The complete list, with the fields of each payload, is in the <a href=\"/guides/guide-outbound-events\" class=\"fancy-link\">Outbound Events guide</a>; the trail carries exactly the same events.</p>\n\n<h3 class=\"\">Step 3: Read one event before reading hundreds</h3>\n<p class=\"notion\">Events reach the chain in batches, which are cut by size or by time, so give the platform a short while after the captures. Then look at the first batch:</p>\n<pre class=\"code\"><code class=\"language-Bash\">curl -sS \"$API_URL/audit/v1/logs?project_id=$PROJECT_ID&amp;pagesize=1\" \\\n  -H \"X-IK-ClientKey: $CLIENT_KEY\" | jq '.items[0] | {sequence, kid, alg, events: (.data | length), first: .data[0]}'</code></pre>\n<pre class=\"code\"><code class=\"language-JSON\">{\n  \"sequence\": 1,\n  \"kid\": \"…\",\n  \"alg\": \"ES256-DER\",\n  \"events\": 3,\n  \"first\": {\n    \"appSpaceId\": \"gid:YOUR_PROJECT_GID\",\n    \"customerId\": \"gid:YOUR_CUSTOMER_GID\",\n    \"data\": {\n      \"@type\": \"type.googleapis.com/indykite.auditsink.v1beta1.CreatedConfig\",\n      \"id\": \"gid:YOUR_AUDIT_SIGNING_GID\",\n      \"type\": \"…\",\n      \"…\": \"…\"\n    },\n    \"eventSource\": \"…\",\n    \"eventType\": \"indykite.audit.config.create\",\n    \"initiator\": {\n      \"appSpaceId\": \"gid:YOUR_PROJECT_GID\",\n      \"customerId\": \"gid:YOUR_CUSTOMER_GID\",\n      \"serviceAccountCredentialsId\": \"gid:YOUR_SERVICE_ACCOUNT_CREDENTIALS_GID\",\n      \"serviceAccountId\": \"gid:YOUR_SERVICE_ACCOUNT_GID\"\n    },\n    \"requestId\": \"…\",\n    \"time\": \"2026-10-07T09:20:05.413908112Z\"\n  }\n}</code></pre>\n<p class=\"notion\">Every event has the same top-level shape, whatever its type, with its top-level keys in alphabetical order:</p>\n<ul class=\"bulleted-list\">\n<li style=\"list-style-type:disc\"><code class=\"notion\">eventType</code> and <code class=\"notion\">time</code>: what happened and when, RFC 3339 with nanoseconds, UTC.</li>\n<li style=\"list-style-type:disc\"><code class=\"notion\">customerId</code> and <code class=\"notion\">appSpaceId</code>: the organization and the project. <code class=\"notion\">appSpaceId</code> equals the <code class=\"notion\">project_id</code> you queried.</li>\n<li style=\"list-style-type:disc\"><code class=\"notion\">initiator</code>: who caused it, as a flat object of identifiers. A Service Account shows <code class=\"notion\">serviceAccountId</code> and <code class=\"notion\">serviceAccountCredentialsId</code>, as above; an Application Agent shows <code class=\"notion\">applicationId</code>, <code class=\"notion\">appAgentId</code> and <code class=\"notion\">appAgentCredentialsId</code>, which is what the capture events of step 1 carry; an end user shows <code class=\"notion\">digitalTwinId</code>, <code class=\"notion\">viaApplicationId</code> and <code class=\"notion\">sessionId</code>.</li>\n<li style=\"list-style-type:disc\"><code class=\"notion\">requestId</code>: the identifier of the API request, the same value that request returned to its caller.</li>\n<li style=\"list-style-type:disc\"><code class=\"notion\">data</code>: the typed payload, named by its <code class=\"notion\">@type</code>, in camelCase. For a capture upsert it holds the node with its properties; for a configuration change, the object's identifiers.</li>\n<li style=\"list-style-type:disc\"><code class=\"notion\">context</code>: string pairs attached to some events, for example <code class=\"notion\">soft_delete</code> on a configuration delete, present only when there are any.</li>\n</ul>\n<p class=\"notion\">Two things that matter later. First, the content of <code class=\"notion\">data</code> is whatever the caller sent, property values included, so an export is evidence to store and index, never input to execute. Second, an accepted event is written to the chain once; a duplicate is possible only when a delivery is replayed long after the original, and such a copy is byte-for-byte identical, same <code class=\"notion\">time</code>, same <code class=\"notion\">requestId</code>, so deduplicating on the whole event object is safe, while two distinct actions always differ in at least <code class=\"notion\">time</code>.</p>",
      "links": {
        "html": "/tutorials/tutorial-audit-trail#chapter-4",
        "markdown": "/tutorials/tutorial-audit-trail/4.md"
      }
    },
    {
      "chapter": 5,
      "title": "Export the trail",
      "description": "Page the keys, manifests, batches and checkpoints out of the Audit Log API into a self-contained folder, byte for byte, with curl and jq.",
      "body": "<h2 class=\"\">Chapter 5: Export the trail</h2>\n\n<p class=\"notion\">An export is four things fetched for one project: the JWK Set, every manifest, every batch, and every checkpoint. This chapter fetches them by hand first, so the envelope and the cursors are familiar, then with a script you can run nightly. One rule shapes the whole chapter: <strong>the batch hash covers the <code class=\"notion\">data</code> array exactly as served</strong>, so the export keeps the response pages as they arrived rather than a pretty-printed or re-encoded copy.</p>\n<figure class=\"image\"><img src=\"/assets/images/audit-export.svg\" alt=\"The export client pages the manifests, logs and checkpoints endpoints with pagesize 50 and next_cursor until has_more is false, fetches the JWK Set without a credential, and writes every page byte for byte into a dated folder; jsonl files are derived for reading only\"/></figure>\n\n<h3 class=\"\">Step 1: The keys</h3>\n<pre class=\"code\"><code class=\"language-Bash\">mkdir -p export &amp;&amp; cd export\ncurl -sS \"$API_URL/audit/.well-known/jwks.json?project_id=$PROJECT_ID\" -o jwks.json\njq . jwks.json</code></pre>\n<pre class=\"code\"><code class=\"language-JSON\">{\n  \"keys\": [\n    {\n      \"crv\": \"P-256\",\n      \"kid\": \"…\",\n      \"kty\": \"EC\",\n      \"use\": \"sig\",\n      \"x\": \"…\",\n      \"y\": \"…\"\n    }\n  ]\n}</code></pre>\n<p class=\"notion\">No credential, and no <code class=\"notion\">alg</code> member on the keys: the algorithm label travels with each signed record instead, because the signatures are DER-encoded rather than the fixed-size R||S form that JWS defines for <code class=\"notion\">ES256</code>. The response is cacheable for 60 seconds and lists every key that has signed for the project, current and retired; a new key can take up to 2 minutes to be listed. The file is saved <em>with</em> the export so that the export verifies on its own, without the API.</p>\n\n<h3 class=\"\">Step 2: One page of manifests</h3>\n<pre class=\"code\"><code class=\"language-Bash\">curl -sS \"$API_URL/audit/v1/manifests?project_id=$PROJECT_ID&amp;pagesize=50\" \\\n  -H \"X-IK-ClientKey: $CLIENT_KEY\" | jq '{next_cursor, has_more, count: (.items | length), first: .items[0]}'</code></pre>\n<pre class=\"code\"><code class=\"language-JSON\">{\n  \"next_cursor\": \"\",\n  \"has_more\": false,\n  \"count\": 2,\n  \"first\": {\n    \"manifest_id\": \"0d1a7a6e-6c6c-4a53-9f1c-0e0f4b4a1c2d\",\n    \"batch_id\": \"7b3f2b9a-5d1e-4c1b-8a4e-2f6c9d8e7a10\",\n    \"batch_uri\": \"…\",\n    \"project_id\": \"gid:YOUR_PROJECT_GID\",\n    \"sequence\": 1,\n    \"prev_hash\": \"\",\n    \"data_hash\": \"9f86d081884c7d659a2feaa0c55ad015a3bf4f1b2b0b822cd15d6c15b0f00a08\",\n    \"head_hash\": \"2c26b46b68ffc68ff99b453c1d30413413422d706483bfa0f98a5e886266e7ae\",\n    \"kid\": \"…\",\n    \"alg\": \"ES256-DER\",\n    \"signature\": \"MEUCIQ…\",\n    \"created_at\": \"2026-10-07T09:22:11.482913604Z\"\n  }\n}</code></pre>\n<p class=\"notion\">Every listing endpoint answers with the same envelope: <code class=\"notion\">items</code>, <code class=\"notion\">has_more</code>, and <code class=\"notion\">next_cursor</code>, which is <code class=\"notion\">\"\"</code> on the last page. <code class=\"notion\">pagesize</code> defaults to 50 and is capped at 50. The cursor is opaque: it is copied back as it is, never built by hand. Manifests and logs page in lockstep, so a manifest cursor is valid on the logs endpoint and the other way round; checkpoint cursors are their own family.</p>\n<p class=\"notion\">Read the first manifest once, field by field: <code class=\"notion\">sequence</code> 1 has an empty <code class=\"notion\">prev_hash</code>; <code class=\"notion\">data_hash</code> is the SHA-256 of the batch's events; <code class=\"notion\">head_hash</code> is derived from the project, the sequence, the previous head, the data hash and the batch id; and <code class=\"notion\">signature</code>, under the key <code class=\"notion\">kid</code> names, covers that head. The second manifest will carry this <code class=\"notion\">head_hash</code> as its <code class=\"notion\">prev_hash</code>. That is the chain.</p>\n\n<h3 class=\"\">Step 3: One batch, and why pages are kept raw</h3>\n<pre class=\"code\"><code class=\"language-Bash\">curl -sS \"$API_URL/audit/v1/logs?project_id=$PROJECT_ID&amp;pagesize=50\" \\\n  -H \"X-IK-ClientKey: $CLIENT_KEY\" -o logs-page-1.json\njq '.items[0] | del(.data) + {events: (.data | length)}' logs-page-1.json</code></pre>\n<pre class=\"code\"><code class=\"language-JSON\">{\n  \"batch_id\": \"7b3f2b9a-5d1e-4c1b-8a4e-2f6c9d8e7a10\",\n  \"project_id\": \"gid:YOUR_PROJECT_GID\",\n  \"sequence\": 1,\n  \"hash\": \"9f86d081884c7d659a2feaa0c55ad015a3bf4f1b2b0b822cd15d6c15b0f00a08\",\n  \"signature\": \"MEQCIB…\",\n  \"kid\": \"…\",\n  \"alg\": \"ES256-DER\",\n  \"chain_hash\": \"2c26b46b68ffc68ff99b453c1d30413413422d706483bfa0f98a5e886266e7ae\",\n  \"manifest_id\": \"0d1a7a6e-6c6c-4a53-9f1c-0e0f4b4a1c2d\",\n  \"events\": 3\n}</code></pre>\n<p class=\"notion\">The batch repeats what the manifest said about it (<code class=\"notion\">hash</code> equals <code class=\"notion\">data_hash</code>, <code class=\"notion\">chain_hash</code> equals <code class=\"notion\">head_hash</code>) and adds the events in <code class=\"notion\">data</code>. The <code class=\"notion\">hash</code> is the SHA-256 of that array's bytes as the server wrote them: compact JSON, top-level keys in alphabetical order, the server's own escaping. Pass it through <code class=\"notion\">jq -c</code> or a JSON library and back, and an escaped character or a number may be written differently, and the hash no longer matches. So the raw response is what goes into the archive, and <code class=\"notion\">jq</code> is used to <em>look</em> at it. Saved with <code class=\"notion\">-o</code>, as above, the page is byte for byte what the API sent.</p>\n\n<h3 class=\"\">Step 4: The whole trail, with a script</h3>\n<p class=\"notion\">Download <a href=\"/assets/downloads/audit-export.sh\" class=\"fancy-link\" download=\"audit-export.sh\">audit-export.sh</a>. It fetches the JWKS, then pages the manifests, the logs and the checkpoints to <code class=\"notion\">has_more: false</code>, keeping every page as it arrived and writing one-item-per-line <code class=\"notion\">.jsonl</code> files next to them for convenience. It stops on the first HTTP error, so an incomplete export is reported rather than mistaken for a short one:</p>\n<pre class=\"code\"><code class=\"language-Bash\">cd ..\nchmod +x audit-export.sh\n./audit-export.sh\n# keys: … (1 JWK Set(s) kept with the export)\n# checkpoints: 1 page(s), 0 item(s)\n# manifests: 1 page(s), 2 item(s)\n# logs: 1 page(s), 2 item(s)\n# keys: … (1 JWK Set(s) kept with the export)\n# newest sequence: 2\n# export written to audit-export/YOUR_PROJECT_GID/2026-10-07T10-00-00Z</code></pre>\n<pre class=\"code\"><code class=\"language-Text\">audit-export/YOUR_PROJECT_GID/\n  jwks-archive/jwks-….json     # every JWK Set ever fetched for this project\n  2026-10-07T10-00-00Z/\n    jwks.json  jwks-….json     # the current set, and a copy of every archived set\n    checkpoints/page-0001.json   manifests/page-0001.json   logs/page-0001.json\n    checkpoints.jsonl            manifests.jsonl            logs.jsonl</code></pre>\n<p class=\"notion\">Two details of the script are worth knowing. It reads the checkpoints first, then the manifests and the logs, and if the chain grew in between it reads again whichever of the two is behind; an export is only reported complete when manifests and logs end at the same sequence. And it keeps every JWK Set it has ever fetched for the project in <code class=\"notion\">jwks-archive</code> and copies all of them into each export, so every export folder verifies on its own, also against a set from before a rotation. After the pages it fetches the set once more, in case the key rotated during the export, and fails if any <code class=\"notion\">kid</code> in the exported records is in none of the saved sets: a key added within the last 2 minutes may not be listed yet, so rerun a little later.</p>\n<p class=\"notion\">The heart of the script is one loop per endpoint; this is all a client has to get right:</p>\n<pre class=\"code\"><code class=\"language-Bash\">cursor=\"\"\nn=0\nwhile :; do\n    n=$((n + 1))\n    page=\"logs/page-$(printf '%04d' \"${n}\").json\"\n    curl -fsS \"${API_URL}/audit/v1/logs?project_id=${PROJECT_ID}&amp;pagesize=50&amp;cursor=${cursor}\" \\\n        -H \"X-IK-ClientKey: ${CLIENT_KEY}\" -o \"${page}\" ||\n        {\n            echo \"export of logs failed on page ${n}; the export is incomplete\" &gt;&amp;2\n            exit 1\n        }\n    has_more=\"$(jq -r '.has_more' \"${page}\")\"\n    [[ \"${has_more}\" == \"true\" ]] || break\n    cursor=\"$(jq -r '.next_cursor' \"${page}\")\"\ndone</code></pre>\n<p class=\"notion\"><code class=\"notion\">curl -f</code> is what makes a <code class=\"notion\">401</code> or <code class=\"notion\">500</code> body fail the loop instead of being written down as a page; without it the export would end early and look complete.</p>\n\n<h3 class=\"\">Step 5: Checkpoints, and a first look at the numbers</h3>\n<p class=\"notion\">Your fresh project most likely has no checkpoint yet: they are written periodically, and only for chains that have grown since the last one, so the newest checkpoint normally trails the newest manifest. On a project with history the file holds items like this, newest first:</p>\n<pre class=\"code\"><code class=\"language-JSON\">{\n  \"checkpoint_id\": \"4e2d9c5a-1b7f-4e0a-9c3d-6a8b2f1e0d47\",\n  \"project_id\": \"gid:YOUR_PROJECT_GID\",\n  \"sequence\": 128,\n  \"head_hash\": \"b3a8e0e1e4c3…\",\n  \"created_at\": \"2026-10-08T13:47:09.219540877Z\",\n  \"signature\": \"MEUCIG…\",\n  \"kid\": \"…\",\n  \"alg\": \"ES256-DER\"\n}</code></pre>\n<p class=\"notion\">A checkpoint is a dated, signed claim about where the chain stood. Its value shows in chapter 6: if someone truncated the chain and let it regrow, the old checkpoint would still name a head that the regrown chain does not have at that sequence.</p>\n<pre class=\"code\"><code class=\"language-Bash\">cd audit-export/YOUR_PROJECT_GID/2026-10-07T10-00-00Z\njq -c '{sequence, events: (.data | length), kid}' logs.jsonl\njq -c '.data[]' logs.jsonl | jq -r '.eventType' | sort | uniq -c</code></pre>\n<pre class=\"code\"><code class=\"language-Text\">{\"sequence\":1,\"events\":3,\"kid\":\"…\"}\n{\"sequence\":2,\"events\":16,\"kid\":\"…\"}\n      2 indykite.audit.capture.upsert.node\n      3 indykite.audit.capture.upsert.relationship\n      …\n      2 indykite.audit.config.create</code></pre>\n<p class=\"notion\">The <code class=\"notion\">.jsonl</code> files are the right place for this kind of question. They are derived from the raw pages and are not what gets verified; the next chapter reads the pages.</p>",
      "links": {
        "html": "/tutorials/tutorial-audit-trail#chapter-5",
        "markdown": "/tutorials/tutorial-audit-trail/5.md"
      }
    },
    {
      "chapter": 6,
      "title": "Verify the export",
      "description": "Recompute every hash, follow every link and check every signature of the export with a short Python script, then break the export on purpose and watch the checks fail.",
      "body": "<h2 class=\"\">Chapter 6: Verify the export</h2>\n\n<p class=\"notion\">Verification is where the trail earns its name. It needs the export folder from chapter 5 and nothing else: no credential, no network, no IndyKite. The rules are few and exact; the script below applies them, and the second half of the chapter breaks the export on purpose so you see what a finding looks like.</p>\n\n<h3 class=\"\">The rules</h3>\n<figure class=\"image\"><img src=\"/assets/images/audit-verify.svg\" alt=\"The three digests a verifier recomputes and compares, and the signature check that uses the JWK named by kid\"/></figure>\n<table class=\"simple-table\">\n<tbody>\n<tr>\n<td class=\"simple-table-header-color\"><strong>Check</strong></td>\n<td class=\"simple-table-header-color\"><strong>Rule</strong></td>\n</tr>\n<tr><td class=\"\">Batch content</td><td class=\"\">SHA-256 of the <code class=\"notion\">data</code> array, bytes exactly as served, as lower-case hex, equals the batch <code class=\"notion\">hash</code> and the manifest <code class=\"notion\">data_hash</code>.</td></tr>\n<tr><td class=\"\">Chain head</td><td class=\"\">SHA-256 of the string <code class=\"notion\">&lt;project_id&gt;|&lt;sequence&gt;|&lt;prev_hash&gt;|&lt;data_hash&gt;|&lt;batch_id&gt;</code> (five fields joined with <code class=\"notion\">|</code>, sequence in decimal, <code class=\"notion\">prev_hash</code> empty for sequence 1) equals the manifest <code class=\"notion\">head_hash</code> and the batch <code class=\"notion\">chain_hash</code>.</td></tr>\n<tr><td class=\"\">Links</td><td class=\"\">Sequences run 1, 2, 3, … without a gap, and each <code class=\"notion\">prev_hash</code> equals the previous <code class=\"notion\">head_hash</code>.</td></tr>\n<tr><td class=\"\">Cross-references</td><td class=\"\">The batch and the manifest at one sequence carry the same <code class=\"notion\">batch_id</code>, <code class=\"notion\">manifest_id</code> and <code class=\"notion\">project_id</code>.</td></tr>\n<tr><td class=\"\">Batch and manifest signatures</td><td class=\"\">ECDSA on P-256 over the 32-byte digest the hex <code class=\"notion\">hash</code> (batch) or <code class=\"notion\">head_hash</code> (manifest) encodes; the signature is ASN.1 DER, Base64 with the standard alphabet and padding; <code class=\"notion\">alg</code> is <code class=\"notion\">ES256-DER</code>; the key is the JWK whose <code class=\"notion\">kid</code> matches.</td></tr>\n<tr><td class=\"\">Checkpoint</td><td class=\"\">Signature over SHA-256 of <code class=\"notion\">project-checkpoint|&lt;project_id&gt;|&lt;sequence&gt;|&lt;head_hash&gt;|&lt;created_at&gt;</code>, <code class=\"notion\">created_at</code> exactly as returned, and the manifest at that sequence carries the same <code class=\"notion\">head_hash</code>.</td></tr>\n</tbody>\n</table>\n<p class=\"notion\">Two details trip up hand-written verifiers. The signatures are DER-encoded, as a KMS produces them, not the fixed-size R||S form that JWS <code class=\"notion\">ES256</code> (RFC 7518) defines, so a JWT or JWS library rejects them unless converted. And the platform signs digests, never documents: the digest is the raw 32 bytes the hex string encodes, so a verifier that hashes the hex string again, or hashes the whole JSON record, fails on every record.</p>\n\n<h3 class=\"\">Step 1: Run the verifier</h3>\n<p class=\"notion\">Download <a href=\"/assets/downloads/audit-verify.py\" class=\"fancy-link\" download=\"audit-verify.py\">audit-verify.py</a>. It needs Python 3.8 or later and the <code class=\"notion\">cryptography</code> package:</p>\n<pre class=\"code\"><code class=\"language-Bash\">pip install cryptography\npython3 audit-verify.py audit-export/YOUR_PROJECT_GID/2026-10-07T10-00-00Z</code></pre>\n<pre class=\"code\"><code class=\"language-Text\">manifests: 2  batches: 2  events: 19  checkpoints: 0\nsequences: 1..2  keys used: …\nnewest head: sequence 2 = …  (compare with the value you kept)\nOK: every hash, link and signature verified</code></pre>\n<p class=\"notion\">Before the chain checks, the script checks the export itself: every endpoint has its pages, numbered without gaps, each page a valid envelope, <code class=\"notion\">has_more</code> true on every page but the last and the last cursor empty. A folder whose last saved page still says <code class=\"notion\">has_more: true</code> is reported as truncated rather than verified. The last line prints the newest sequence and head; write them down with the date, since a later export that verifies but ends earlier than this one is the sign of a chain whose tail was removed, and only a value you kept can reveal that.</p>\n<p class=\"notion\">The exit code is <code class=\"notion\">0</code> when every check passes and <code class=\"notion\">1</code> otherwise, with one <code class=\"notion\">FAIL</code> line per failed check on standard error, so the script slots into a nightly job. It reads the raw pages, <code class=\"notion\">manifests/page-*.json</code>, <code class=\"notion\">logs/page-*.json</code> and <code class=\"notion\">checkpoints/page-*.json</code>, and every <code class=\"notion\">jwks*.json</code> in the folder, so an export that holds two JWKS snapshots across a rotation verifies as one.</p>\n\n<h3 class=\"\">How the script does it</h3>\n<p class=\"notion\">The whole script is in the <a href=\"/resources/audit-log-1\" class=\"fancy-link\">Audit Log resource</a>; these are the three pieces that matter.</p>\n<p class=\"notion\">Loading a key from the JWK Set, and verifying a signature over a digest:</p>\n<pre class=\"code\"><code class=\"language-Python\">from cryptography.hazmat.primitives import hashes\nfrom cryptography.hazmat.primitives.asymmetric import ec, utils\n# a JWK's x and y are base64url integers\ndef b64url_int(s):\n    return int.from_bytes(base64.urlsafe_b64decode(s + \"=\" * (-len(s) % 4)), \"big\")\n# the public key named by the record's kid\nkey = ec.EllipticCurvePublicNumbers(b64url_int(jwk[\"x\"]), b64url_int(jwk[\"y\"]), ec.SECP256R1()).public_key()\n# verify a signature over a digest the record carries in hex\nkey.verify(\n    base64.b64decode(record[\"signature\"]),        # DER, standard Base64\n    bytes.fromhex(hex_digest),                     # the 32 bytes the hex encodes\n    ec.ECDSA(utils.Prehashed(hashes.SHA256())),    # the digest is given, not recomputed\n)</code></pre>\n<p class=\"notion\">Recomputing the two hashes of a manifest and batch pair:</p>\n<pre class=\"code\"><code class=\"language-Python\">data_hash = hashlib.sha256(raw_data_bytes).hexdigest()          # bytes sliced out of the page as served\nhead = hashlib.sha256(\n    f\"{m['project_id']}|{m['sequence']}|{m['prev_hash']}|{m['data_hash']}|{m['batch_id']}\".encode()\n).hexdigest()\nassert data_hash == b[\"hash\"] == m[\"data_hash\"]\nassert head == m[\"head_hash\"] == b[\"chain_hash\"]</code></pre>\n<p class=\"notion\">And the checkpoint digest:</p>\n<pre class=\"code\"><code class=\"language-Python\">digest = hashlib.sha256(\n    f\"project-checkpoint|{c['project_id']}|{c['sequence']}|{c['head_hash']}|{c['created_at']}\".encode()\n).hexdigest()</code></pre>\n<p class=\"notion\">The one piece that is not a cryptographic rule is getting <code class=\"notion\">raw_data_bytes</code>: the script scans the page text for each item's <code class=\"notion\">\"data\"</code> value and takes that slice, instead of parsing and re-serializing, so the bytes hashed are the bytes the server hashed.</p>\n\n<h3 class=\"\">Step 2: Cross-check one signature with OpenSSL</h3>\n<p class=\"notion\">A second tool that agrees is worth having when the verifier is new to your team. Convert the JWK with the right <code class=\"notion\">kid</code> to a PEM public key, here with the same <code class=\"notion\">cryptography</code> package the verifier uses, then let OpenSSL check the signature:</p>\n<pre class=\"code\"><code class=\"language-Bash\">KID=$(head -n 1 manifests.jsonl | jq -r '.kid')          # the key the first exported manifest names\npython3 - \"$KID\" &lt;&lt;'EOF' &gt; key.pem\nimport json, base64, sys, glob\nfrom cryptography.hazmat.primitives import serialization\nfrom cryptography.hazmat.primitives.asymmetric import ec\nkeys = {}\nfor path in sorted(glob.glob(\"jwks*.json\")):          # the current set and every archived snapshot\n    with open(path, encoding=\"utf-8\") as f:\n        doc = json.load(f)\n        for key in doc[\"keys\"]:\n            keys[key[\"kid\"]] = key\nk = keys[sys.argv[1]]\nn = lambda s: int.from_bytes(base64.urlsafe_b64decode(s + \"=\" * (-len(s) % 4)), \"big\")\npub = ec.EllipticCurvePublicNumbers(n(k[\"x\"]), n(k[\"y\"]), ec.SECP256R1()).public_key()\nprint(pub.public_bytes(serialization.Encoding.PEM, serialization.PublicFormat.SubjectPublicKeyInfo).decode(), end=\"\")\nEOF</code></pre>\n<pre class=\"code\"><code class=\"language-Bash\">HEAD_HASH=$(head -n 1 manifests.jsonl | jq -r '.head_hash')\nSIGNATURE=$(head -n 1 manifests.jsonl | jq -r '.signature')\necho -n \"$HEAD_HASH\" | xxd -r -p &gt; digest.bin\necho \"$SIGNATURE\" | base64 -d &gt; signature.der\nopenssl pkeyutl -verify -pubin -inkey key.pem -in digest.bin -sigfile signature.der\n# Signature Verified Successfully</code></pre>\n\n<h3 class=\"\">Step 3: Break it, and read the findings</h3>\n<p class=\"notion\">Copy the export and change one character inside an event of the first batch, say a letter of an <code class=\"notion\">externalId</code>:</p>\n<pre class=\"code\"><code class=\"language-Bash\">cp -r audit-export/YOUR_PROJECT_GID/2026-10-07T10-00-00Z tampered\nsed -i 's/\"externalId\":\"customerA\"/\"externalId\":\"customerX\"/' tampered/logs/page-0001.json\npython3 audit-verify.py tampered</code></pre>\n<pre class=\"code\"><code class=\"language-Text\">FAIL batch 1: SHA-256 of data as served differs from hash / data_hash\n1 check(s) failed</code></pre>\n<p class=\"notion\">Now remove a whole manifest from the middle of a longer export, or edit a <code class=\"notion\">sequence</code>:</p>\n<pre class=\"code\"><code class=\"language-Text\">FAIL manifest 5: expected sequence 4, gap or duplicate in the export\nFAIL batch 4: no manifest in manifests/ for this batch</code></pre>\n<p class=\"notion\">And replace <code class=\"notion\">jwks.json</code> with keys that did not sign the trail:</p>\n<pre class=\"code\"><code class=\"language-Text\">FAIL manifest 1: signature does not verify under kid '…' (InvalidSignature)\nFAIL batch 1: signature does not verify under kid '…' (InvalidSignature)\n…</code></pre>\n<p class=\"notion\">Each finding names the record and the rule, which is what a report needs. Three readings to keep in mind:</p>\n<ul class=\"bulleted-list\">\n<li style=\"list-style-type:disc\"><strong>A content or link failure at one sequence</strong> on an otherwise intact chain means the stored record differs from what was signed. Keep the export and the JWKS exactly as fetched and report the project, the sequence and the time.</li>\n<li style=\"list-style-type:disc\"><strong>A gap</strong> is most often an export problem: a page lost to an error that was not treated as fatal. Re-export; a gap that persists at the same sequence is a finding.</li>\n<li style=\"list-style-type:disc\"><strong>Every signature failing under one <code class=\"notion\">kid</code></strong> means the key in your JWKS is not the key that signed: usually the snapshot was taken after a rotation. Verify with the JWKS kept with the export, which is the reason it is kept.</li>\n</ul>\n<p class=\"notion\">A checkpoint failure deserves its own line: the manifest at the checkpoint's <code class=\"notion\">sequence</code> showing a different <code class=\"notion\">head_hash</code> is the model's strongest signal, because it means the chain reached that sequence with a different history than the one that was signed at checkpoint time.</p>",
      "links": {
        "html": "/tutorials/tutorial-audit-trail#chapter-6",
        "markdown": "/tutorials/tutorial-audit-trail/6.md"
      }
    },
    {
      "chapter": 7,
      "title": "Run it day to day",
      "description": "Archiving exports, key rotation, feeding a SIEM, deduplication, and the errors you will meet and what each one means.",
      "body": "<h2 class=\"\">Chapter 7: Run it day to day</h2>\n\n<p class=\"notion\">The previous chapters produced one verified export. This one is about turning that into a routine: what to keep, how often, how to react to a key change, how to feed the events into the tools your security team already uses, and what each error means when something goes wrong.</p>\n\n<h3 class=\"\">Archive by project, keep the keys with the data</h3>\n<p class=\"notion\">An export is self-contained when, for one <code class=\"notion\">project_id</code>, it holds the manifests, the logs and the checkpoints each fetched to <code class=\"notion\">has_more: false</code>, together with JWKS snapshots that between them contain every <code class=\"notion\">kid</code> those records reference. A layout that keeps this straight:</p>\n<pre class=\"code\"><code class=\"language-Text\">audit-archive/\n  &lt;project_id&gt;/\n    2026-10-07T10-00-00Z/\n      jwks.json              # the keys as published at export time\n      jwks-&lt;digest&gt;.json     # every JWK Set ever fetched for this project, copied in by the script\n      manifests/page-*.json  # the raw pages: what audit-verify.py reads\n      logs/page-*.json\n      checkpoints/page-*.json\n      manifests.jsonl        # derived with jq, for reading only\n      logs.jsonl\n      checkpoints.jsonl\n      verify.log             # output of audit-verify.py, with the date and the newest head</code></pre>\n<p class=\"notion\">The raw page directories are the evidence: the batch hash covers the bytes as served, so a folder that kept only the <code class=\"notion\">.jsonl</code> files can no longer be verified. The JWKS is served with a 60-second cache lifetime and contains every key that has signed for the project, current and retired; a new key can take up to 2 minutes to appear. Keeping the sets with the exports makes each export verifiable without the API. The export script therefore keeps every JWK Set it has fetched in a <code class=\"notion\">jwks-archive</code> folder next to the exports and copies all of them into each new export, so a folder taken after a rotation still verifies on its own. If you export with your own tooling, keep the previous <code class=\"notion\">jwks.json</code> next to the new one. Never delete an older export because a newer one exists.</p>\n<p class=\"notion\">Exports are incremental by nature: the chain only grows at the end, and sequences are contiguous. A nightly job can store the newest <code class=\"notion\">sequence</code> it has, fetch everything, and keep the full set; or diff on sequence and append. Verify after every export, not only when an auditor asks, so that a problem is found while the context is fresh.</p>\n\n<h3 class=\"\">Key rotation</h3>\n<ol type=\"1\" class=\"numbered-list\" start=\"1\">\n<li>Keep the JWK Set that names the current key before anything changes: run an export, or fetch <code class=\"notion\">GET /audit/.well-known/jwks.json</code> into a dated file in your archive. The API keeps serving the old public key after the rotation; the copy in your archive is what lets an export verify without the API. Keep the JWK Set with each export for the platform-managed key as well.</li>\n<li>Create the new key version in your KMS, same algorithm (EC P-256, ECDSA with SHA-256).</li>\n<li>For a customer-managed key, update the Audit Signing configuration: new <code class=\"notion\">key_resource</code>, new <code class=\"notion\">kid</code>, <code class=\"notion\">If-Match</code> with the current ETag. In Terraform, change the two arguments and apply.</li>\n<li>Whatever changed the key, new records carry a new <code class=\"notion\">kid</code> and the JWK Set changes with it. Take an export soon after, so that your archive holds a JWKS snapshot for each <code class=\"notion\">kid</code> that appears in the trail; the export script keeps every set it has fetched and copies them all into each new export.</li>\n<li>Keep the old key version readable, or at least its public key, for as long as records signed with it must be verifiable. Destroying a key version in the KMS does not alter the trail, but it removes your ability to re-derive the public key later should a JWKS snapshot be lost.</li>\n</ol>\n<p class=\"notion\">A verifier handles rotation without special cases: each record names its <code class=\"notion\">kid</code>, and the key is looked up by that name. What breaks verification is a <code class=\"notion\">kid</code> that is in no JWKS you kept.</p>\n\n<h3 class=\"\">Feeding a SIEM or a data warehouse</h3>\n<table class=\"simple-table\">\n<tbody>\n<tr>\n<td class=\"simple-table-header-color\"><strong>Need</strong></td>\n<td class=\"simple-table-header-color\"><strong>Source</strong></td>\n<td class=\"simple-table-header-color\"><strong>Why</strong></td>\n</tr>\n<tr><td class=\"\">Alerts and dashboards on events as they happen</td><td class=\"\"><a href=\"/guides/guide-outbound-events\" class=\"fancy-link\">Outbound Events</a> to Kafka, Pub/Sub, Event Grid or Service Bus</td><td class=\"\">Pushed within moments of the action, routed and filtered by event type, labels and properties. Unsigned.</td></tr>\n<tr><td class=\"\">Evidence that stands on its own</td><td class=\"\">The Audit Log API export from chapter 5</td><td class=\"\">Signed, chained, verifiable offline. Pulled, in batches.</td></tr>\n<tr><td class=\"\">Both</td><td class=\"\">Both</td><td class=\"\">They carry the same <code class=\"notion\">indykite.audit.*</code> events. Use the stream for operations and the export for retention and proof; reconcile the two on <code class=\"notion\">requestId</code> and <code class=\"notion\">time</code> when a question arises.</td></tr>\n</tbody>\n</table>\n<p class=\"notion\">For loading into a warehouse, one event per line is the convenient shape; the batch fields can travel with each event so the provenance is kept:</p>\n<pre class=\"code\"><code class=\"language-Bash\">jq -c '. as $b | .data[] | . + {_sequence: $b.sequence, _batch_id: $b.batch_id, _kid: $b.kid}' logs.jsonl &gt; events.jsonl\njq -sc 'unique_by(del(._sequence, ._batch_id, ._kid))[]' events.jsonl &gt; events.dedup.jsonl   # one record per distinct event</code></pre>\n<p class=\"notion\">Deduplicate on the original event fields, as above, so that a redelivery that landed in a later batch still collapses onto the first copy and keeps that copy's provenance. Never strip <code class=\"notion\">time</code> or <code class=\"notion\">requestId</code> first: two real actions can have identical content and differ only there.</p>\n\n<h3 class=\"\">Errors, and what each one means</h3>\n<table class=\"simple-table\">\n<tbody>\n<tr>\n<td class=\"simple-table-header-color\"><strong>Symptom</strong></td>\n<td class=\"simple-table-header-color\"><strong>Meaning and fix</strong></td>\n</tr>\n<tr><td class=\"\"><code class=\"notion\">200</code> with <code class=\"notion\">\"items\": []</code> on every endpoint</td><td class=\"\">The chain is empty: no event recorded for the project yet. Not an error. A new project also has no checkpoint until its chain has grown and the next checkpoint has been written.</td></tr>\n<tr><td class=\"\"><code class=\"notion\">401</code> <code class=\"notion\">insufficient API access level for appAgent</code></td><td class=\"\">The agent lacks the <code class=\"notion\">Audit</code> permission, or received it moments ago. Grants apply asynchronously; retry before changing anything.</td></tr>\n<tr><td class=\"\"><code class=\"notion\">401</code> <code class=\"notion\">Missing or malformed AppAgent credential token in X-IK-ClientKey header</code></td><td class=\"\">No credential, or a Service Account token where an agent credential belongs. The JWKS endpoint takes none.</td></tr>\n<tr><td class=\"\"><code class=\"notion\">403</code> <code class=\"notion\">the authenticated credential does not have access to this project</code></td><td class=\"\"><code class=\"notion\">project_id</code> is another project, even one of the same organization. Each project is exported with its own agent.</td></tr>\n<tr><td class=\"\"><code class=\"notion\">400</code> <code class=\"notion\">invalid cursor</code></td><td class=\"\">The cursor was edited, truncated, or taken from the other endpoint family. Manifests and logs share cursors; checkpoints have their own. Copy <code class=\"notion\">next_cursor</code> verbatim.</td></tr>\n<tr><td class=\"\"><code class=\"notion\">400</code> <code class=\"notion\">pagesize must be a positive integer</code></td><td class=\"\"><code class=\"notion\">pagesize</code> is zero, negative or not a number. Values above 50 are capped silently, not refused.</td></tr>\n<tr><td class=\"\"><code class=\"notion\">406</code></td><td class=\"\">An <code class=\"notion\">Accept</code> header that is absent or allows neither <code class=\"notion\">application/json</code> nor <code class=\"notion\">*/*</code>.</td></tr>\n<tr><td class=\"\"><code class=\"notion\">422</code> on <code class=\"notion\">/configs/v1/audit-signings</code></td><td class=\"\">Validation: <code class=\"notion\">missing field provider</code>, <code class=\"notion\">key_resource is required for customer-managed providers</code>, <code class=\"notion\">kid is required for customer-managed providers</code>, <code class=\"notion\">auth_params</code> limits (32 pairs, 1-256 characters each, no empty values), or a <code class=\"notion\">name</code> that does not match <code class=\"notion\">[a-z][-a-z0-9]*[a-z0-9]</code>. The <code class=\"notion\">errors</code> array names the field.</td></tr>\n<tr><td class=\"\"><code class=\"notion\">412</code> on update or delete</td><td class=\"\">Stale <code class=\"notion\">If-Match</code>. Re-read the configuration, take the new ETag, retry.</td></tr>\n<tr><td class=\"\"><code class=\"notion\">409</code> on create</td><td class=\"\"><code class=\"notion\">audit signing config already exists in project</code>: a project holds exactly one configuration. Update the existing one, or import it into Terraform rather than declaring a second resource.</td></tr>\n<tr><td class=\"\">Verifier: a signature fails on one record</td><td class=\"\">First check the <code class=\"notion\">kid</code> is in the JWKS you used, and that you converted the Base64 DER signature correctly. A real failure on an otherwise intact chain means the record was altered after signing. Keep the export and the JWKS exactly as fetched and report the project, the sequence and the time.</td></tr>\n<tr><td class=\"\">Verifier: a <code class=\"notion\">prev_hash</code> does not match the previous <code class=\"notion\">head_hash</code></td><td class=\"\">Either a page was lost during export (a <code class=\"notion\">401</code> or <code class=\"notion\">500</code> body taken for a page; use <code class=\"notion\">curl -f</code> and stop on error) or the chain was altered. Re-export; if the break persists at the same sequence, treat it as a finding.</td></tr>\n<tr><td class=\"\">Verifier: a checkpoint's <code class=\"notion\">head_hash</code> differs from the manifest at the same <code class=\"notion\">sequence</code></td><td class=\"\">The chain reached that sequence with a different head than the one signed at checkpoint time: the strongest signal of tampering the model offers. Report it.</td></tr>\n</tbody>\n</table>\n\n<h3 class=\"\">Where to go next</h3>\n<ul class=\"bulleted-list\">\n<li style=\"list-style-type:disc\">The complete API reference, field by field: <a href=\"/guides/guide-audit-log\" class=\"fancy-link\">Audit Log API guide</a></li>\n<li style=\"list-style-type:disc\">Every field and error of the signing configuration: <a href=\"/guides/guide-audit-signing\" class=\"fancy-link\">Audit Signing guide</a>, the <a href=\"/resources/audit-signing-1\" class=\"fancy-link\">REST resource</a> and the <a href=\"/terraform/terraform-8\" class=\"fancy-link\">Terraform example</a></li>\n<li style=\"list-style-type:disc\">The export and verification scripts as a resource: <a href=\"/resources/audit-log-1\" class=\"fancy-link\">Audit Log: export and verify a project's trail</a></li>\n<li style=\"list-style-type:disc\">Let a coding agent run the export for you: the <a href=\"/agent-skills/indykite-audit-logs/SKILL.md\" class=\"fancy-link\">indykite-audit-logs</a> skill</li>\n<li style=\"list-style-type:disc\">The same events as a live stream: <a href=\"/guides/guide-outbound-events\" class=\"fancy-link\">Outbound Events guide</a></li>\n</ul>",
      "links": {
        "html": "/tutorials/tutorial-audit-trail#chapter-7",
        "markdown": "/tutorials/tutorial-audit-trail/7.md"
      }
    }
  ],
  "links": {
    "html": "/tutorials/tutorial-audit-trail",
    "markdown": "/tutorials/tutorial-audit-trail.md"
  }
}