RiskboundDocs

Policy library

Spending on cloud resources

Agents that create infrastructure can run up a bill fast. This template looks at the monthly cost of what is about to be created.

What it guards#

ToolWhen an agent calls it
provision_resourceTo create a VM, database, cluster, GPU or any billed resource

Params#

ParamTypeRequiredMeaning
monthly_cost_minorwhole numberyesEstimated monthly cost in minor units. 4000 is $40.00 a month
resource_typestringyesSuch as vm, database, cluster, gpu
regionstringyesSuch as us-east-1

The param is monthly_cost_minor, not amount_minor, on purpose. It is a rate, not money spent now, so it does not count toward the agent's daily spend cap.

Outcomes#

RequestOutcomePolicy id
Up to $100 a monthallowcloud-small
Up to $5,000 a monthask_humancloud-needs-approval
A GPU up to $5,000 a monthask_humancloud-needs-approval
More than $5,000 a month, caller has a plan stepdry_runcloud-plan-only
More than $5,000 a month, no plan stepblockno_matching_policy
More than $50,000 a monthblockcloud-hard-cap
A region not on the listblockcloud-regions

cloud-gpu-needs-a-person is a forbid on Action::"act" only. It stops a GPU from running on its own but leaves the way to a person open.

Tune it#

  • Change 10000, 500000 and 5000000 to move the lines.
  • Edit the region list in cloud-regions.
  • Pass a plan step such as terraform plan as the guard's dry-run handler.

The policy#

This is cloud-spend.cedar as it is in the repository.

cedar
// Spending on cloud resources.
//
// Tool: provision_resource
// Params: monthly_cost_minor (whole number, minor units),
//         resource_type (string), region (string)
//
//   up to $100 a month                 allow
//   up to $5,000 a month               ask a human
//   any GPU                            ask a human, whatever the cost
//   more than $5,000 a month           dry run (plan only)
//   more than $50,000 a month          block
//   a region not on the list           block

@id("cloud-small")
permit (principal, action == Action::"act", resource == Tool::"provision_resource")
when { context.monthly_cost_minor <= 10000 };

@id("cloud-needs-approval")
permit (
  principal,
  action == Action::"act_with_approval",
  resource == Tool::"provision_resource"
)
when { context.monthly_cost_minor <= 500000 };

@id("cloud-plan-only")
permit (principal, action == Action::"dry_run", resource == Tool::"provision_resource");

// A forbid on one action only. A GPU never runs on its own, but it can
// still go to a person.
@id("cloud-gpu-needs-a-person")
forbid (principal, action == Action::"act", resource == Tool::"provision_resource")
when { context.resource_type == "gpu" };

@id("cloud-hard-cap")
forbid (principal, action, resource == Tool::"provision_resource")
when { context.monthly_cost_minor > 5000000 };

@id("cloud-regions")
forbid (principal, action, resource == Tool::"provision_resource")
unless { ["us-east-1", "eu-west-1"].contains(context.region) };