Demo library › Chapter 6
Change the perimeter as data, manage policy as code
Approve a new bucket by editing a JSON document, and watch exactly one exfiltration row change. Then the Rego module behind every policy, the unit tests, and the Terraform that deploys it all.
The problem
Guardrails that need a policy engineer for every new bucket do not survive contact with a real organisation. The rule - "data only goes to company-owned resources" - changes rarely; the list of what the company owns changes every week.
Lands with: security engineering and platform teams who will own the policies
Before you start
- Rego metadata ↗ open in the dashboard.
- The exfiltration test open, with the last run through CWS showing five of five blocked.
Run it
The list is data
| Do | Say |
|---|---|
| Open Rego metadata → data-perimeter. | This is the data perimeter: a JSON list of the resources the company owns. The policy reads it as data.metadata.data_perimeter. |
Add "exfil-drop-bucket" to approved_resources and save. | Suppose that bucket really were ours - a new partner bucket, say. No policy edit, no review of Rego: one line of data. |
| Wait 30 seconds and run the test through CWS. | Exactly one row changed. S3 to that bucket is now allowed; the other four are still blocked. |
Remove "exfil-drop-bucket" again and save. | And it's gone. Who may add to this list is a question for your change process, not for the policy author. |
The code behind it
| Do | Say |
|---|---|
| Open Rego modules ↗ → cws-lab-helpers. | Shared Rego. It knows the AWS wire protocols - JSON, query-encoded, S3's REST - so every policy can ask simple questions: what operation is this, where does it write, does it mention AdministratorAccess. |
| Open Policies in the guide. | Every policy in this lab, with its filter, what it blocks and its source. |
Whybackground, if you are asked
The helpers prefer the proxy's own classification - input.application.service and operation, from the Action Mapper - and fall back to reading the request when there is none, so a policy keeps working whichever way a request arrives.
Policy as code
| Do | Say |
|---|---|
| Show the Terraform resources from the Policies page. | Everything you've seen - policies, policy sets, workloads, the metadata, the deployment - is created by the Cloudflare Terraform provider in this lab. Code review, history and rollback for guardrails, the way you'd want them. |
| Show the test run on the same page. | And unit tests: every policy is tested with OPA against requests that should pass and requests that should fail - before it's deployed. |
What the audience should see
- One exfiltration row turning red after a one-line metadata change, and green again after it is removed.
- The shared Rego module, the policies and their tests.
Where the evidence is
Proxy decisions: the allowed PutObject to exfil-drop-bucket while it was approved, and the denials either side of it.
Known limitations
Metadata edits made in the dashboard are reverted by the next terraform apply, as with any Terraform-managed resource.
Part of: Guardrails for every pipeline · The data perimeter