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.
With valid credentials, try to copy an object to a bucket in another organisation. It is refused.
How it works
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 startReady
org_id = "o-xxxxxxxxxx"main.tf, line 22target_id = "ou-xxxx-xxxxxxxx"main.tf, line 23
aws sts get-caller-identity
Shows the account and role you are signed in as. Check it before every apply.terraform init
Downloads the provider. Run it once per folder.terraform plan
Shows what will be created. Changes nothing. Read it.terraform apply
Shows the plan again and waits for you to type yes.terraform destroy
When you have finished. If it refuses, How to undo it below explains why.
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.
Open main.tf as plain text
StandardReady
org_id. The organisation ID, o-xxxxxxxxxx.target_ids. OU or account IDs to attach both policies to. Start with a test OU.
aws sts get-caller-identity
Shows the account and role you are signed in as. Check it before every apply.# terraform.tfvars org_id = "" target_ids = ""
Create this file beside the others and fill in your values. Terraform reads it on its own.terraform init
Downloads the provider. Run it once per folder.terraform plan
Shows what will be created. Changes nothing. Read it.terraform apply
Shows the plan again and waits for you to type yes.terraform output verify
Prints the commands that prove it worked.
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.
Open main.tf as plain text
Open outputs.tf as plain text
Open variables.tf as plain text
Open versions.tf as plain text
HardenedReady
org_id. The organisation ID, o-xxxxxxxxxx.target_ids. OU or account IDs to attach both policies to. Start with a test OU.
aws sts get-caller-identity
Shows the account and role you are signed in as. Check it before every apply.# terraform.tfvars org_id = "" target_ids = ""
Create this file beside the others and fill in your values. Terraform reads it on its own.terraform init
Downloads the provider. Run it once per folder.terraform plan
Shows what will be created. Changes nothing. Read it.terraform apply
Shows the plan again and waits for you to type yes.terraform output verify
Prints the commands that prove it worked.
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.
Open .checkov.yml as plain text
Open guard.yml as plain text
Open main.tf as plain text
Open outputs.tf as plain text
Open variables.tf as plain text
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.
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.
Terraform. A network security perimeter around the resources, with Azure Policy behind it
What you need first
- A resource group for the perimeter, and Network Contributor on it.
- On each resource that joins, the right to join it to a perimeter (Contributor carries it), and on each allowed subscription, the right to name it in a perimeter rule.
- The resources to protect: storage accounts, key vaults, and the other services that support perimeters. Each must be reachable afterwards through a private endpoint or from an allowed network, so plan where your applications call from.
- For the Standard policies, Resource Policy Contributor on the management group, or on the template's own subscription.
What it creates
- A network security perimeter and a profile, with one inbound rule for your networks and no outbound rule
- An association of each protected resource, enforced, so the perimeter's rules override the resource's own firewall and Azure's trusted-service exceptions
- The access log into your workspace, with an alert on every refusal (Standard)
- Native activity log alerts, which Azure evaluates without the workspace, on a diagnostic setting deleted or written, a log search rule disabled by Azure, and a lock deleted (Standard, with alerts)
- A native alert on the refusal rule's read access removed, with the workspace in this subscription, and a cannot-delete lock on the action group and each alert (Standard, with alerts)
- A Learning mode, which Azure now calls Transition, where each resource's own firewall decides whatever the perimeter does not, and the alert also fires on what Enforced would refuse (Standard)
- Azure Policy on a management group or the template's own subscription (Standard). It refuses cross-tenant replication, shared keys, public network access, public blobs, copies from outside the tenant, and key vaults without a firewall.
See the six alerts this creates
The code
Quick startReady
subscription_id = "00000000-0000-0000-0000-000000000000"main.tf, line 25resource_group_name = "rg-data"main.tf, line 26storage_account_name = "contosodata"main.tf, line 27storage_resource_group = "rg-data"main.tf, line 28allowed_ip_ranges = ["203.0.113.0/24"]main.tf, line 29
az login
Signs the command line tool in. Terraform uses the same sign-in.export ARM_SUBSCRIPTION_ID=$(az account show --query id -o tsv)
Tells the provider which subscription. It stopped guessing in version 4.terraform init
Downloads the provider. Run it once per folder.terraform plan
Shows what will be created. Changes nothing. Read it.terraform apply
Shows the plan again and waits for you to type yes.terraform output verify
Prints the commands that prove it worked.terraform destroy
When you have finished. If it refuses, How to undo it below explains why.
Formatting passedValid not runLint passed
Security scan: zero checks passed, and none flagged.
Last run 2026-11-09 with OpenTofu v1.12.6.
Open main.tf as plain text
StandardReady
subscription_id. Subscription that contains the perimeter, as a GUID. Resources it protects may be in any subscription of the tenant.resource_group_name. Resource group for the perimeter and its alerts.protected_resource_ids. Resource IDs of the storage accounts, key vaults, and other perimeter-aware resources to put inside. Each one then answers only the networks and subscriptions named below.
az login
Signs the command line tool in. Terraform uses the same sign-in.export ARM_SUBSCRIPTION_ID=$(az account show --query id -o tsv)
Tells the provider which subscription. It stopped guessing in version 4.# terraform.tfvars subscription_id = "" resource_group_name = "" protected_resource_ids = ""
Create this file beside the others and fill in your values. Terraform reads it on its own.terraform init
Downloads the provider. Run it once per folder.terraform plan
Shows what will be created. Changes nothing. Read it.terraform apply
Shows the plan again and waits for you to type yes.terraform output verify
Prints the commands that prove it worked.
Formatting passedValid not runLint passed
Security scan: zero checks passed, and none flagged.
Last run 2026-11-09 with OpenTofu v1.12.6.
Open main.tf as plain text
Open outputs.tf as plain text
Open variables.tf as plain text
Open versions.tf as plain text
HardenedReady
subscription_id. Subscription that contains the perimeter, as a GUID. Resources it protects may be in any subscription of the tenant.resource_group_name. Resource group for the perimeter and its alerts.protected_resource_ids. Resource IDs of the storage accounts, key vaults, and other perimeter-aware resources to put inside. Each one then answers only the networks and subscriptions named below.
az login
Signs the command line tool in. Terraform uses the same sign-in.export ARM_SUBSCRIPTION_ID=$(az account show --query id -o tsv)
Tells the provider which subscription. It stopped guessing in version 4.# terraform.tfvars subscription_id = "" resource_group_name = "" protected_resource_ids = ""
Create this file beside the others and fill in your values. Terraform reads it on its own.terraform init
Downloads the provider. Run it once per folder.terraform plan
Shows what will be created. Changes nothing. Read it.terraform apply
Shows the plan again and waits for you to type yes.terraform output verify
Prints the commands that prove it worked.
Formatting passedValid not runLint passed
Security scan: zero checks passed, and none flagged.
Last run 2026-11-09 with OpenTofu v1.12.6.
Open .checkov.yml as plain text
Open guard.yml as plain text
Open main.tf as plain text
Open outputs.tf as plain text
Open variables.tf as plain text
Open versions.tf as plain text
How to check it worked
From an address outside the allowed ranges, az storage blob list against a protected account fails with an authorization failure. From an allowed address it lists the blobs.
Azure has no tenant-wide rule that keys on whose identity and whose resource, the way AWS and Google Cloud do. The perimeter stops requests from outside your networks, and with no outbound rule a protected resource sends nothing to a name outside. It does not stop a workload inside downloading data and sending it out over a path you allow; that is a question for the network's egress rules.
Enforced means it. Private endpoints keep working, and so does traffic from the subscriptions and networks named. Everything else is refused: Azure services that relied on the trusted-service exception, Azure Backup of the account, and NFS, SMB, and SFTP.
An account with object replication or a static website cannot join a perimeter, and apply fails on that association. Turn them off first, or leave that account out.
A protected resource's own diagnostic logs must go to a destination inside the same perimeter. Add the workspace that receives them to protected_resource_ids, or those logs may stop.
Callers from an allowed subscription must sign in with Microsoft Entra ID. A SAS from those subscriptions is refused.
A perimeter refuses you too, and anything else that reads the protected resources' data from outside the allowed networks, such as another Terraform stack. Work from an allowed network, or add your own range before you apply.
The copy-scope setting on a storage account protects the account as a destination: it refuses copies whose source is outside the tenant. The perimeter, and the shared-key and public-access policies, carry the weight of keeping copies from going out.
A policy definition can only be assigned at or below the scope it is made in. Name a management group to cover every subscription beneath it; without one, the policies cover the template's own subscription only.
An account under the policies that does not already comply has its next update refused, along with the change that was meant. Read the compliance report in a test scope first.
Every alert, the native ones included, emails through one action group. Locks stop the action group and the alerts being deleted, but whoever can edit the group can still disable it or change its addresses.
The locks block Terraform too. A change that replaces or removes an alert or the action group fails while its lock is on. Remove that lock with terraform destroy -target, then apply, and the lock returns. Its removal fires the lock alert.
The refusal rule reads the workspace through a role assignment on it. With the workspace in another subscription, that assignment's removal is recorded there, and nothing here reports it. Hardened's daily drift plan is what notices.
The diagnostic-setting-written alert fires on every diagnostic setting created or changed in the subscription, policy remediation included, because a rewrite can drop a category or send logs elsewhere without a delete.
The access log can take up to 90 minutes to start after it is made, so test the refusal alert after that. Azure disables a rule whose query fails for a week, and the rule-disabled alert reports it without the workspace.
How to undo it
Remove the alert locks first with terraform destroy -target=azurerm_management_lock.alerts, or module.standard.azurerm_management_lock.alerts in Hardened. Then terraform destroy removes the associations, the perimeter, and the policy assignments. The resources answer from anywhere their own firewall allows again, at once.
What it costs
Nothing for the perimeter or the policies, by Microsoft's answer on its Q&A site. The access log is billed by the workspace's ingestion, and refusals are small.
Terraform. VPC Service Controls perimeter around sensitive projects
What you need first
- An organisation, and the Access Context Manager Admin role on it.
- For the quick start, one project to protect. For Standard, the numbers of every project inside, and the organisation's access policy.
- For Standard, your office's public address ranges, and a security project for the violations log and alert.
What it creates
- A perimeter in its own access policy, scoped to one project, protecting Cloud Storage and BigQuery
- An ingress rule that lets the named operator in, and no egress rule, so data cannot be copied out
- A perimeter around several projects and eight services, in dry run until you switch it off (Standard)
- An office network access level, admin identities, and named projects allowed to receive data (Standard)
- Every violation in the organisation, dry run or enforced, gathered in one bucket with an alert (Standard)
See the one alert this creates
The code
Quick startReady
org_id = "123456789012"main.tf, line 24project_id = "your-project-id"main.tf, line 25operator = "user:you@example.com"main.tf, line 26
gcloud auth application-default login
The sign-in Terraform reads. A plain gcloud auth login is not enough.terraform init
Downloads the provider. Run it once per folder.terraform plan
Shows what will be created. Changes nothing. Read it.terraform apply
Shows the plan again and waits for you to type yes.terraform destroy
When you have finished. If it refuses, How to undo it below explains why.
Formatting passedValid passedLint passed
Security scan: zero checks passed, and none flagged.
Last run 2026-10-02 with OpenTofu v1.12.6 against hashicorp/google 8.4.0.
Open main.tf as plain text
StandardReady
org_id. Numeric organisation ID.access_policy. The access policy the perimeter belongs to, as accessPolicies/<number>. gcloud access-context-manager policies list --organization <org> shows it.project_numbers. Project numbers of the projects inside the perimeter: the all-digit identifier, such as 123456789012. gcloud projects describe <id> --format='value(projectNumber)' shows one.security_project. Project containing the violations log bucket and alert.alert_emails. Addresses told about every violation, in dry run or enforced.
gcloud auth application-default login
The sign-in Terraform reads. A plain gcloud auth login is not enough.# terraform.tfvars org_id = "" access_policy = "" project_numbers = "" security_project = "" alert_emails = ""
Create this file beside the others and fill in your values. Terraform reads it on its own.terraform init
Downloads the provider. Run it once per folder.terraform plan
Shows what will be created. Changes nothing. Read it.terraform apply
Shows the plan again and waits for you to type yes.terraform output verify
Prints the commands that prove it worked.
Formatting passedValid passedLint passed
Security scan: six checks passed, and none flagged.
Last run 2026-10-02 with OpenTofu v1.12.6 against hashicorp/google 8.4.0.
Open main.tf as plain text
Open outputs.tf as plain text
Open variables.tf as plain text
Open versions.tf as plain text
HardenedReady
org_id. Numeric organisation ID.access_policy. The access policy the perimeter belongs to, as accessPolicies/<number>. gcloud access-context-manager policies list --organization <org> shows it.project_numbers. Project numbers of the projects inside the perimeter: the all-digit identifier, such as 123456789012. gcloud projects describe <id> --format='value(projectNumber)' shows one.security_project. Project containing the violations log bucket and alert.alert_emails. Addresses told about every violation, in dry run or enforced.
gcloud auth application-default login
The sign-in Terraform reads. A plain gcloud auth login is not enough.# terraform.tfvars org_id = "" access_policy = "" project_numbers = "" security_project = "" alert_emails = ""
Create this file beside the others and fill in your values. Terraform reads it on its own.terraform init
Downloads the provider. Run it once per folder.terraform plan
Shows what will be created. Changes nothing. Read it.terraform apply
Shows the plan again and waits for you to type yes.terraform output verify
Prints the commands that prove it worked.
Formatting passedValid passedLint passed
Security scan: six checks passed, and none flagged.
Last run 2026-10-02 with OpenTofu v1.12.6 against hashicorp/google 8.4.0.
Open .checkov.yml as plain text
Open guard.yml as plain text
Open main.tf as plain text
Open outputs.tf as plain text
Open variables.tf as plain text
Open versions.tf as plain text
How to check it worked
Copy an object from a bucket inside the perimeter to a bucket in another project. The copy is refused with a VPC Service Controls error.
A perimeter refuses you too when you work from outside it, including in the console. The quick start lets the named operator in; Standard uses an office network and named identities.
Changes take up to 30 minutes to take effect, so a test run straight after apply may still pass.
Enforcing a perimeter without a dry run first breaks pipelines, dashboards, and partners that call in. Standard starts in dry run and alerts on every call it would refuse.
Resources are listed by project number, the all-digit identifier, which differs from the project ID people usually type.
How to undo it
terraform destroy removes the perimeter, and calls across it work again once the change propagates.
What it costs
Nothing for VPC Service Controls. The violations log is billed by volume beyond the free allowance.
Terraform. A deny policy keyed on a network source, with a security zone behind it
What you need first
- Deny policies switched on for the tenancy, in the console's policy settings. Once on, they cannot be switched off.
- Terraform running as a member of the default domain's Administrators group, which every deny policy exempts. Standard locks network sources to that group, so nobody else can apply it twice.
- The compartments whose Object Storage sits inside, the public ranges people read from, and for Standard the VCNs your workloads read from through a service gateway.
- For the Standard security zone, Cloud Guard enabled in the tenancy and the OCID of a security zone recipe.
What it creates
- A network source in the tenancy root naming the networks that count as inside: public ranges, and in Standard VCN subnets reaching Object Storage through a service gateway
- A deny policy in each compartment with three statements. From outside the network source, reads of objects and changes to buckets are refused for every principal. Pre-authenticated requests cannot be made at all.
- A tenancy deny policy letting nobody but the default domain's Administrators change network sources (Standard)
- A security zone on each compartment, refusing new violations of the recipe you name (Standard, optional)
- An email when a perimeter policy, the network source, its lock, or a zone is changed or deleted, by anyone. The topic, its subscriptions, and the connector's policy are watched too (Standard)
See the one alert this creates
The code
Quick startReady
tenancy_ocid = "ocid1.tenancy.oc1..aaaaaaaa"main.tf, line 33compartment_ocid = "ocid1.compartment.oc1..aaaaaaaa"main.tf, line 34region = "us-ashburn-1"main.tf, line 35office_cidrs = ["203.0.113.0/24"]main.tf, line 36
oci os ns get
Prints your Object Storage namespace, which proves ~/.oci/config works.terraform init
Downloads the provider. Run it once per folder.terraform plan
Shows what will be created. Changes nothing. Read it.terraform apply
Shows the plan again and waits for you to type yes.terraform output verify
Prints the commands that prove it worked.terraform destroy
When you have finished. If it refuses, How to undo it below explains why.
Formatting passedValid passedLint passed
Security scan: one check passed, and none flagged.
Last run 2026-11-09 with OpenTofu v1.12.6 against oracle/oci 9.8.0.
Open main.tf as plain text
StandardReady
tenancy_ocid. The tenancy. Network sources and the audit connector live in its root.compartment_ocids. Compartments whose Object Storage sits inside the perimeter. Each gets its own deny policy, and its own security zone when a recipe is named. A compartment can be in one zone only, so with a recipe named, list no compartment beneath another.region. Home region identifier, such as us-ashburn-1. Identity resources are made there.alert_emails. Addresses told when the perimeter's policy or network source is changed or deleted.
oci os ns get
Prints your Object Storage namespace, which proves ~/.oci/config works.# terraform.tfvars tenancy_ocid = "" compartment_ocids = "" region = "" alert_emails = ""
Create this file beside the others and fill in your values. Terraform reads it on its own.terraform init
Downloads the provider. Run it once per folder.terraform plan
Shows what will be created. Changes nothing. Read it.terraform apply
Shows the plan again and waits for you to type yes.terraform output verify
Prints the commands that prove it worked.
Formatting passedValid passedLint passed
Security scan: one check passed, and none flagged.
Last run 2026-11-09 with OpenTofu v1.12.6 against oracle/oci 9.8.0.
Open main.tf as plain text
Open outputs.tf as plain text
Open variables.tf as plain text
Open versions.tf as plain text
HardenedReady
tenancy_ocid. The tenancy. Network sources and the audit connector live in its root.compartment_ocids. Compartments whose Object Storage sits inside the perimeter. Each gets its own deny policy, and its own security zone when a recipe is named. A compartment can be in one zone only, so with a recipe named, list no compartment beneath another.region. Home region identifier, such as us-ashburn-1. Identity resources are made there.alert_emails. Addresses told when the perimeter's policy or network source is changed or deleted.
oci os ns get
Prints your Object Storage namespace, which proves ~/.oci/config works.# terraform.tfvars tenancy_ocid = "" compartment_ocids = "" region = "" alert_emails = ""
Create this file beside the others and fill in your values. Terraform reads it on its own.terraform init
Downloads the provider. Run it once per folder.terraform plan
Shows what will be created. Changes nothing. Read it.terraform apply
Shows the plan again and waits for you to type yes.terraform output verify
Prints the commands that prove it worked.
Formatting passedValid passedLint passed
Security scan: one check passed, and none flagged.
Last run 2026-11-09 with OpenTofu v1.12.6 against oracle/oci 9.8.0.
Open .checkov.yml as plain text
Open guard.yml as plain text
Open main.tf as plain text
Open outputs.tf as plain text
Open variables.tf as plain text
Open versions.tf as plain text
How to check it worked
From an office range, oci os object get returns an object. From anywhere else, with the same credential, it fails with NotAuthorizedOrNotFound, and making the bucket public is refused. From anywhere, creating a pre-authenticated request is refused. A member of the default domain's Administrators group passes all of these. In Standard, confirm each subscription email first, then edit a perimeter policy statement; the email arrives within a few minutes.
Oracle Cloud policies are allow-only until deny policies are on, so without that one-time switch the statements here are refused as invalid. The switch is permanent.
A deny policy wins over every allow, in every compartment below it, for every principal but the default domain's Administrators. That group is the break-glass path, and it is also the group this perimeter cannot see. Keep it small.
Any-user means every principal: people, instance principals, functions, OKE pods, and connectors. Writers of objects are untouched. Readers in your VCNs must be in the network source, through the VCN's own ranges, or their reads stop too. Test Cloud Shell before relying on it either way.
The not-equal condition on the network source is Oracle's own example for a tenancy-wide restriction. Test it from outside before relying on it: one object read from a phone hotspot settles it.
Oracle checks the creator's permissions each time a pre-authenticated request is used, and does not say whether this condition applies at that check. List the compartment's requests before applying and delete the ones you did not mean; afterwards only the default domain's Administrators can.
From inside the networks, someone who may update buckets can still make one public. The security zone refuses that; without one, keep bucket updates to few people.
A security zone refuses new violations and reports existing ones through Cloud Guard. Oracle's maximum security recipe refuses public subnets and internet gateways as well as public buckets, so it can break a workload compartment. A compartment can be in one zone only.
Terraform state kept in a protected compartment cannot be read from outside the network source, including from a hosted CI runner. Keep state elsewhere, or run from inside.
Policy, network source, and topic names are unique in the tenancy. The quick start and Standard both make a network source named data-perimeter, so destroy one before applying the other.
Deleting the notification topic or the connector's policy stops the watch, and so does moving the connector out of the tenancy root. None of these can be mailed through the watch itself. The daily drift plan in Hardened is what notices.
How to undo it
terraform destroy removes the policies, the network source, the zones, and the watch. Reads work from anywhere the allow policies permit again, at once. Deny policies stay switched on for the tenancy.
What it costs
Nothing for policies, network sources, security zones, or connectors. Notifications bills email beyond a monthly free allowance, and a perimeter changes rarely.
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.