28.4 Least privilege for tools, data and network
- Approved by
- Panaversity ·
In everyday life. In a small family shop, a helper writes the checks for the week's suppliers. But a check is worth nothing until the owner signs it, and the bank looks at the signature, not the helper's word. The helper's key opens the storeroom, not the office. And the shop's bank account is not on the helper's phone, so a stranger who calls cannot ask the helper to send money from it. In this section, writing a check is proposing a payment, the signature is a person's approval, the bank is the connector, and every key the helper does not hold is a privilege the worker does not have.
What you will learn. You practice this in Lab 28, Tasks 3 and 4.
- What is least privilege, and which tier is it?
- Who may propose a payment?
- Why is approving not a scope?
- How does one approval pay only once?
- Which tools does the orchestrator keep?
- What data may the worker see?
- Where can data still leave?
Why it matters. Anthropic gives the reason in one line: "Apply the principle of least privilege so that a successful injection can do minimal damage".1 The layers of 28.3 make a fooled model less likely. Least privilege decides what a fooled model can reach.
At work. Two events from the overview end here. One is the 403 at 10:15. The other is the 9:20 note that no tool can carry out.
What is least privilege, and which tier is it?
Least privilege means each part gets only the access its job needs. Anthropic: "don't give Claude access to secrets it doesn't need, run tools in sandboxed environments, and scope permissions as narrowly as possible."1 The place you apply it decides the tier. A limit in the connector, such as a scope, an approval or a field it never returns, meets every call, whichever route it came by. A limit in the runtime, such as its tools, hosts or sandbox, meets only the calls that come through that runtime.
Who may propose a payment?
A person whose role carries ap:pay. Proposed: an owner or an admin. 18.7 gave the first tool that acts its own scope, ap:pay, "which no role has until someone decides who may move money". This chapter decides. ap:pay means "may propose a payment", and Brightline's map of roles to scopes becomes:
| Role | Scopes |
|---|---|
owner, admin | ap:read, ap:vendors.read, ap:pay |
member | ap:read, ap:vendors.read |
auditor | ap:read |
The connector gains two tools. schedule_payment needs ap:pay and a matching row in approvals. get_approval needs only ap:read, and only reads.
The model's call to schedule_payment carries only an invoice and an amount. The company comes from the token, and code, never the model, adds the run key. Before the hook decides, it writes the call's evidence line (28.5). The portal's approval page lists a call that has no approval yet as a proposal, but only when the run's token carries ap:pay. The proposer is the person whose token the run carries. That is how INV-8305 reaches Dave. Ana's 9:00 run proposes it, and the hook denies the call and writes its line. Then at 10:00 Dave approves it for one amount. The 9:40 script's calls propose nothing, because no hook runs on that route.
A run carries the token of the person who started it (23.9), so Ana's runs may propose a payment and Priya's may not. A call from Priya's run puts nothing on the approval page, and if it reaches the connector, the connector answers 403. If Priya's app tries 18.7's step-up for ap:pay, the sign-in server grants only her role's scopes. A role's new scopes reach each person with their next token (18.14).
Dave Kowalski is an admin, so his token carries ap:pay too. Proposed: Dave never starts a payment run. He is the one who approves, and nobody approves a payment their own run proposed.
Why is approving not a scope?
Because a scope is carried in the run's token, and a fooled model can use anything the run carries. If approving were a scope given to Dave, every run he started would carry it. A planted note could lead the model to approve and pay in one run, and no check could tell Dave's decision from the model's.
So an approval is a row, not a permission. The portal's server writes a row in approvals when a person, signed in as themselves, approves a proposal on the approval page. It writes the row only if that person is not the proposer, and only if their limit covers the amount. Each person's limit is in an approvers list in data/settings.csv (proposed). Over $5,000.00, only Dave Kowalski may approve. No tool and no token writes approvals.
At the payment, the connector checks both: the token carries ap:pay, and a row matches the token's company, the invoice and the amount. It also refuses if the person whose token makes the call is the row's approver. Words in a run can change what the model proposes. They cannot write a row.
How does one approval pay only once?
The connector makes each payment's run key from the matching row's id, and uses the approval up in the same step as the payment. A run key is the value that names one payment run, so that a second call with the same key does nothing. Code sets it, never the model, and one approval can only ever have one.
The connector also marks the row as used in the same transaction as the payment. A transaction is a group of database changes that happen together or not at all. So at 10:30, a second call for Dave's approval finds the row used, and does nothing.
Which tools does the orchestrator keep?
Only the ones its job needs, and none that reach outside. On the Claude Agent SDK its tools come in three groups:
- Built-in tools.
tools: []"turns off every built-in tool" (Chapter 22 reference). In Lab 28, Task 2, the orchestrator lists one,tools: ["Agent"], which starts its subagents, so the shell, the file tools and the web tools are gone.allowedToolswould not do this. It only approves the tools it names, and "Other tools not listed here still exist".2 The init message, a run's first message, names that toolTask. - Connector tools. The four read tools, and
schedule_payment, which only the main loop holds.vendor-lookup's only tool is stillfind_vendor. - A denied tool. The connector also lists
get_approval, which only the hook's code calls, straight to the connector (28.5). So the orchestrator writes it indisallowedToolsby its full name, the connector's prefix included. A call the model makes to it is then denied "even inbypassPermissionsmode and when a hook returnedallow".2 Whether the model still sees the tool is a separate question. Claude Code's permissions page says a deny rule that names a whole tool "removes the tool from Claude's context entirely", and a glob such as"mcp__*"works "the same as a bare tool name".3 But the Agent SDK's page promises this only "To hide a built-in tool".2 Claude Code's caching page adds that when tool search is active, "which is the default on supported models, the request's tool definitions don't change".4 So count on the deny, not on the model never seeing the tool.
With no shell, no file tool and no web tool, the 9:20 note asks for something no tool can do. That guard decides on one route: this runtime's list.
What data may the worker see?
Only the fields the job needs, cut at the connector. find_vendor returns the last four digits of an account (17.7). A field the connector never returns cannot leak by any route.
The payment's bank check needs more, because a new account can end in the same four digits. Proposed: when Dave approves, the portal's server stores a fingerprint of the vendor's full account in the row. A fingerprint here is a one-way hash: a short code computed from the account's record, from which nobody can work the number back. At the payment, the connector computes it again and refuses if the two differ. No tool ever returns the full number.
Keys follow the same rule. For an agent that runs code, Anthropic advises a proxy "that injects the key into requests. The agent can make API calls, but it never sees the credential itself." The same guide says to "Avoid mounting sensitive host directories like ~/.ssh, ~/.aws, or ~/.config", and lists .env among "Common files to exclude or sanitize before mounting".5 The orchestrator runs no code for the model, so it needs none of the guide's four ways to isolate code: "Sandbox runtime", "Containers", "gVisor" and "Virtual machines".5
Where can data still leave?
Through any host you allowed, and through the worker's own reply. A host list (23.7) closes every host not on it, and none of the hosts on it. Anthropic warns that "limiting the environment's hosts does not stop the agent from using a credential on a host you allowed."6 The Agent SDK's guide says the same of its proxy: "Within your proxy's allowlist, the agent can send data to any allowed domain. Allow only the domains the agent needs."5
No network rule covers the answer itself: "An agent can still put data it is allowed to read into its own reply or tool output."6 So the last guard against data leakage is the first one: data the worker never reads, it cannot leak. In Lab 28, Task 4, a test checks that the reply to the 9:20 note holds no full account number, and that the run made no outside request.
The operating rule: give each runtime only the tools its job needs, give each role the fewest scopes, and make each approval a row that no token can write. Keep full account numbers and keys where no tool returns them.
Do this now. Ask your coding agent to list who can reach what. Copy this line:
List every tool the model can call in this project's orchestrator, and the scope the connector asks for each. Then list every role and the scopes it maps to. Mark each tool the job does not need, each role that holds a scope it never uses, and any way a tool could send data to a host other than the connector's. Change no file.
Check yourself
Question 1 / 8
0 answered
Under this chapter's proposal, what does the ap:pay scope let a run do?
Sources
- Owner
- Panaversity