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.
Use the account in a drill. An alert reaches the on-call channel within minutes.
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. 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 startReady
trail_log_group = "your-cloudtrail-log-group"main.tf, line 24alert_email = "oncall@example.com"main.tf, line 25
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: 17 checks passed, and four rules flagged, each with a written reason:
- SNS topic encrypted
- IAM user outside single sign-on
- AdministratorAccess attached
- Policy attached to a user
Last run 2026-10-02 with OpenTofu v1.12.6 against hashicorp/aws 6.66.0.
Open main.tf as plain text
StandardReady
trail_log_group. CloudWatch log group a multi-region CloudTrail trail delivers to.
aws sts get-caller-identity
Shows the account and role you are signed in as. Check it before every apply.# terraform.tfvars trail_log_group = ""
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: 31 checks passed, and six rules flagged, each with a written reason:
- IAM permissions management without constraints
- IAM write access without constraints
- IAM user outside single sign-on
- AdministratorAccess attached
- IAM resource of *
- Policy attached to a user
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
trail_log_group. CloudWatch log group a multi-region CloudTrail trail delivers to.
aws sts get-caller-identity
Shows the account and role you are signed in as. Check it before every apply.# terraform.tfvars trail_log_group = ""
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: 28 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
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.
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.
Terraform. A cloud-only account excluded from Conditional Access, with alerts on sign-in and change
What you need first
- The account created in Entra first: cloud-only, a FIDO2 security key, excluded from Conditional Access. The quick start lists the steps.
- Owner or User Access Administrator where the account gets Owner.
- Global Administrator or Security Administrator, to stream Entra logs.
What it creates
- Owner on the subscription for the account
- Entra sign-in and audit logs and the Activity Log in a Log Analytics workspace, kept a year
- An email each time the account signs in or does anything in the subscription
- Three native activity log alerts, which Azure evaluates without the workspace: a diagnostic setting deleted, a diagnostic setting written, and a log search rule disabled by Azure
- Several accounts, Owner at a management group or subscription, several watched subscriptions, and a second alert on any change to them (Standard)
- A cannot-delete lock on the monitoring resource group, made last so it covers everything there, and a native alert on any lock deleted (Standard)
See the six alerts this creates
The code
Quick startReady
break_glass_upn = "breakglass@example.onmicrosoft.com"main.tf, line 31break_glass_object_id = "00000000-0000-0000-0000-000000000000"main.tf, line 32alert_email = "oncall@example.com"main.tf, line 33
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 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 monitoring workspace, and whose Activity Log is watched.role_scope. Where the accounts get Owner: a management group ID such as /providers/Microsoft.Management/managementGroups/<tenant id> for the root, or a subscription ID. Removing an Owner assignment made at a management group is logged there, where this template does not watch.accounts. Break-glass accounts by user principal name, each with its Entra object ID. Two, held by different people, means one lost key does not lock everyone out.alert_emails. Addresses that receive the alerts. Prefer an on-call address over a person.
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 = "" role_scope = "" accounts = "" 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 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 monitoring workspace, and whose Activity Log is watched.role_scope. Where the accounts get Owner: a management group ID such as /providers/Microsoft.Management/managementGroups/<tenant id> for the root, or a subscription ID. Removing an Owner assignment made at a management group is logged there, where this template does not watch.accounts. Break-glass accounts by user principal name, each with its Entra object ID. Two, held by different people, means one lost key does not lock everyone out.alert_emails. Addresses that receive the alerts. Prefer an on-call address over a person.
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 = "" role_scope = "" accounts = "" 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 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
Wait up to 90 minutes after the first apply, while the exports start. Then sign in as the account with its security key. The email follows once the sign-in reaches the workspace. Standard prints more checks with terraform output verify.
Terraform cannot create the account, register its key, or exclude it from Conditional Access with this provider. Those steps are manual, and the alert is what tells you if they are undone.
An account left in a Conditional Access policy that requires a managed device or MFA it cannot satisfy is locked out when you need it. Record the exclusions.
Entra logs are streamed tenant-wide. A second diagnostic setting with the same categories doubles the ingestion bill.
With Owner at a management group, list every subscription below it in watched_subscription_ids. Removing an Owner assignment made at a management group is logged there, which this template does not watch; the sign-in alert still fires on use.
Every alert, the native ones included, emails through one action group. In the quick start, deleting or disabling that group, or deleting its resource group, silences them all. Standard's lock stops the deletes, but whoever can edit the group can still disable it or change its addresses.
Standard's lock blocks Terraform too. A change that replaces or removes a resource in the monitoring group fails while it is on. Remove the lock with terraform destroy -target=azurerm_management_lock.monitoring, then apply, and the lock returns. Its removal fires the lock alert.
The native alerts read one subscription's activity log. The Entra log stream is set at the tenant, and each other watched subscription keeps its own activity log, so changes to those raise no alert. 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.
An export can take up to 90 minutes to start after it is made, so run the drills after that. Azure disables a log search rule whose query fails for a week, and the rule-disabled alert reports that without the workspace.
How to undo it
In Standard, remove the lock first with terraform destroy -target=azurerm_management_lock.monitoring, or module.standard.azurerm_management_lock.monitoring in Hardened. Then terraform destroy removes the role assignment, the diagnostic settings, the alerts, and the workspace. The account itself stays in Entra until you delete it.
What it costs
Log Analytics by GB ingested and kept, and a small monthly charge per log search alert rule.
Terraform. A dedicated organisation administrator with a log-based alert
What you need first
- The break-glass account created by hand in the Google Workspace or Cloud Identity admin console, outside single sign-on, with a hardware security key.
- Rights to grant roles at organisation level and to create organisation log sinks.
- A security project to contain the activity log bucket and the alerts.
What it creates
- The Organization Administrator role for the account
- An organisation sink that copies everything the account does, in every project, into a log bucket kept 400 days
- A log-based metric and alert policy that email on any activity
- Several accounts, and a second alert when anyone changes an IAM grant that names them (Standard)
See the two alerts this creates
The code
Quick startReady
org_id = "123456789012"main.tf, line 19security_project = "your-security-project"main.tf, line 20break_glass = "break-glass@example.com"main.tf, line 21alert_email = "oncall@example.com"main.tf, line 22
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: nine 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.security_project. Project that contains the activity bucket and the alerts. Keep it separate from workloads.break_glass_accounts. Break-glass accounts, created outside single sign-on. Two, held by different people, means one lost key does not lock everyone out.alert_emails. Addresses that receive the alerts. Prefer an on-call address over a person.
gcloud auth application-default login
The sign-in Terraform reads. A plain gcloud auth login is not enough.# terraform.tfvars org_id = "" security_project = "" break_glass_accounts = "" 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: nine 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.security_project. Project that contains the activity bucket and the alerts. Keep it separate from workloads.break_glass_accounts. Break-glass accounts, created outside single sign-on. Two, held by different people, means one lost key does not lock everyone out.alert_emails. Addresses that receive the alerts. Prefer an on-call address over a person.
gcloud auth application-default login
The sign-in Terraform reads. A plain gcloud auth login is not enough.# terraform.tfvars org_id = "" security_project = "" break_glass_accounts = "" 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: nine 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
Sign in as the account in a drill and change something harmless, such as a label on a test project. The alert email arrives within minutes.
Terraform cannot create the account or set its password. Create it in the admin console, and keep it out of single sign-on, or it fails exactly when it is needed.
Log-based metrics only see their own project's logs, so an organisation sink first copies the account's entries from every project into one bucket.
Reads are Data Access logs, off by default in most services, so a look-only session may raise no alert. Every change raises one.
Sign-ins appear in Cloud Logging only when Google Workspace shares its audit logs with Google Cloud, a setting in the admin console.
How to undo it
terraform destroy removes the role, the sink, the bucket, and the alerts. The account itself stays in the admin console.
What it costs
Nothing for the role and the alert. The log bucket contains only this account's entries, which are few.
Terraform. A local user in the Default domain, outside federation, alerted on every use
What you need first
- A tenancy administrator, working in the home region.
- After apply: a password reset and MFA enrolment for each account, both sealed. The quick start lists the steps.
What it creates
- A user in the Default identity domain, in Administrators, allowed a console password and no other credential
- An alarm email when Audit records the account doing anything, in any compartment
- Several accounts in a group and policy of their own (Standard)
- A second email on any change Audit records against the accounts, their memberships, group, and policy, or against the use connector, its alarm, the topic, its subscription, and the connectors' policy (Standard)
See the two alerts this creates
The code
Quick startReady
tenancy_ocid = "ocid1.tenancy.oc1..change-me"main.tf, line 35home_region = "us-ashburn-1"main.tf, line 36account_email = "breakglass-owner@example.com"main.tf, line 37alert_email = "security-oncall@example.com"main.tf, line 38
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 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 one rule flagged, each with a written reason:
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.region. The tenancy's home region, such as us-ashburn-1. Identity changes and their audit events happen there.accounts. Emergency accounts, by user name, each with a mailbox its owners read. Two, held by different people, means one lost key does not lock everyone out.alert_email. Address for the alerts. Prefer an on-call address over a person. It must confirm the subscription before mail arrives.
oci os ns get
Prints your Object Storage namespace, which proves ~/.oci/config works.# terraform.tfvars tenancy_ocid = "" region = "" accounts = "" alert_email = ""
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: two checks 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.region. The tenancy's home region, such as us-ashburn-1. Identity changes and their audit events happen there.accounts. Emergency accounts, by user name, each with a mailbox its owners read. Two, held by different people, means one lost key does not lock everyone out.alert_email. Address for the alerts. Prefer an on-call address over a person. It must confirm the subscription before mail arrives.
oci os ns get
Prints your Object Storage namespace, which proves ~/.oci/config works.# terraform.tfvars tenancy_ocid = "" region = "" accounts = "" alert_email = ""
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: two checks 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
Confirm the subscription email first. Then sign in as the account and open any page in the console. The alarm email, naming the account, arrives within a few minutes. Standard prints more checks with terraform output verify.
Identity changes and their audit events happen in the home region. The connectors must be there, or nothing is caught.
A connector that emails directly may read only one compartment's audit events. Use anywhere in the tenancy is counted into a metric, and an alarm sends the email, so it names the account and the time but not the action. Logging Search shows what the account did.
Terraform cannot set the password or enrol MFA. Those steps are manual, and until they are done the account cannot sign in.
If the domain's sign-on policy sends every user to your identity provider, the account depends on it after all. Exclude the account from that rule.
Deleting the notification topic or the connectors' policy stops both alerts, and neither can report it. Hardened refuses both deletes, and its daily drift plan notices one made by hand.
Standard's change email also fires when an apply changes the use connector, its alarm, the topic, or the subscription. Expect one after such an apply.
How to undo it
terraform destroy deletes the accounts, the alerts, and, in Standard, the group and policy.
What it costs
Nothing for the accounts. Notifications email is free up to a monthly limit.
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.