Fleet budget store
Sum routing budget spend across managed devices with the optional budget store, so a user with two devices has one limit.
Without a store, each managed device counts its own spend, so a user with two devices has two limits. The optional budget store sums spend across devices. Each device gets its own credential, which names only that device's users and the budgets they are in.
Before you start
- Routing budgets set in the device bundle.
- A host for the store, with a TLS certificate and its own service account.
- An administrator workstation that keeps the tenant secret. No device and no store holds it.
- MDM to install a protected credential on each device.
Set it up
Create the tenant secret
On the administrator workstation, once:
openssl rand -base64 32 > tenant-secret; chmod 600 tenant-secretRun the store
Copy the bundle's routing.admin.budgets into the store's config, so it knows the group and connector limits.
config_version: 9
routing:
admin:
budgets: [] # the same budgets as the device bundle
budget_store:
server:
listen: 0.0.0.0:8443
tls_cert_file: /etc/defenseclaw-budget-store/cert.pem
tls_key_file: /etc/defenseclaw-budget-store/key.pem
db_path: /var/lib/defenseclaw-budget-store/store.db
device_daily_cap_usd: 500 # the most one device may add per UTC daydefenseclaw-gateway budget-store serve --config /etc/defenseclaw-budget-store/config.yamlThe TLS key must be owned by the account that runs the store and readable only by it. It may be a link, for example into /etc/letsencrypt/live, when the file it points to meets that rule.
Issue a credential for each device
Name the device's users (UPN or SID) and the groups of theirs that budgets name:
defenseclaw-gateway budget-store device issue --config bundle-config.yaml --secret-file ./tenant-secret \
--user alice@example.com --group "EXAMPLE\\eng" \
--credential-out laptop-17.cred --record-out laptop-17.recordOn Windows, run device issue in a folder only Administrators and SYSTEM can read; it refuses to leave the files anywhere else.
Name each person the same way on every device (the SID when you have it). A UPN on one device and a SID on another count as two people.
Install the credential and register the device
Install laptop-17.cred on the device as the protected credential routing-budget-store-device with your MDM. Copy laptop-17.record to the store host and register it:
defenseclaw-gateway budget-store device add --config /etc/defenseclaw-budget-store/config.yaml --record laptop-17.recordDelete both files afterwards.
Point the devices at the store
In the device bundle:
routing:
admin:
budget_store:
url: https://budgets.example.internal:8443
ca_file: /etc/defenseclaw/budget-store-ca.pem # recommended with a private CACheck it worked
On a device, defenseclaw routing budgets list says whether each budget reads the fleet spend or this device only. defenseclaw doctor reports a store that is down or refusing.
Manage devices
defenseclaw-gateway budget-store device list --config /etc/defenseclaw-budget-store/config.yaml
defenseclaw-gateway budget-store device revoke --config /etc/defenseclaw-budget-store/config.yaml d3f1...
defenseclaw-gateway budget-store report --config /etc/defenseclaw-budget-store/config.yaml --since 2026-11-01| Task | How |
|---|---|
A device's users or groups change, or you add a per-user (subject: "*") budget | Issue the device again, add it, and revoke the old credential. Until then that budget counts on each device only. |
| Revoke a device | device revoke. It is refused within 10 seconds, and its spend so far stays counted. |
| Remove forged spend | device revoke --drop-spend-from YYYY-MM-DD also deletes its spend from that day on. |
| Bring a revoked device back | device add --reactivate. Without it, device add refuses a revoked device. |
| Per-device spend | report --by-device. |
| Give one device its own cap | device issue --cap-usd N. |
| Remove a budget | Remove it from the bundle first. Remove it from the store config only after the new bundle has reached every device. |
What the store sees
| Sent | Not sent |
|---|---|
| Device id, budget id, a keyed hash for each user, group and named user, connector names, UTC days, dollar amounts | User, group, device or host names, prompts, models |
Budget ids and connector names reach the store as they are, so do not put a person's name in a budget id. The store also sees each device's address and when it sends.
What a device may do
- Add spend only for its own users and the budgets its credential names. Anything else is refused.
- Spend only grows: the store ignores a lower value, and only today's and yesterday's spend (UTC) can grow.
- Read the fleet spend of its own users. For a group or connector budget it learns only whether the limit is reached, never the total.
- Group and connector totals and every device's spend are read on the store host only (
report). The store has no network API for them. - Add at most
device_daily_cap_usdper UTC day over all its keys (or its own--cap-usd).device listshows the last day a device reached it.
Limits
- Cap at midnight. The cap counts per UTC day of the spend. Yesterday's spend can still grow for a day, so just after midnight a device can add up to two caps within a few hours.
- Per-device limits. One device may run at most 16 gateway processes at once, store spend from at most 64 gateway processes a day, and use at most 64 connector names a day beyond its credential's keys.
- Offline devices. Spend made while a device cannot reach the store for more than a day counts on that device only; it never reaches the fleet total.
- Store down or refusing. Budgets keep counting this device only.
defenseclaw routing budgets listanddoctorsay so, and the fleet total comes back when the store answers. - Missing budgets. The store must know every group and connector budget. When its config lacks one, devices count their own spend and
defenseclaw routing budgets listnames the missing budget. - Unnamed users. A user the device's credential does not name, or with no verified SID or UPN, is counted on that device only.
- Turning it on mid-period. Per-user, group and named-user budgets start again on each device.
- After a gateway restart. A user's spend on other devices is read within seconds; calls made in those seconds see only this device's spend.
- Shared NAT. Devices behind one NAT address share a high request limit (20 times
rate_limit_per_minute). A busy host on that address can push them to per-device counting for a minute.
Security
- Every request, and every answer to an authenticated request, is signed with the device's key, over HTTPS. The device refuses plain HTTP, redirects, proxies from the environment and spend answers the store did not sign (for example rewritten by a TLS-inspecting proxy). Any other answer only makes it count on this device.
- Set
ca_fileto your private CA. Without it the device trusts the system roots, including any TLS-inspection root on the device. - A local administrator of a device can read and add spend for that device's users and its groups, up to its daily cap. They cannot reach other users. Revoke the device to stop it.
- The store's database holds every device's secret. Protect it and its backups like the TLS key: anyone with a copy can act as any device within that device's keys.
- If the tenant secret leaks, the hashes of names can be computed. Make a new secret and issue every device again; spend counted under the old secret no longer adds up.
Each managed device's gateway connects to the store URL every sync_interval (30 seconds by default) and when a new user starts an agent. Allow it in your firewall, and expose the store only to the devices' network.
Undo
Remove routing.admin.budget_store from the device bundle. Budgets then count each device's own spend again.
Next
- Routing rules and budgets
- Tokenomics: the budget store metrics
Routing rules and budgets
Limit which models each group may use and cap model spend per user, group or connector, on one device or across the fleet with the opt-in budget store.
Scanning and admission
DefenseClaw scans skills, MCP servers and plugins when they appear, then allows, warns about or blocks them by severity.