iac.htora.dev · security templates

Home/Templates/Emergency access that works when login is broken

Emergency access that works when login is broken

A separate account that does not depend on your identity provider, and shouts every time it is used.

Terraform

Why bother

Emergency accounts fail two ways. They sit behind the same single sign-on that just went down, or they work quietly and nobody notices they were used. This sets up an account outside the normal login path, with an alert on every sign-in.

How you know it worked

Use the account in a drill. An alert reaches the on-call channel within minutes.

How it works

1Normal sign-in is brokenthe identity provider is down2The emergency accountoutside single sign-on, with a hardware key3Everything it does is recordedin the cloud's audit log4An alert fires, every timeto the on-call channel
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. A standalone IAM user with a hardware key and a CloudTrail alarm

What you need first

  • A multi-region CloudTrail trail delivering to CloudWatch Logs, such as the Standard audit log template builds. Apply in that log group's region.
  • Someone to set each user's password and register its hardware security key by hand after apply, and a sealed place to keep them.
  • An email address, or for Standard an SNS topic, that reaches the on-call channel.

What it creates

  • An IAM user with AdministratorAccess, refused everything until it signs in with MFA
  • A metric filter and alarm on the trail's log group that fire on any sign-in or call by the user, in any region
  • Two users by default, each unable to create access keys for itself (Standard)
  • A second alarm on changes to the users: access keys, passwords, MFA, policies, or groups (Standard)

See the two alerts this creates

The code

Quick startReadyone file, 127 lines
One file. One MFA-gated administrator user and an alarm on any sign-in or call.
Change these first
  • trail_log_group = "your-cloudtrail-log-group" main.tf, line 24
  • alert_email = "oncall@example.com" main.tf, line 25
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: 17 checks passed, and four rules flagged, each with a written reason:

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

outcomes/breakglass-identity/aws/t0
main.tf
Open main.tf as plain text
StandardReadyfour files, 243 lines
Adds two users by default, a self-imposed ban on access keys, and an alarm on any change to the users. It also adds an existing topic or several emails, and a topic key the alarms are allowed to use.
Change these first
  • trail_log_group. CloudWatch log group a multi-region CloudTrail trail delivers to.
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
    trail_log_group = ""
    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: 31 checks passed, and six rules flagged, each with a written reason:

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

outcomes/breakglass-identity/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, 212 lines
Standard as a module. Plan rules refuse access keys for the accounts, the accounts moved off their path, the MFA or access-key denies dropped, alarms deleted, disabled, or without an action, key rotation off. A daily plan reports drift, and the scan fails on any unexplained finding.
Change these first
  • trail_log_group. CloudWatch log group a multi-region CloudTrail trail delivers to.
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
    trail_log_group = ""
    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: 28 checks passed, and none flagged.

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

outcomes/breakglass-identity/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

Sign in as the user with its password and hardware key in a drill. The alarm fires and the email arrives within about ten minutes.

What catches people

Terraform never sets the password or the MFA device, so neither lands in state. Set both by hand after apply, and until you do the user cannot sign in.

The alert reads the trail's CloudWatch log group, which contains every region's events. An EventBridge rule in one region would miss actions taken in the others.

Service control policies apply to IAM users too. Add each user's ARN to the guardrail template's exempt list, or the guardrails block the repairs it exists for.

CloudWatch filter patterns are limited to 1,024 characters, so Standard allows at most three users.

CloudWatch alarms cannot publish to an SNS topic encrypted with the AWS managed key, and nothing reports the failure. Standard creates its topic with a key whose policy allows them. A topic you pass in needs the same.

How to undo it

terraform destroy removes the users, their policies, and the alarms. Delete any password or MFA device set by hand first, or destroy fails on the user.

What it costs

Nothing for the users. The metric filters and alarms cost well under a dollar a month, and the Standard topic's KMS key a dollar a month.

Good to know

  • Drill it on a schedule. An account nobody has signed in to for a year tends to fail when it is needed, through an expired password, a lost key, or a policy that now blocks it.
  • Keep two, held by different people. One lost key or one person away then does not lock everyone out.

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.