Security review
The finding: SEC03-BP01
The review rated it Critical. Its evidence: the balance check lived only in core/ledger.ts, the app connected as admin, and the app's AWS identity was an IAM user with a long-lived key that could call 6 of 6 destructive actions on the clusters.
So a write that skipped the check, from a script, a hotfix or a new route, would commit. Measured on Aurora DSQL, ten such writers took a $3.00 budget to -$7.00 in 20 runs out of 20. Concurrency control put the writes in order. Nothing decided whether they were affordable.
SEC03-BP01
Each of your workload components or services runs under a distinct identity scoped to the permissions its function requires.
What changed
- 1
The database enforces the budget
Every balance carries
CHECK (balance_micro >= 0), and accounts also carry a cap check, so a bug can't mint budget either. Each was added asNOT VALIDand validated in the background, with no downtime. - 2
A least-privilege database role
The app connects as
stub_app. It can add entries and move balances, but not change or delete an entry, create an account or touch the schema. - 3
No stored AWS keys
The app assumes an IAM role through Vercel OIDC, gets one-hour credentials, and may only call dsql:DbConnect.
- 4
A refusal becomes a record
A 23514 that reaches the app is stored as a denial with reason
db_refused, so it shows in the audit trail. - 5
CI attacks a real database
Every push starts Postgres 17, connects as stub_app, sends the six statements from the proof page and runs the ten-writer race. It fails if any statement is accepted.
The review
- Security scoreBefore1 of 5After3 of 5
- Reliability scoreBefore2 of 5After3 of 5
- Critical findingsBefore3After0
- An agent's own key approves its over-threshold spendBeforeacceptedAfterignored, only the operator approves
The budget
- Ten writers skip the app's check and race a $3.00 budget on Aurora DSQLBefore10 committed, -$7.00 in 20 of 20 runsAfter3 committed, 7 refused 23514, $0.00 in 20 of 20 runs
- Balance below zero, as the app's roleBeforeacceptedAfterrefused, 23514
- Balance below zero, as adminBeforeacceptedAfterrefused, 23514
- Raise a budget above its cap, as the app's roleBeforeacceptedAfterrefused, 23514
- CHECK constraints on balance tablesBefore0After3, all validated
Access
- App's database roleBeforeadmin, owns every tableAfterstub_app, owns nothing
- Rewrite or delete a ledger entry, as the app's roleBeforeacceptedAfterrefused, 42501
- Create or drop a table, as the app's roleBeforeallowed, as ownerAfterrefused, 42501
- Destructive DSQL actions the app's AWS principal may callBefore6 of 6After0 of 6
- App's credentialsBeforelong-lived access keyAfterVercel OIDC, 1-hour sessions
- Unlisted principal connects as adminBefore2 of 2 clustersAfter0 of 2
- Admin and export routes, without a credentialBefore200 on 4 of 4After401 on 4 of 4
Recovery
- Deletion protectionBefore0 of 2 clustersAfter2 of 2
- Backup plans covering the ledgerBefore0After2, daily at 05:00 UTC, 35-day retention
- Restores testedBefore0After1, verified, 2 min 9 s
- Spend while the primary Region is unreachableBeforefails after 3.0 sAftercommitted on us-east-2 in 7.59 s
- Production under an AWS FIS fault on the primary RegionBeforenot testedAfterserving from us-east-2 in 17.3 s
Detection and audit
- CloudTrail trailsBefore0After1, multi-Region
- GuardDuty detectorsBefore0After2
- CloudWatch alarmsBefore0After4
- SQL audit log on the ledger's clustersBeforeoffAfterevery DDL, role change and write, both Regions
Delivery
- Required status checks on mainBeforenoneAfter4
- Least-privilege guardrail testBefore0 of 3 passAfter3 of 3 pass
- Guardrail test over the templatesBeforenoneAfter6 tests
Operations
Infrastructure as code
Clusters, backups, the audit trail, detection and the failure drill are CloudFormation stacks with termination protection, deployed from main.
infra/Incident response
One playbook per alarm and rule, the freeze criteria, and recovery with the measured restore and failover times.
incident-response.mdData classification
Every table, column, export and log classed Public, Internal or Confidential, with retention and where it flows.
data-classification.md