iac.htora.dev · security templates

Home/Templates/Block the changes you never want

Block the changes you never want

Policies that make dangerous actions fail outright, so there is nothing to alert on afterwards.

Terraform

Why bother

Alerts tell you that someone turned off logging or opened a region you do not use. By then it has happened. A guardrail makes the action fail, so there is nothing to respond to.

How you know it worked

Try a blocked action from a member account. It should be refused.

How it works

1Someone tries a blocked actionswitching off logging, a new region2The organisation policychecked before anything happens3The call is refusednothing changes4The attempt is recordedin the audit log, for whoever reviews it
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 control policies from the management account

What you need first

  • AWS Organizations with all features on, and Terraform running in the management account.
  • An OU or account to attach to. Start with a test OU.
  • For Standard, the ARNs of the break-glass and security automation roles to exempt.

What it creates

  • A policy that denies leaving the organisation, audit and detection tampering, and use of the root user
  • Protection for the account-wide S3 public access block and for roles under the security path (Standard)
  • A second policy that refuses regional services outside the regions you name (Standard)
  • An attachment to each target you list

The code

Quick startReadyone file, 83 lines
One file. One policy with three rules, attached to one OU or account.
Change these first
  • target_id = "ou-xxxx-xxxxxxxx" main.tf, line 19
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: 12 checks passed, and none flagged.

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

outcomes/guardrail-baseline/aws/t0
main.tf
Open main.tf as plain text
StandardReadyfour files, 208 lines
Adds protection for Security Hub, Access Analyzer, the public access block, and the security team's roles, a region limit, named exemptions, and several targets.
Change these first
  • 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
    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/guardrail-baseline/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, 200 lines
Standard as a module. Plan rules refuse a policy deleted, an Allow in a service control policy, a baseline statement dropped, the tampering deny weakened, the region deny removed, wildcard exemptions. A daily plan reports drift, and the scan fails on any unexplained finding.
Change these first
  • 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
    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/guardrail-baseline/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 under the target, run aws cloudtrail stop-logging against any trail. It fails with an explicit deny in a service control policy. Standard prints two more checks with terraform output verify.

What catches people

Service control policies never apply to the management account. Anything run there is unaffected, so keep workloads out of it.

A policy attached to the organisation root applies to every member account at once. Attach it to a test OU first, and try the actions your teams use every day.

The region rule leaves global services out, because they answer from us-east-1. A service missing from that list stops working outside the allowed regions, so review the list against what you run.

Each policy is limited to 5,120 characters, and a target takes at most five policies. Add rules to these two before adding a third.

How to undo it

terraform destroy detaches and deletes the policies, and the denied actions work again at once.

What it costs

Nothing. Service control policies are free.

Good to know

  • A guardrail is a deny that no permission inside the account can override. Keep the list to actions nobody should ever take, and handle everything else with ordinary permissions.
  • Every refused call is still recorded in the audit log, with the policy that refused it. A burst of refusals is worth a detection of its own.

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.