iac.htora.dev · security templates

Home/Templates/Catch account takeover at the identity provider

Catch account takeover at the identity provider

Alerts in Okta, Entra ID, Google Workspace, and Microsoft 365 on the moves that turn one stolen account into many. They cover admin rights granted, sign-in rules changed, MFA removed, mail forwarded out, and a log feed going quiet.

Terraform

Why bother

An account takeover can run its whole course without touching a cloud console. Someone talks the help desk into resetting a user's MFA and signs in. They grant themselves an admin role, add an identity provider or an app secret so they can come back, and forward the mailbox somewhere outside. Each of those is an ordinary admin action in the identity provider, recorded in its own audit log, which the cloud audit templates never read. These templates bring that log into the cloud you already watch and alert on the moves themselves.

How you know it worked

In a test tenant or org, grant a test user an admin role and remove it. The alert reaches the security inbox within minutes.

How it works

1Someone acts in the identity providergrants a role, changes sign-in, removes MFA2Its audit log records itOkta, Entra ID, Workspace, or Microsoft 3653A copy lands in your cloudEventBridge, Log Analytics, or Cloud Logging4A rule matchesand an email names who, what, and from where
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. Okta's System Log streamed to an Amazon EventBridge partner event source, with EventBridge rules and a CloudWatch log group

What you need first

  • An Okta super admin, to make the API token Terraform uses or an API service app with the okta.logStreams.manage scope. Okta allows two log streams per org.
  • An AWS account, in one of the 17 regions Okta streams to: US East and West, Canada, São Paulo, Frankfurt, Ireland, London, Paris, Stockholm, Mumbai, Singapore, Sydney, Tokyo, Seoul, and Osaka.
  • An email address that reaches the security team.

What it creates

  • An Okta log stream to EventBridge, and the partner event bus that accepts it
  • A log group that keeps every Okta event, and a rule that fills it
  • Rules that email on admin roles or API tokens granted, and on identity providers, policies, or authenticators changed
  • Rules that email on a user's MFA reset or removed, an Okta support session, and log streams or event hooks changed
  • An alarm when no Okta events arrive for an hour
  • Named pipeline actors left out of the change alerts, and a sixth rule on a session that moves networks or an API token used outside its zone (Standard)
  • A KMS key for the log group and the alert topic, and saved Logs Insights queries for one actor, admin and policy changes, sign-ins by source, and factor changes (Standard)

See the seven alerts this creates

Saved queries this installs

Standard and Hardened install these four, ready for the first hour of a case. Quick start installs none.

Saved queryWhat it answersWhere to open it
okta/one-actorEverything one Okta user did, newest first. Replace the login first.CloudWatch console, Logs Insights, Queries, folder okta
okta/admin-and-policy-changesChanges to who can sign in, how, and with what rights.CloudWatch console, Logs Insights, Queries, folder okta
okta/sign-ins-by-sourceSign-ins by user, address, and result, to spot a spray or a new address.CloudWatch console, Logs Insights, Queries, folder okta
okta/factor-changesWhose MFA factors changed, and who changed them.CloudWatch console, Logs Insights, Queries, folder okta

The code

Quick startReadyone file, 278 lines
One file. The stream, the bus, an archive of every event, five alert rules, and a silence alarm.
Change these first
  • okta_org_name = "your-org" main.tf, line 29
  • okta_base_url = "okta.com" main.tf, line 30
  • aws_region = "us-east-1" main.tf, line 31
  • alert_email = "security-alerts@example.com" main.tf, line 32
Run it
  1. export OKTA_API_TOKEN=<token>
    The Okta provider reads its token from here. Make it as a super admin, and revoke it when you are done.
  2. aws sts get-caller-identity
    Shows the AWS account the events will go to. Check it before every apply.
  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.
  7. terraform destroy
    When you have finished. If it refuses, How to undo it below explains why.
Download main.tf
Checks

Formatting passedValid not runLint passed

Security scan: 26 checks passed, and two rules flagged, each with a written reason:

Last run 2026-10-06 with OpenTofu v1.12.6.

outcomes/identity-provider-signals/okta/t0
main.tf
Open main.tf as plain text
StandardReadysix files, 509 lines
Adds named pipeline exceptions, a session-and-token rule, your own key on the archive and topic, a configurable silence window, and saved queries.
Change these first
  • okta_org_name. The Okta org's subdomain, such as acme for acme.okta.com. It also names the event source in AWS.
  • aws_region. Region that receives the events. Okta streams to 17 regions, listed in the validation below.
  • alert_emails. Addresses subscribed to the alert topic. Prefer an on-call address over a person.
