RiskboundDocs

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#

ToolWhen an agent calls it
bulk_update_recordsTo change a field on many records
delete_recordsTo delete records

Params#

Both tools:

ParamTypeRequiredMeaning
record_countwhole numberyesHow many records the change touches. Count them first, with the same filter
tablestringyesThe table or object type

Outcomes#

RequestOutcomePolicy id
Update up to 100 recordsallowbulk-update-small
Update up to 10,000ask_humanbulk-update-needs-approval
Update more than 10,000, caller has a dry rundry_runbulk-update-dry-run
Update more than 100,000blockbulk-update-hard-cap
Delete up to 100ask_humandelete-needs-approval
Delete more than 100, caller has a dry rundry_rundelete-dry-run
Delete more than 10,000blockdelete-hard-cap
Either tool on audit_log, ledger or invoicesblockrecords-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 act permit like bulk-update-small for delete_records.
  • Edit the list in records-protected-tables to 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.

cedar
// 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)
};