On a Launch HN thread earlier this month, someone put the security-review question plainly: "On Salesforce projects, security teams approve an integration user with narrow permissions and an audit log much sooner than any kind of browser automation. Can the generated MCP run under a dedicated service account and log every call? Then I could bring it to a client's security review." (comment, 15 November.)
That's the right instinct. A security reviewer doesn't ask what the agent is for. They ask who it is, what it can reach, and what you'll be able to show them afterwards. For a retrieval agent the last one comes down to a single question, and our audit spec opens with it: "Show me which documents your agent read last quarter."
So I set it up the way the commenter describes. One service account for a bot, read access to one layer, a few things for it to try, and then the log. Everything below ran today on a clean install from the quickstart, version 0.41.4.
The setup
The quickstart's demo company has three layers: handbook, engineering and contracts. The bot gets its own service account and a single grant, read on handbook. It isn't a delegation acting for some person (that's the other kind of connection, covered in an earlier piece). It's an identity of its own, which is what a client's security team usually wants to see for an unattended integration.
#!/usr/bin/env bash
# A support bot with one layer, the things it tries, and what the access log says about each.
# Against a local quickstart: demo-seed prints the admin's email and password.
# ADMIN_EMAIL=... ADMIN_PASSWORD=... ./audit-demo.sh
set -euo pipefail
API=${API:-http://localhost:8082}
Q='what is the contract number for Northwind'
# 1. Sign in as the org admin, the role that can read the full log.
ADMIN=$(curl -s "$API/v1/auth/login" -H 'content-type: application/json' \
-d "{\"email\":\"$ADMIN_EMAIL\",\"password\":\"$ADMIN_PASSWORD\"}" | jq -r .access_token)
HANDBOOK=$(curl -s "$API/v1/layers" -H "authorization: Bearer $ADMIN" \
| jq -r '.items[]|select(.slug=="handbook").id')
# 2. A service account for the bot, with read on the handbook and nothing else.
SA=$(curl -s "$API/v1/service-accounts" -H "authorization: Bearer $ADMIN" \
-H 'content-type: application/json' -d '{"name":"svc-support-bot"}')
SA_ID=$(jq -r .id <<<"$SA"); KEY=$(jq -r .key <<<"$SA")
curl -s -o /dev/null "$API/v1/grants" -H "authorization: Bearer $ADMIN" -H 'content-type: application/json' \
-d "{\"principal_type\":\"service_account\",\"principal_id\":\"$SA_ID\",\"scope_type\":\"layer\",\"scope_id\":\"$HANDBOOK\",\"permission\":\"read\"}"
# 3. The bot asks the question twice, the way a retry would.
for i in 1 2; do
curl -s "$API/v1/search" -H "authorization: Bearer $KEY" -H 'content-type: application/json' \
-d "{\"query\":\"$Q\",\"top_k\":10}" | jq -c '{returned: [.items[].doc_id]}'
done
# 4. It tries to open the Northwind contract by id. (The admin looks it up, to give it something real to try.)
DOC=$(curl -s "$API/v1/search" -H "authorization: Bearer $ADMIN" -H 'content-type: application/json' \
-d "{\"query\":\"$Q\",\"top_k\":10}" | jq -r '[.items[]|select(.layer=="contracts")][0].doc_id')
echo "bot GET /v1/documents/$DOC -> $(curl -s -o /dev/null -w '%{http_code}' "$API/v1/documents/$DOC" -H "authorization: Bearer $KEY")"
# 5. Revoke the bot, and let it try once more.
curl -s -o /dev/null -X DELETE "$API/v1/service-accounts/$SA_ID" -H "authorization: Bearer $ADMIN"
echo "after revoke, search -> $(curl -s -o /dev/null -w '%{http_code}' "$API/v1/search" -H "authorization: Bearer $KEY" \
-H 'content-type: application/json' -d "{\"query\":\"$Q\"}")"
# 6. What the log says the bot did, oldest first.
curl -s "$API/v1/audit?actor_id=$SA_ID" -H "authorization: Bearer $ADMIN" -H 'accept: application/x-ndjson' | tac
What the bot saw
{"returned":["9892de13-…","4845b3eb-…","51d8eee9-…"]}
{"returned":["9892de13-…","4845b3eb-…","51d8eee9-…"]}
bot GET /v1/documents/7f109178-… -> 404
after revoke, search -> 401
Three handbook documents, twice. The question was about a contract, and the contract isn't in its reach, so the search simply returns what the bot is allowed to have. Asked for the contract by id, it gets 404, the same answer as a document that doesn't exist. Once the account is revoked, the key stops working on the next request. The API spec says there's "no TTL and no propagation window" for a revoked key, and that's what happened.
What the log says
Three lines for the bot, trimmed only for width:
{"id":"53","actor":{"type":"service_account","id":"b4d0de7d-…"},"surface":"api","action":"search",
"target":{"layers":["handbook"],"returned_docs":["9892de13-…","4845b3eb-…","51d8eee9-…"],"top_k":10},
"result":"allow","detail":{"returned":3,"latency_ms":38,"query_hash":"sha256:5c6038…a9a9"}}
{"id":"54", … same search, same three returned_docs, "query_hash":"sha256:5c6038…a9a9" …}
{"id":"56","actor":{"type":"service_account","id":"b4d0de7d-…"},"surface":"api","action":"get_document",
"target":{"document_id":"7f109178-…"},"result":"deny"}
What made me trust it:
Every search names the documents it returned. Not "the bot searched", but which three documents left the index, from which layer. That's the line a reviewer actually asks for, since one query can hand an agent ten documents and each of them is an access.
The query itself isn't stored, but you can still match it. By default the log keeps a SHA-256 of the query rather than its text, so the journal doesn't turn into a second copy of everything people asked. Both searches carry the same hash, so "did the bot run this query, and how often" is still answerable: hash the question you're investigating and compare. Turn on NACRE_AUDIT_QUERY_TEXT if your reviewer wants the text.
The refusal is a line of its own. Line 56 is the attempt on the contract, result: "deny", with the document id it asked for. On the wire that was a 404 that says nothing, but in the log it's the most useful entry. The spec is blunt about it: "result: "deny" is the most useful line in the file and the easiest to forget to write, because the code path that produces it is an early return."
The administrator is in it too. Reading the whole log without the filter also shows the other side: create_service_account with the bot's name, issue_grant naming the layer and read, revoke_service_account, and an audit.read for each time I read the log. A reviewer can see who gave the bot its access, as well as what the bot did with it.
Over MCP, the same thing
The commenter asked about MCP specifically, so I checked that too. A second service account, the same grant, the same question, this time through the MCP server's search tool over Streamable HTTP with the key as the bearer token. Same three handbook documents, and the log line is the same shape with one field different: "surface":"mcp". The MCP server and the REST API share one audit sink, so you don't get a second, thinner log for agents.
Can someone quietly edit it?
Not from the application. Append-only is enforced in the database, not by the code being polite. I took the deny row above and tried, as the application's own Postgres role:
nacre=> delete from audit_events where id = 56;
ERROR: permission denied for table audit_events
nacre=> update audit_events set result = 'allow' where id = 56;
ERROR: permission denied for table audit_events
A database superuser can still do anything. That's true of every log that lives in a database, and it's why the SIEM forwarding exists, for when the copy has to live somewhere your own admins can't reach.
What it didn't show
Two things I'd want to know before a review, rather than during one.
The revoked key's attempt left no line. The search that got 401 after revocation isn't in the log, filtered by the bot or unfiltered. Refusals of a principal that signed in are recorded, but a request that never authenticates has no principal to attach a line to. If your reviewer asks about failed authentication against a revoked credential, that answer comes from your gateway or reverse-proxy logs, not from this one.
The actor label is the id, not the name. The spec's example shows a readable label for a service account, while today's lines carried service_account:<id>. The name is one lookup away, in the create_service_account event or GET /v1/service-accounts, but a CSV export handed to a reviewer is easier to read if you join it first.
And the boundary that matters most: the log records what retrieval handed to the agent. What the agent then did with those three documents, what it wrote, who it sent it to, happens in your runtime, and only your runtime can log it.
For the security review
The short version of what you can show:
- The agent is its own principal, with a key that's stored hashed and shown once.
- Its reach is a list of grants you can read back, and every change to that list is in the log with who made it.
- Every search records the documents it returned. Every refusal is a
denyline, even when the wire said404. - The log is append-only for the application, kept 400 days by default (
NACRE_AUDIT_RETENTION_DAYS), and exports as JSONL or CSV fromGET /v1/audit.
The audit log, its export and the retention are in the Apache-2.0 core. Forwarding to a SIEM is in the commercial build. To try it yourself, the script above runs against the quickstart on any machine with Docker, and docs/audit.md is the page to hand your reviewer.
Originally published at https://nacre.work/blog/which-documents-did-the-agent-read.
Top comments (0)