Run it
  1. export OKTA_API_TOKEN=<token>
    The Okta provider reads its token from here. Make it as a super admin, and revoke it when you are done.
  2. aws sts get-caller-identity
    Shows the AWS account the events will go to. Check it before every apply.
  3. # terraform.tfvars
    okta_org_name = ""
    aws_region = ""
    alert_emails = ""
    Create this file beside the others and fill in your values. Terraform reads it on its own.
  4. terraform init
    Downloads the provider. Run it once per folder.
  5. terraform plan
    Shows what will be created. Changes nothing. Read it.
  6. terraform apply
    Shows the plan again and waits for you to type yes.
  7. terraform output verify
    Prints the commands that prove it worked.
Download all six files as a zip
Checks

Formatting passedValid not runLint passed

Security scan: 40 checks passed, and three rules flagged, each with a written reason:

Last run 2026-10-06 with OpenTofu v1.12.6.

outcomes/identity-provider-signals/okta/t1
detections.tf
Open detections.tf as plain text
main.tf
Open main.tf as plain text
outputs.tf
Open outputs.tf as plain text
queries.tf
Open queries.tf as plain text
variables.tf
Open variables.tf as plain text
versions.tf
Open versions.tf as plain text
HardenedReadysix files, 287 lines
Standard as a module. Plan rules refuse the stream, bus, rules, archive, key, topic, or alarms deleted, and the stream inactive or pointed elsewhere. They also refuse any watched event type dropped from every rule, the archive narrowed or unencrypted, and a silence alarm that ignores missing data. A daily plan reports drift, including a stream Okta deactivated.
Change these first
  • okta_org_name. The Okta org's subdomain, such as acme for acme.okta.com. It also names the event source in AWS.
  • aws_region. Region that receives the events. Okta streams to 17 regions, listed in the validation below.
  • alert_emails. Addresses subscribed to the alert topic. Prefer an on-call address over a person.
Run it
  1. export OKTA_API_TOKEN=<token>
    The Okta provider reads its token from here. Make it as a super admin, and revoke it when you are done.
  2. aws sts get-caller-identity
    Shows the AWS account the events will go to. Check it before every apply.
  3. # terraform.tfvars
    okta_org_name = ""
    aws_region = ""
    alert_emails = ""
    Create this file beside the others and fill in your values. Terraform reads it on its own.
  4. terraform init
    Downloads the provider. Run it once per folder.
  5. terraform plan
    Shows what will be created. Changes nothing. Read it.
  6. terraform apply
    Shows the plan again and waits for you to type yes.
  7. terraform output verify
    Prints the commands that prove it worked.
Download all six files as a zip
Checks

Formatting passedValid not runLint passed

Security scan: 34 checks passed, and none flagged.

Last run 2026-10-06 with OpenTofu v1.12.6.

outcomes/identity-provider-signals/okta/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

Grant a test user the Read-Only Administrator role in Okta, then remove it. The okta-admin-granted email arrives within a few minutes.

What catches people

Okta deactivates a stream when two delivery attempts fail, and does not turn it back on. A deactivated stream cannot send the event that says so, which is why the silence alarm exists. When it fires, reactivate the stream in Reports > Log Streaming.

Events Okta sends before the event bus exists are dropped. The bus is created right after the stream, so the first minutes after apply may be missing.

The stream's account, region, and source name cannot change. Changing any of them replaces the stream, the source, and the bus.

The org name is the subdomain, acme for acme.okta.com, and it is part of the event source name in AWS.

How to undo it

terraform destroy removes the stream, the bus, the rules, the alarm, and the topic. The log group is deleted with its events, so export what you need first.

What it costs

EventBridge charges for each partner event received, and CloudWatch Logs charges to ingest and keep every Okta event. A busy org sends an event for every sign-in, so check the bill after a week. The KMS key in Standard adds a monthly key charge.

Good to know

  • Each source also has a silence alert. A log feed that stops is the quietest way to hide everything else, and an Okta stream that Okta itself switches off cannot report that it stopped.
  • Tune before you trust. Run the saved queries over a normal week, name the provisioning pipeline as an expected actor, and leave MFA and forwarding alerts on for everyone.
  • An alert on a role grant or an MFA reset starts a check with the person named. Reach them through a channel the attacker does not control, such as a call to a known number.

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.