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#
| Tool | When an agent calls it |
|---|---|
provision_resource | To create a VM, database, cluster, GPU or any billed resource |
Params#
| Param | Type | Required | Meaning |
|---|---|---|---|
monthly_cost_minor | whole number | yes | Estimated monthly cost in minor units. 4000 is $40.00 a month |
resource_type | string | yes | Such as vm, database, cluster, gpu |
region | string | yes | Such 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#
| Request | Outcome | Policy id |
|---|---|---|
| Up to $100 a month | allow | cloud-small |
| Up to $5,000 a month | ask_human | cloud-needs-approval |
| A GPU up to $5,000 a month | ask_human | cloud-needs-approval |
| More than $5,000 a month, caller has a plan step | dry_run | cloud-plan-only |
| More than $5,000 a month, no plan step | block | no_matching_policy |
| More than $50,000 a month | block | cloud-hard-cap |
| A region not on the list | block | cloud-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,500000and5000000to move the lines. - Edit the region list in
cloud-regions. - Pass a plan step such as
terraform planas the guard's dry-run handler.
The policy#
This is cloud-spend.cedar as it is in the repository.
// 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) };