{
  "id": "tutorial-audit-acceptance",
  "title": "Accept a tamper-proof audit log deployment: produce, read, verify",
  "description": "A go/no-go test for a freshly deployed tamper-proof audit log: produce a handful of audit events, read the signed batches and the public keys back through the API, verify one page offline with a single-file Go program, read every line of its output, then break the page on purpose and watch it fail.",
  "category": "Audit Log",
  "order": 31,
  "image": "/assets/images/categories/card-audit.svg",
  "summary": "Five short chapters that take a deployment from 'the service is up' to 'the trail verifies': the credentials and URLs you need, a few events, two API calls, one verifier run, and how to read what it says before you lock the retention.",
  "body": "<p class=\"notion pdf-download\">Download the whole tutorial, all five chapters, as a PDF: <a href=\"/assets/downloads/tutorial-audit-acceptance.pdf\" class=\"fancy-link\" target=\"_blank\">tutorial-audit-acceptance.pdf</a>.</p>\n\n<p class=\"notion\">A tamper-proof audit log is only worth its name once someone outside the platform has verified it. This tutorial is that first verification, written as an acceptance test: short enough to run in an afternoon, exact enough to be the gate before the one-way decisions of a dedicated deployment, such as locking the bucket's retention. It works just as well against the shared IndyKite platform, where the infrastructure is not yours but the proof still is.</p>\n<p class=\"notion\">It uses <code class=\"notion\">curl</code>, <code class=\"notion\">jq</code> and one Go file you download. Nothing here needs the Hub beyond the credentials you create there once.</p>\n\n<h3 class=\"\">What you will have at the end</h3>\n<ol type=\"1\" class=\"numbered-list\" start=\"1\">\n<li>Audit events of your own in the project's chain: Capture upserts and configuration reads.</li>\n<li>Two saved API responses: a page of signed batches and the JWK Set that signed them.</li>\n<li>A verifier you ran yourself, which recomputed every batch hash, checked every signature against the published keys and followed every chain link on the page.</li>\n<li>The ability to read its output: what each failure line means, which ones point at the data and which at the keys.</li>\n<li>Proof that the verifier bites: the same page altered by one character, and the lines that catch it.</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> and its GID, a <strong>Service Account</strong> credential for the Config API, and an <strong>Application Agent</strong> credential holding the <code class=\"notion\">Audit</code> and <code class=\"notion\">Capture</code> API permissions. Chapter 1 lists where each comes from.</li>\n<li style=\"list-style-type:disc\">A destination you own for an <strong>Event Sink</strong> (a Kafka topic, a Pub/Sub topic, an Event Grid topic or a Service Bus queue): the chain holds only the events a sink of the project delivered, so chapter 2 creates one, together with the Audit Signing configuration that switches the chain on.</li>\n<li style=\"list-style-type:disc\"><code class=\"notion\">curl</code>, <code class=\"notion\">jq</code>, and <strong>Go 1.25 or later</strong> for chapter 4.</li>\n<li style=\"list-style-type:disc\">For a dedicated deployment: the public API host of that deployment, and someone on the platform side who can tell you the integrity verifier's last exit code (chapter 5).</li>\n</ul>\n\n<h3 class=\"\">Who this tutorial is for</h3>\n<p class=\"notion\">Platform and security engineers accepting a dedicated deployment of the audit log, as described in the <a href=\"/guides/guide-audit-infrastructure\" class=\"fancy-link\">infrastructure guide</a>; compliance teams who want a repeatable spot check; and anyone who prefers a single Go file to a Python environment. For the full export, with manifests and checkpoints, and the operating habits around it, continue with the <a href=\"/tutorials/tutorial-audit-trail\" class=\"fancy-link\">audit trail tutorial</a>.</p>\n\n<h3 class=\"\">The flow at a glance</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 ties them to a published key\"/></figure>",
  "chapterCount": 5,
  "chapters": [
    {
      "chapter": 1,
      "title": "What you need",
      "description": "The project, the two credentials and their permissions, the API host of a shared or dedicated deployment, and the shell variables the next chapters use.",
      "body": "<h2 class=\"\">Chapter 1: What you need</h2>\n\n<p class=\"notion\">Four values and two tools. Everything else is created along the way.</p>\n\n<h3 class=\"\">Step 1: The project and its credentials</h3>\n<table class=\"simple-table\">\n<tbody>\n<tr>\n<td class=\"simple-table-header-color\"><strong>What</strong></td>\n<td class=\"simple-table-header-color\"><strong>Used for</strong></td>\n<td class=\"simple-table-header-color\"><strong>Where it comes from</strong></td>\n</tr>\n<tr><td class=\"\">Project GID</td><td class=\"\">The <code class=\"notion\">project_id</code> of every Audit Log API call.</td><td class=\"\">The <a href=\"/resources/environment-1\" class=\"fancy-link\">environment setup example</a> creates one with the Config API; an existing project's GID is in its read response.</td></tr>\n<tr><td class=\"\">Service Account token</td><td class=\"\">The Config API calls that produce configuration events (chapter 2).</td><td class=\"\">The <a href=\"/guides/guide-credentials\" class=\"fancy-link\">Credentials guide</a>; a credential created with an <code class=\"notion\">expire_time</code> carries a ready-to-use <code class=\"notion\">token</code>.</td></tr>\n<tr><td class=\"\">Application Agent credential with <code class=\"notion\">Audit</code> and <code class=\"notion\">Capture</code></td><td class=\"\"><code class=\"notion\">Capture</code> for the events of chapter 2, <code class=\"notion\">Audit</code> for reading the trail in chapter 3. Add <code class=\"notion\">Authorization</code> or <code class=\"notion\">ContXIQ</code> too if you want decision or query events in the trail.</td><td class=\"\">Set <code class=\"notion\">api_permissions</code> when creating the agent, or add the values to an existing agent with <code class=\"notion\">PUT /configs/v1/application-agents/{id}</code>; see the <a href=\"/guides/guide-environment\" class=\"fancy-link\">Environment guide</a>.</td></tr>\n<tr><td class=\"\">API host</td><td class=\"\">Every call.</td><td class=\"\">Shared platform: <code class=\"notion\">https://us.api.indykite.com</code> or <code class=\"notion\">https://eu.api.indykite.com</code>, the region of the project. Dedicated deployment: the public host under your domain that the deployment exposes, for example <code class=\"notion\">https://api.example.com</code>. The paths are identical.</td></tr>\n</tbody>\n</table>\n<p class=\"notion\">An agent without <code class=\"notion\">Audit</code> gets <code class=\"notion\">401</code> and <code class=\"notion\">insufficient API access level for appAgent</code> on every Audit Log endpoint except the JWK Set, which needs no permission.</p>\n\n<h3 class=\"\">Step 2: Export the variables</h3>\n<p class=\"notion\">The next chapters use these names. Put them in a file you <code class=\"notion\">source</code>, so the verifier's input files and the curl calls agree:</p>\n<pre class=\"code\"><code class=\"language-Bash\">export API_URL=https://us.api.indykite.com   # or https://eu.api.indykite.com, or https://api.&lt;your-domain&gt;\nexport PROJECT_ID=\"gid:YOUR_PROJECT_GID\"\nexport SA_TOKEN=\"&lt;token from the Service Account credentials file&gt;\"\nexport CLIENT_KEY=\"&lt;token from the Application Agent credentials file&gt;\"</code></pre>\n<p class=\"notion\">Check the agent before producing anything: a <code class=\"notion\">200</code> here, even with an empty <code class=\"notion\">items</code> array, means the host, the credential and the permission are right.</p>\n<pre class=\"code\"><code class=\"language-Bash\">curl -sS -o /dev/null -w \"%{http_code}\\n\" \"$API_URL/audit/v1/logs?project_id=$PROJECT_ID&amp;pagesize=1\" \\\n  -H \"X-IK-ClientKey: $CLIENT_KEY\" -H \"Accept: application/json\"</code></pre>\n\n<h3 class=\"\">Step 3: The tools</h3>\n<ul class=\"bulleted-list\">\n<li style=\"list-style-type:disc\"><code class=\"notion\">curl</code> and <code class=\"notion\">jq</code>, for the calls and for looking at what comes back.</li>\n<li style=\"list-style-type:disc\"><strong>Go 1.25 or later</strong> (<code class=\"notion\">go version</code>). The verifier is one file with no dependencies outside the standard library; it is run with <code class=\"notion\">go run</code>, nothing is installed.</li>\n</ul>\n<p class=\"notion\">How this differs from the <a href=\"/tutorials/tutorial-audit-trail\" class=\"fancy-link\">audit trail tutorial</a>: that one exports a whole chain, manifests and checkpoints included, and verifies all of it with a Python script. This one verifies a single page of batches with a Go program and stops. It is the quick gate, not the archive.</p>",
      "links": {
        "html": "/tutorials/tutorial-audit-acceptance#chapter-1",
        "markdown": "/tutorials/tutorial-audit-acceptance/1.md"
      }
    },
    {
      "chapter": 2,
      "title": "Produce events",
      "description": "Put a few audit events of each kind into the chain: Capture upserts with the sample dataset, and configuration reads and lists with the Config API.",
      "body": "<h2 class=\"\">Chapter 2: Produce events</h2>\n\n<p class=\"notion\">A chain with nothing in it cannot be verified. First the two configurations the chain depends on, then two kinds of calls you would make anyway: a Capture ingest and a couple of Config API reads.</p>\n\n<h3 class=\"\">Step 1: Switch the chain on</h3>\n<p class=\"notion\">An event is chained only when the project has an <a href=\"/guides/guide-audit-signing\" class=\"fancy-link\">Audit Signing</a> configuration and an <a href=\"/guides/guide-outbound-events\" class=\"fancy-link\">Event Sink</a> of the project delivered the event to at least one destination. Both are Config API objects; skip whichever the project already has.</p>\n<pre class=\"code\"><code class=\"language-Bash\">curl -sS -X POST \"$API_URL/configs/v1/audit-signings\" \\\n  -H \"Authorization: Bearer $SA_TOKEN\" -H \"Content-Type: application/json\" \\\n  -d '{ \"project_id\": \"'\"$PROJECT_ID\"'\", \"name\": \"audit-signing\", \"provider\": \"PLATFORM_MANAGED\" }'\ncurl -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\": \"acceptance-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 sink's destination must accept deliveries: an event the destination rejects, or that no route matches, is not chained. The Outbound Events guide shows the Pub/Sub, Event Grid and Service Bus forms and how to read a provider's <code class=\"notion\">last_error</code>. A project has one Event Sink; if one exists, add a route on <code class=\"notion\">indykite.audit.*</code> to it instead of creating another.</p>\n\n<h3 class=\"\">Step 2: Capture the sample dataset</h3>\n<p class=\"notion\">The two files are the ones the <a href=\"/guides/guide-data-schema\" class=\"fancy-link\">Data Schema guide</a> uses: eight nodes and five relationships of a car-rental company.</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></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></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\">Each node becomes one <code class=\"notion\">indykite.audit.capture.upsert.node</code> event and each relationship one <code class=\"notion\">indykite.audit.capture.upsert.relationship</code> event. Both calls are upserts, so running them again is harmless to the graph and adds another round of events, which is useful if you want more than one page later.</p>\n\n<h3 class=\"\">Step 3: Read and list configuration</h3>\n<p class=\"notion\">Reads and lists are audited too, not only writes. Two Service Account calls that change nothing:</p>\n<pre class=\"code\"><code class=\"language-Bash\">curl -sS \"$API_URL/configs/v1/token-introspects?project_id=$PROJECT_ID\" \\\n  -H \"Authorization: Bearer $SA_TOKEN\" -H \"Accept: application/json\" | jq '.data | length'\ncurl -sS \"$API_URL/configs/v1/projects/$PROJECT_ID\" \\\n  -H \"Authorization: Bearer $SA_TOKEN\" -H \"Accept: application/json\" | jq '{name, ikg_status}'</code></pre>\n<p class=\"notion\">The list leaves an <code class=\"notion\">indykite.audit.config.list</code> event carrying the IDs it returned, the read an <code class=\"notion\">indykite.audit.config.read</code> event. If you also hold <code class=\"notion\">Authorization</code> or <code class=\"notion\">ContXIQ</code> on the agent, an AuthZEN evaluation or a Knowledge Query execution adds the <code class=\"notion\">authorization.*</code> and <code class=\"notion\">ciq.execute</code> families; the <a href=\"/guides/guide-outbound-events\" class=\"fancy-link\">Outbound Events guide</a> lists every event type.</p>\n\n<h3 class=\"\">Step 4: Wait for the batch</h3>\n<p class=\"notion\">Events reach the chain in batches, cut by size or by time, so the first page may lag the calls by a short while. The next chapter's first call tells you when it is there: a non-empty <code class=\"notion\">items</code> array whose last event is one you just produced.</p>",
      "links": {
        "html": "/tutorials/tutorial-audit-acceptance#chapter-2",
        "markdown": "/tutorials/tutorial-audit-acceptance/2.md"
      }
    },
    {
      "chapter": 3,
      "title": "Read the trail and the keys",
      "description": "Save a page of signed batches and the JWK Set as two files, look at what a batch contains, and check that the key each batch names is one the platform publishes.",
      "body": "<h2 class=\"\">Chapter 3: Read the trail and the keys</h2>\n\n<p class=\"notion\">Two calls, two files. Save the responses exactly as served, since the verifier recomputes hashes over the bytes of <code class=\"notion\">data</code>; <code class=\"notion\">curl -o</code> does that, a copy-paste through an editor may not.</p>\n\n<h3 class=\"\">Step 1: A page of batches</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\" -H \"Accept: application/json\" \\\n  -o response-logs.json\njq '{batches: (.items | length), first: .items[0].sequence, last: .items[-1].sequence, has_more, next_cursor}' response-logs.json</code></pre>\n<p class=\"notion\">Batches come oldest first. A page is at most <code class=\"notion\">pagesize</code> batches; <code class=\"notion\">has_more</code> says whether there are more, and <code class=\"notion\">next_cursor</code> is what you pass as <code class=\"notion\">cursor=</code> to get them. For the acceptance test one page is enough; the <a href=\"/guides/guide-audit-log\" class=\"fancy-link\">Audit Log guide</a> has the paging rules for a full export.</p>\n<p class=\"notion\">What one batch carries, and what the verifier will do with each field:</p>\n<pre class=\"code\"><code class=\"language-Bash\">jq '.items[0] | {sequence, batch_id, kid, alg, hash, chain_hash, manifest_id, events: (.data | length), first_event: .data[0].eventType}' response-logs.json</code></pre>\n<table class=\"simple-table\">\n<tbody>\n<tr>\n<td class=\"simple-table-header-color\"><strong>Field</strong></td>\n<td class=\"simple-table-header-color\"><strong>Meaning</strong></td>\n<td class=\"simple-table-header-color\"><strong>Checked how</strong></td>\n</tr>\n<tr><td class=\"\"><code class=\"notion\">data</code></td><td class=\"\">The events of the batch, a JSON array, as the platform received them.</td><td class=\"\">Its SHA-256 must equal <code class=\"notion\">hash</code>.</td></tr>\n<tr><td class=\"\"><code class=\"notion\">hash</code>, <code class=\"notion\">signature</code>, <code class=\"notion\">kid</code>, <code class=\"notion\">alg</code></td><td class=\"\">The digest of <code class=\"notion\">data</code>, its signature, the key that made it and the algorithm, always <code class=\"notion\">ES256-DER</code>.</td><td class=\"\">The signature must verify over <code class=\"notion\">hash</code> under the JWK with that <code class=\"notion\">kid</code>.</td></tr>\n<tr><td class=\"\"><code class=\"notion\">sequence</code>, <code class=\"notion\">chain_hash</code>, <code class=\"notion\">batch_id</code>, <code class=\"notion\">project_id</code></td><td class=\"\">The batch's position, the head of the chain after it, and the identifiers that go into the head.</td><td class=\"\"><code class=\"notion\">chain_hash</code> must equal the SHA-256 of <code class=\"notion\">project_id|sequence|previous chain_hash|hash|batch_id</code>; sequences must be consecutive.</td></tr>\n<tr><td class=\"\"><code class=\"notion\">manifest_id</code></td><td class=\"\">The manifest that records this batch in the chain.</td><td class=\"\">Not on this page; the full export verifies manifests and checkpoints.</td></tr>\n</tbody>\n</table>\n\n<h3 class=\"\">Step 2: The JWK Set</h3>\n<p class=\"notion\">The public keys need no credential: anyone may verify.</p>\n<pre class=\"code\"><code class=\"language-Bash\">curl -sS \"$API_URL/audit/.well-known/jwks.json?project_id=$PROJECT_ID\" -o response-jwks.json\njq '.keys[] | {kid, kty, crv}' response-jwks.json</code></pre>\n<p class=\"notion\">Each key is an EC P-256 public key with a <code class=\"notion\">kid</code>. Before running anything, confirm the page and the keys talk about the same key:</p>\n<pre class=\"code\"><code class=\"language-Bash\">jq -r '.items[].kid' response-logs.json | sort -u          # kids the page uses\njq -r '.keys[].kid' response-jwks.json | sort -u            # kids the platform publishes</code></pre>\n<p class=\"notion\">Every value of the first list must appear in the second. On a dedicated deployment the <code class=\"notion\">kid</code> is the key identifier agreed at hand-over, the one the deployment was configured to stamp on every signature. If it is not that value, stop here; the deployment signs with a key, or a configuration, you did not intend.</p>\n\n<h3 class=\"\">Step 3: Keep the keys independently</h3>\n<p class=\"notion\">A verification is only as trustworthy as its keys. Fetch the JWK Set yourself, from the API, and keep it with the export; never accept the keys from whoever hands you the export, since one party controlling both could have signed both. The <code class=\"notion\">Cache-Control</code> header of the JWK Set response says how long the set may be reused.</p>",
      "links": {
        "html": "/tutorials/tutorial-audit-acceptance#chapter-3",
        "markdown": "/tutorials/tutorial-audit-acceptance/3.md"
      }
    },
    {
      "chapter": 4,
      "title": "Run the verifier",
      "description": "Run the single-file Go verifier on the saved page and keys, understand the five checks it makes on every batch, and read its exit codes.",
      "body": "<h2 class=\"\">Chapter 4: Run the verifier</h2>\n\n<p class=\"notion\">The verifier needs the two files from chapter 3 and nothing else: no credential, no network, no IndyKite. It is a single Go file using only the standard library.</p>\n\n<h3 class=\"\">Step 1: Run it</h3>\n<p class=\"notion\">Download <a href=\"/assets/downloads/audit-verify.go\" class=\"fancy-link\" download=\"audit-verify.go\">audit-verify.go</a> next to the two files and run:</p>\n<pre class=\"code\"><code class=\"language-Bash\">go run audit-verify.go -logs response-logs.json -jwks response-jwks.json</code></pre>\n<pre class=\"code\"><code class=\"language-Text\">OK   seq=1 batch=bf76b15c-9fc6-49bb-adca-10622039f65c events=17\nOK   seq=2 batch=311bbd81-6c0c-4ec1-9e8e-aac8d7a79033 events=2\nOK   seq=3 batch=7d722889-e005-413c-af18-4ce0d6bfc03b events=2\n…\nOK   seq=29 batch=2106a710-eb39-4266-aca9-ea809ddf6465 events=1\n29 batches, 0 failed</code></pre>\n<p class=\"notion\">One line per batch, oldest first, with the number of events it holds, then a summary. The sequence numbers are yours; the first batch of a new project is <code class=\"notion\">seq=1</code> and usually the largest, since the project's creation and setup left many events before the first batch was cut.</p>\n\n<h3 class=\"\">Step 2: What it checks, per batch</h3>\n<ol type=\"1\" class=\"numbered-list\" start=\"1\">\n<li><strong>The batch hash.</strong> <code class=\"notion\">data</code> is re-encoded as compact JSON, exactly the bytes the platform hashed, and its SHA-256 must equal <code class=\"notion\">hash</code>. This is why the response must be saved as served: re-encoding restores the bytes even if the file was pretty-printed, but a changed character in any event changes the digest.</li>\n<li><strong>The signature.</strong> <code class=\"notion\">alg</code> must be <code class=\"notion\">ES256-DER</code>; the key named by <code class=\"notion\">kid</code> must be in the JWK Set; and the DER-encoded ECDSA signature, Base64-decoded, must verify over the digest that <code class=\"notion\">hash</code> stands for. A signature that verifies proves the platform's key produced it; the hash check then ties <code class=\"notion\">data</code> to it.</li>\n<li><strong>The chain link.</strong> <code class=\"notion\">chain_hash</code> must equal the SHA-256 of <code class=\"notion\">project_id|sequence|previous chain_hash|hash|batch_id</code>, where the previous <code class=\"notion\">chain_hash</code> is the one of the batch before. For the first batch on the page the previous value is empty when the page starts at sequence 1; otherwise pass it with <code class=\"notion\">-prev</code>, or the first link is reported as not checked.</li>\n<li><strong>Continuity.</strong> Each sequence must be the previous one plus one: a missing or reordered batch is reported even when every batch verifies on its own.</li>\n<li><strong>One project.</strong> Every batch on the page must carry the same <code class=\"notion\">project_id</code>.</li>\n</ol>\n<p class=\"notion\">The checks run on every batch and all problems are printed; one bad batch does not hide the state of the batches after it, because each link is checked against what the previous batch <em>records</em>, not against what was recomputed.</p>\n\n<h3 class=\"\">Step 3: Exit codes</h3>\n<table class=\"simple-table\">\n<tbody>\n<tr>\n<td class=\"simple-table-header-color\"><strong>Exit code</strong></td>\n<td class=\"simple-table-header-color\"><strong>Meaning</strong></td>\n</tr>\n<tr><td class=\"\"><code class=\"notion\">0</code></td><td class=\"\">Every batch on the page passed every check.</td></tr>\n<tr><td class=\"\"><code class=\"notion\">1</code></td><td class=\"\">At least one batch failed a check; the lines above the summary say which and why.</td></tr>\n<tr><td class=\"\"><code class=\"notion\">2</code></td><td class=\"\">The verifier could not run: a file is missing or not JSON, the JWK Set has no usable P-256 key, or the page has no items. Nothing was verified.</td></tr>\n</tbody>\n</table>\n<p class=\"notion\">The exit code makes it a pipeline step: a nightly job that fetches one page and the keys and fails the build on anything but <code class=\"notion\">0</code> is a reasonable first monitor, independent of the platform's own integrity verifier.</p>\n\n<h3 class=\"\">Step 4: A later page</h3>\n<p class=\"notion\">To verify a page that does not start at sequence 1, take the <code class=\"notion\">chain_hash</code> of the last batch of the page before it:</p>\n<pre class=\"code\"><code class=\"language-Bash\">PREV=$(jq -r '.items[-1].chain_hash' response-logs.json)\nCURSOR=$(jq -r '.next_cursor' response-logs.json)\ncurl -sS \"$API_URL/audit/v1/logs?project_id=$PROJECT_ID&amp;pagesize=50&amp;cursor=$CURSOR\" \\\n  -H \"X-IK-ClientKey: $CLIENT_KEY\" -H \"Accept: application/json\" -o response-logs-2.json\ngo run audit-verify.go -logs response-logs-2.json -jwks response-jwks.json -prev \"$PREV\"</code></pre>\n<p class=\"notion\">The last line of the summary tells you when you are done: it repeats <code class=\"notion\">has_more</code> and the cursor to fetch next while the chain continues.</p>",
      "links": {
        "html": "/tutorials/tutorial-audit-acceptance#chapter-4",
        "markdown": "/tutorials/tutorial-audit-acceptance/4.md"
      }
    },
    {
      "chapter": 5,
      "title": "Read the result, then break it",
      "description": "What each failure line of the verifier means and where to look, two deliberate alterations that make it fail, and what to do after the test passes: the full export, the platform-side checks, and the retention lock.",
      "body": "<h2 class=\"\">Chapter 5: Read the result, then break it</h2>\n\n<h3 class=\"\">Step 1: The failure lines</h3>\n<p class=\"notion\">A failed batch prints <code class=\"notion\">FAIL</code> instead of <code class=\"notion\">OK</code> and one indented line per problem. What each one means:</p>\n<table class=\"simple-table\">\n<tbody>\n<tr>\n<td class=\"simple-table-header-color\"><strong>Line</strong></td>\n<td class=\"simple-table-header-color\"><strong>Meaning</strong></td>\n<td class=\"simple-table-header-color\"><strong>Where to look</strong></td>\n</tr>\n<tr><td class=\"\"><code class=\"notion\">data hashes to …, batch records …</code></td><td class=\"\">The events are not the bytes that were signed.</td><td class=\"\">The file was altered or re-serialised after download, or the stored batch differs from what was signed: the strongest tampering signal there is.</td></tr>\n<tr><td class=\"\"><code class=\"notion\">signature does not verify under kid \"…\"</code></td><td class=\"\">The signature is not over this <code class=\"notion\">hash</code> with this key.</td><td class=\"\"><code class=\"notion\">hash</code> or <code class=\"notion\">signature</code> was altered, or the JWK Set is not the platform's. Re-fetch the keys yourself first.</td></tr>\n<tr><td class=\"\"><code class=\"notion\">kid \"…\" is not in the JWKS</code></td><td class=\"\">The page names a key the JWK Set does not publish.</td><td class=\"\">A stale or foreign JWK Set, or, on a dedicated deployment, a signing key that was changed: compare with what your key-management team handed over.</td></tr>\n<tr><td class=\"\"><code class=\"notion\">alg is \"…\", want \"ES256-DER\"</code></td><td class=\"\">An algorithm the platform never uses.</td><td class=\"\">The record was altered.</td></tr>\n<tr><td class=\"\"><code class=\"notion\">chain_hash recomputes to …, batch records …</code></td><td class=\"\">The link to the previous batch is broken.</td><td class=\"\">A batch was inserted, removed or replaced before this one, or the wrong <code class=\"notion\">-prev</code> was passed for the first batch of the page.</td></tr>\n<tr><td class=\"\"><code class=\"notion\">sequence N follows M</code></td><td class=\"\">A gap or reordering.</td><td class=\"\">A batch is missing from the page or the page was edited.</td></tr>\n<tr><td class=\"\"><code class=\"notion\">chain link to the previous batch not checked: pass -prev</code></td><td class=\"\">Not a failure: the page does not start at sequence 1 and no previous head was given.</td><td class=\"\">Chapter 4, step 4.</td></tr>\n</tbody>\n</table>\n\n<h3 class=\"\">Step 2: Break the page on purpose</h3>\n<p class=\"notion\">A verifier that has never failed proves nothing. Two alterations, each on a copy:</p>\n<pre class=\"code\"><code class=\"language-Bash\">jq '.items[0].data[0].eventType |= sub(\"indykite\";\"indykyte\")' response-logs.json > tampered-data.json   # 1: one character changed inside an event\ngo run audit-verify.go -logs tampered-data.json -jwks response-jwks.json; echo \"exit=$?\"\njq 'del(.items[1])' response-logs.json > tampered-gap.json                                                 # 2: a batch dropped from the middle of the page\ngo run audit-verify.go -logs tampered-gap.json -jwks response-jwks.json; echo \"exit=$?\"</code></pre>\n<p class=\"notion\">The first copy fails its first batch on <code class=\"notion\">data hashes to …</code>: the hash no longer matches, and nothing else, since the signature was never over the altered bytes but over the recorded hash, which is intact. The second copy fails on batch 3 with both <code class=\"notion\">sequence 3 follows 1</code> and <code class=\"notion\">chain_hash recomputes to …</code>: its link was computed from batch 2's head, which is no longer on the page. Both exit with <code class=\"notion\">1</code>. Delete the copies afterwards; keep only what was served.</p>\n\n<h3 class=\"\">Step 3: After the test passes</h3>\n<ul class=\"bulleted-list\">\n<li style=\"list-style-type:disc\"><strong>Run the full export once.</strong> This page proves the batches; the <a href=\"/tutorials/tutorial-audit-trail\" class=\"fancy-link\">audit trail tutorial</a> exports manifests and checkpoints as well and verifies the chain end to end with <a href=\"/resources/audit-log-1\" class=\"fancy-link\">audit-export.sh and audit-verify.py</a>. A checkpoint is what later proves the chain was not quietly truncated, so an acceptance without one is incomplete.</li>\n<li style=\"list-style-type:disc\"><strong>Ask for the integrity verifier's exit code</strong> on a dedicated deployment. The platform's own scheduled verifier reads the stored chains directly: <code class=\"notion\">0</code> is clean, <code class=\"notion\">2</code> means findings, any other value means the job failed to run. Your page check and its run should agree; if yours passes and it reports findings, the stored chain differs from what the API serves, which is exactly the case it exists for. The <a href=\"/guides/guide-audit-infrastructure\" class=\"fancy-link\">infrastructure guide</a> lists the alerts to put on it and on the dead-letter queue.</li>\n<li style=\"list-style-type:disc\"><strong>Then take the one-way decision.</strong> Lock the write-once bucket's retention (GCP) or switch it to <code class=\"notion\">COMPLIANCE</code> mode (AWS) only now, with this test and the full export as the evidence that the pipeline works in that environment. Before the lock, a project owner could still remove the policy; after it, nobody can.</li>\n<li style=\"list-style-type:disc\"><strong>Repeat on a schedule.</strong> The two curl calls and the <code class=\"notion\">go run</code> are a four-line job. Keep every page and JWK Set it fetches: a chain verified today and a chain verified next month, together, prove that nothing between the two was rewritten.</li>\n</ul>",
      "links": {
        "html": "/tutorials/tutorial-audit-acceptance#chapter-5",
        "markdown": "/tutorials/tutorial-audit-acceptance/5.md"
      }
    }
  ],
  "links": {
    "html": "/tutorials/tutorial-audit-acceptance",
    "markdown": "/tutorials/tutorial-audit-acceptance.md"
  }
}