iac.htora.dev · security templates

Home/Templates/Data that cannot leave your organisation

Data that cannot leave your organisation

Perimeter policies so stolen credentials cannot copy data to an attacker's own account or project.

Terraform

Why bother

An attacker with valid credentials does not need to break anything to take data. They copy it to a bucket they own. A data perimeter checks where requests come from and where data goes, and refuses anything that crosses the organisation's edge, even with valid credentials.

How you know it worked

With valid credentials, try to copy an object to a bucket in another organisation. It is refused.

How it works

1A request with valid credentialspossibly stolen2The perimeter checks both endswhose identity, whose resource, which network3Crossing the edge is refusedwhatever the credentials allow4The attempt is loggedfor the responders
Step by step, from the thing that happens to the result you want.

Set it up

Pick your platform, then open the level you want. Each level is complete on its own. Read the comments in the files as you go. Anything with a real consequence is explained on the line where it happens.

Terraform. Service and resource control policies keyed on the organisation ID

What you need first

  • AWS Organizations with all features on, and Terraform running in the management account.
  • Resource control policies switched on for the organisation: aws organizations enable-policy-type --root-id <root> --policy-type RESOURCE_CONTROL_POLICY.
  • The organisation ID, and an OU or account to attach to. Start with a test OU.
  • For Standard, the account IDs of any vendors that must use or receive your data.

What it creates

  • A resource control policy: only principals in the organisation can use its S3, KMS, SQS, and Secrets Manager resources
  • A service control policy: identities in the organisation cannot write to S3 buckets outside it
  • Named outside accounts allowed through, encrypted connections required, and an exemption tag nobody in a member account can set (Standard)

The code

Quick startReadyone file, 101 lines
One file. Both perimeters for the organisation, attached to one OU or account.
Change these first
  • org_id = "o-xxxxxxxxxx" main.tf, line 22
  • target_id = "ou-xxxx-xxxxxxxx" main.tf, line 23
Run it
  1. aws sts get-caller-identity
    Shows the account and role you are signed in as. Check it before every apply.
  2. terraform init
    Downloads the provider. Run it once per folder.
  3. terraform plan
    Shows what will be created. Changes nothing. Read it.
  4. terraform apply
    Shows the plan again and waits for you to type yes.
  5. terraform destroy
    When you have finished. If it refuses, How to undo it below explains why.
Download main.tf
Checks

Formatting passedValid passedLint passed

Security scan: 23 checks passed, and none flagged.

Last run 2026-10-02 with OpenTofu v1.12.6 against hashicorp/aws 6.66.0.

outcomes/data-perimeter/aws/t0
main.tf
Open main.tf as plain text
StandardReadyfour files, 207 lines
Adds named outside accounts, encrypted transport required, S3 restores covered, and an exemption tag nobody in a member account can set.
Change these first
  • org_id. The organisation ID, o-xxxxxxxxxx.
  • target_ids. OU or account IDs to attach both policies to. Start with a test OU.
Run it
  1. aws sts get-caller-identity
    Shows the account and role you are signed in as. Check it before every apply.
  2. # terraform.tfvars
    org_id = ""
    target_ids = ""
    Create this file beside the others and fill in your values. Terraform reads it on its own.
  3. terraform init
    Downloads the provider. Run it once per folder.
  4. terraform plan
    Shows what will be created. Changes nothing. Read it.
  5. terraform apply
    Shows the plan again and waits for you to type yes.
  6. terraform output verify
    Prints the commands that prove it worked.
Download all four files as a zip
Checks

Formatting passedValid passedLint passed

Security scan: 23 checks passed, and none flagged.

Last run 2026-10-02 with OpenTofu v1.12.6 against hashicorp/aws 6.66.0.

outcomes/data-perimeter/aws/t1
main.tf
Open main.tf as plain text
outputs.tf
Open outputs.tf as plain text
variables.tf
Open variables.tf as plain text
versions.tf
Open versions.tf as plain text
HardenedReadysix files, 204 lines
Standard as a module. Plan rules refuse either policy deleted, the organisation or TLS deny dropped from the resource policy, the resource-organisation deny or exemption-tag protection dropped from the service control policy. A daily plan reports drift, and the scan fails on any unexplained finding.
Change these first
  • org_id. The organisation ID, o-xxxxxxxxxx.
  • target_ids. OU or account IDs to attach both policies to. Start with a test OU.
Run it
  1. aws sts get-caller-identity
    Shows the account and role you are signed in as. Check it before every apply.
  2. # terraform.tfvars
    org_id = ""
    target_ids = ""
    Create this file beside the others and fill in your values. Terraform reads it on its own.
  3. terraform init
    Downloads the provider. Run it once per folder.
  4. terraform plan
    Shows what will be created. Changes nothing. Read it.
  5. terraform apply
    Shows the plan again and waits for you to type yes.
  6. terraform output verify
    Prints the commands that prove it worked.
Download all six files as a zip
Checks

Formatting passedValid passedLint passed

Security scan: 23 checks passed, and none flagged.

Last run 2026-10-02 with OpenTofu v1.12.6 against hashicorp/aws 6.66.0.

outcomes/data-perimeter/aws/t2
.checkov.yml
Open .checkov.yml as plain text
guard.yml
Open guard.yml as plain text
main.tf
Open main.tf as plain text
outputs.tf
Open outputs.tf as plain text
variables.tf
Open variables.tf as plain text
versions.tf
Open versions.tf as plain text

How to check it worked

From a member account, run aws s3 cp to a bucket in another organisation. It fails with an explicit deny in a service control policy.

What catches people

Resource control policies stay off until switched on for the organisation. Until then, apply fails when attaching the first one.

Every vendor that reads your buckets or keys is refused until its account is named. List them before attaching the policy anywhere that matters.

AWS services acting under their own service principal pass the identity perimeter. Services that act with your role's credentials are checked like you.

Neither kind of policy applies to the management account, or to resources in it.

How to undo it

terraform destroy detaches and deletes both policies, and data can cross the edge again at once.

What it costs

Nothing. Organisation policies are free.

Good to know

  • Stolen credentials keep their permissions. The perimeter decides where data may go whatever those permissions allow, so a stolen key still cannot copy data to the attacker's own account.
  • AWS services acting for you, such as CloudTrail writing to its bucket, pass the identity perimeter. Third parties are refused until you name their accounts.
  • Only AWS and Google Cloud have a tenancy-wide rule that keys on whose identity and whose resource. Azure draws a network boundary around the resources that contain the data, and Oracle Cloud refuses reads from outside named networks with a deny policy. Each page says what its perimeter stops and what it does not.

Registry 0.23.0. Built 2026-11-17.

Made by Habibullah Tora. Source on GitHub. Code under the MIT licence, writing under CC BY 4.0.