Policy library
Deleting or bulk-changing records
Writes that touch many rows at once, and deletes. One wrong WHERE clause
from an agent can wipe a table.
What it guards#
| Tool | When an agent calls it |
|---|---|
bulk_update_records | To change a field on many records |
delete_records | To delete records |
Params#
Both tools:
| Param | Type | Required | Meaning |
|---|---|---|---|
record_count | whole number | yes | How many records the change touches. Count them first, with the same filter |
table | string | yes | The table or object type |
Outcomes#
| Request | Outcome | Policy id |
|---|---|---|
| Update up to 100 records | allow | bulk-update-small |
| Update up to 10,000 | ask_human | bulk-update-needs-approval |
| Update more than 10,000, caller has a dry run | dry_run | bulk-update-dry-run |
| Update more than 100,000 | block | bulk-update-hard-cap |
| Delete up to 100 | ask_human | delete-needs-approval |
| Delete more than 100, caller has a dry run | dry_run | delete-dry-run |
| Delete more than 10,000 | block | delete-hard-cap |
Either tool on audit_log, ledger or invoices | block | records-protected-tables |
Without a dry-run handler, requests that would get dry_run are blocked
with no_matching_policy.
Tune it#
- Deletes never run on their own. To let small deletes run, add an
actpermit likebulk-update-smallfordelete_records. - Edit the list in
records-protected-tablesto name your own tables. - The dry-run handler should run the same filter as a count or a
SELECT ... LIMIT, and show what would change.
The policy#
This is records.cedar as it is in the repository.
// Deleting records, and changing many records at once.
//
// Tool: bulk_update_records
// Params: record_count (whole number), table (string)
//
// up to 100 records allow
// up to 10,000 records ask a human
// more than 10,000 dry run (show what would change)
// more than 100,000 block
//
// Tool: delete_records
// Params: record_count (whole number), table (string)
//
// up to 100 records ask a human (never runs on its own)
// more than 100 dry run
// more than 10,000 block
//
// Both tools: a protected table block
@id("bulk-update-small")
permit (principal, action == Action::"act", resource == Tool::"bulk_update_records")
when { context.record_count <= 100 };
@id("bulk-update-needs-approval")
permit (
principal,
action == Action::"act_with_approval",
resource == Tool::"bulk_update_records"
)
when { context.record_count <= 10000 };
@id("bulk-update-dry-run")
permit (principal, action == Action::"dry_run", resource == Tool::"bulk_update_records");
@id("bulk-update-hard-cap")
forbid (principal, action, resource == Tool::"bulk_update_records")
when { context.record_count > 100000 };
@id("delete-needs-approval")
permit (principal, action == Action::"act_with_approval", resource == Tool::"delete_records")
when { context.record_count <= 100 };
@id("delete-dry-run")
permit (principal, action == Action::"dry_run", resource == Tool::"delete_records");
@id("delete-hard-cap")
forbid (principal, action, resource == Tool::"delete_records")
when { context.record_count > 10000 };
// Tables that hold history or money. Nothing changes them through an agent.
@id("records-protected-tables")
forbid (principal, action, resource)
when {
[Tool::"bulk_update_records", Tool::"delete_records"].contains(resource) &&
["audit_log", "ledger", "invoices"].contains(context.table)
};