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.
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
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 query | What it answers | Where to open it |
|---|---|---|
okta/one-actor | Everything one Okta user did, newest first. Replace the login first. | CloudWatch console, Logs Insights, Queries, folder okta |
okta/admin-and-policy-changes | Changes to who can sign in, how, and with what rights. | CloudWatch console, Logs Insights, Queries, folder okta |
okta/sign-ins-by-source | Sign-ins by user, address, and result, to spot a spray or a new address. | CloudWatch console, Logs Insights, Queries, folder okta |
okta/factor-changes | Whose MFA factors changed, and who changed them. | CloudWatch console, Logs Insights, Queries, folder okta |
The code
Quick startReady
okta_org_name = "your-org"main.tf, line 29okta_base_url = "okta.com"main.tf, line 30aws_region = "us-east-1"main.tf, line 31alert_email = "security-alerts@example.com"main.tf, line 32
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.aws sts get-caller-identity
Shows the AWS account the events will go to. 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 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: 26 checks passed, and two rules flagged, each with a written reason:
Last run 2026-10-06 with OpenTofu v1.12.6.
Open main.tf as plain text
StandardReady
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.
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.aws sts get-caller-identity
Shows the AWS account the events will go to. Check it before every apply.# 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.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: 40 checks passed, and three rules flagged, each with a written reason:
Last run 2026-10-06 with OpenTofu v1.12.6.
Open detections.tf as plain text
Open main.tf as plain text
Open outputs.tf as plain text
Open queries.tf as plain text
Open variables.tf as plain text
Open versions.tf as plain text
HardenedReady
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.
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.aws sts get-caller-identity
Shows the AWS account the events will go to. Check it before every apply.# 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.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: 34 checks passed, and none flagged.
Last run 2026-10-06 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
Grant a test user the Read-Only Administrator role in Okta, then remove it. The okta-admin-granted email arrives within a few minutes.
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.
Terraform. A tenant diagnostic setting sending audit and sign-in logs to Log Analytics, with scheduled query alerts
What you need first
- Microsoft Entra ID P1 or P2, which Microsoft's guide to these logs in Log Analytics lists as a prerequisite.
- At least the Security Administrator role in Entra ID for whoever runs apply, and Contributor on the resource group. Standard and Hardened give each alert a reader role on the workspace, which needs Owner or User Access Administrator on the group.
- An existing resource group, and an email address that reaches the security team.
What it creates
- A Log Analytics workspace, and a tenant-wide diagnostic setting sending AuditLogs and SignInLogs to it
- Audit log alerts on a directory role granted or made eligible, and on an app given a secret, certificate, consent, or permissions
- Audit log alerts on a Conditional Access policy, named location, federation, authorization, or cross-tenant setting changed, and on an admin changing a user's MFA methods
- An alert when no sign-ins arrive for an hour
- Named actors left out, an identity per rule, an alert on any emergency access sign-in, and an optional alert on high-risk sign-ins (Standard)
- Saved queries for each alert, one user's activity, and sign-ins by source (Standard)
See the seven alerts this creates
Saved queries this installs
Standard and Hardened install these eight, ready for the first hour of a case. Quick start installs none.
| Saved query | What it answers | Where to open it |
|---|---|---|
entra-role-granted | The search behind the role-granted alert, over the last seven days. | Log Analytics workspace, Logs, Queries, category Identity provider signals |
entra-app-credentials | The search behind the app-credentials alert, over the last seven days. | Log Analytics workspace, Logs, Queries, category Identity provider signals |
entra-sign-in-changed | The search behind the sign-in-changed alert, over the last seven days. | Log Analytics workspace, Logs, Queries, category Identity provider signals |
entra-mfa-changed-by-admin | The search behind the mfa-changed-by-admin alert, over the last seven days. | Log Analytics workspace, Logs, Queries, category Identity provider signals |
entra-break-glass-sign-in | The search behind the break-glass-sign-in alert, over the last seven days. Only when break_glass_object_ids is set. | Log Analytics workspace, Logs, Queries, category Identity provider signals |
entra-risky-sign-in | The search behind the risky-sign-in alert, over the last seven days. Only when risky_sign_in_alerts is true. | Log Analytics workspace, Logs, Queries, category Identity provider signals |
entra-one-user | Everything one user did and every sign-in they made, last seven days. Replace the UPN first. | Log Analytics workspace, Logs, Queries, category Identity provider signals |
entra-sign-ins-by-source | Sign-ins by user, address, and result, last 24 hours. | Log Analytics workspace, Logs, Queries, category Identity provider signals |
The code
Quick startReady
subscription_id = "00000000-0000-0000-0000-000000000000"main.tf, line 29resource_group_name = "rg-security"main.tf, line 30alert_email = "security-alerts@example.com"main.tf, line 31
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 passedLint passed
Security scan: zero checks passed, and none flagged.
Last run 2026-10-06 with OpenTofu v1.12.6 against hashicorp/azurerm 5.6.0.
Open main.tf as plain text
StandardReady
subscription_id. Subscription for the workspace and alerts, as a GUID. The diagnostic setting itself covers the whole tenant.resource_group_name. An existing resource group for the workspace, alerts, and saved queries. Keep it apart from workloads.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 = "" resource_group_name = "" 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: zero checks passed, and none flagged.
Last run 2026-10-06 with OpenTofu v1.12.6 against hashicorp/azurerm 5.6.0.
Open detections.tf as plain text
Open main.tf as plain text
Open outputs.tf as plain text
Open queries.tf as plain text
Open variables.tf as plain text
Open versions.tf as plain text
HardenedReady
subscription_id. Subscription for the workspace and alerts, as a GUID. The diagnostic setting itself covers the whole tenant.resource_group_name. An existing resource group for the workspace, alerts, and saved queries. Keep it apart from workloads.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 = "" resource_group_name = "" 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: zero checks passed, and none flagged.
Last run 2026-10-06 with OpenTofu v1.12.6 against hashicorp/azurerm 5.6.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
Assign a test user the Reports Reader role, then remove it. The entra-role-granted email arrives within about fifteen minutes.
Microsoft allows up to three days for the first rows to reach a new workspace. The silence alert fires until they do.
The risk columns in the sign-in log read hidden without Entra ID P2, so the high-risk alert is off by default and does nothing without that licence.
Operation names come from Microsoft's audit activity reference, which Microsoft says changes from time to time. Run the saved queries against a week of your own data to confirm each one appears.
A Log Analytics workspace takes a key of your own only through a dedicated cluster, which is priced for 100 GB a day and more, so the workspace uses Microsoft-managed encryption.
How to undo it
terraform destroy removes the diagnostic setting, the workspace, and the alerts. The workspace goes with its data, so export what you need first.
What it costs
Entra ID logs are billed by the gigabyte in Log Analytics, and sign-in volume grows with users and apps. Read the workspace's Usage table after a week before adding more categories.
Terraform. Workspace audit logs shared with Google Cloud, an organisation sink to a log bucket, log-based metrics, and Cloud Monitoring alerts
What you need first
- A Workspace super admin to turn on sharing with Google Cloud, once, in the Admin console: Account settings > Legal and compliance > Sharing options.
- The Google Cloud organisation linked to the Workspace account, and rights to create organisation sinks and grant roles in a security project.
- The Cloud Logging and Cloud Monitoring APIs on in the security project.
What it creates
- An organisation sink copying every Admin, Login, Groups, and OAuth audit entry into a log bucket in the security project
- Alerts on an admin role or domain-wide API access granted, and on 2-Step Verification enforcement or single sign-on changed
- Alerts on 2SV turned off for a user, an account warning from Google, and mail forwarded outside the domain
- An alert when no sign-in events arrive for an hour
- Named admins left out of the change alerts, an alert on an admin resetting a password, and a configurable silence window (Standard)
- Shared saved queries for each alert, one user, and failed sign-ins (Standard)
See the seven alerts this creates
Saved queries this installs
Standard and Hardened install these eight, ready for the first hour of a case. Quick start installs none.
| Saved query | What it answers | Where to open it |
|---|---|---|
Workspace: admin-granted | The events the admin-granted alert matches. | Logs Explorer, Saved queries, Shared, in the security project |
Workspace: sign-in-changed | The events the sign-in-changed alert matches. | Logs Explorer, Saved queries, Shared, in the security project |
Workspace: two-step-off | The events the two-step-off alert matches. | Logs Explorer, Saved queries, Shared, in the security project |
Workspace: password-reset-by-admin | The events the password-reset-by-admin alert matches. | Logs Explorer, Saved queries, Shared, in the security project |
Workspace: account-warning | The events the account-warning alert matches. | Logs Explorer, Saved queries, Shared, in the security project |
Workspace: mail-forwarded-out | The events the mail-forwarded-out alert matches. | Logs Explorer, Saved queries, Shared, in the security project |
Workspace: one user | Everything one user did, or that names them. Replace the email first. | Logs Explorer, Saved queries, Shared, in the security project |
Workspace: failed sign-ins | Failed Workspace sign-ins. | Logs Explorer, Saved queries, Shared, in the security project |
The code
Quick startReady
org_id = "123456789012"main.tf, line 27security_project = "your-security-project"main.tf, line 28alert_email = "security-alerts@example.com"main.tf, line 29
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 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: six checks passed, and none flagged.
Last run 2026-10-06 with OpenTofu v1.12.6 against hashicorp/google 8.4.0.
Open main.tf as plain text
StandardReady
org_id. Numeric ID of the Google Cloud organisation linked to the Workspace account.security_project. Project that contains the log bucket, alerts, and saved queries. Keep it separate from workloads.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 = "" 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-06 with OpenTofu v1.12.6 against hashicorp/google 8.4.0.
Open detections.tf as plain text
Open main.tf as plain text
Open outputs.tf as plain text
Open queries.tf as plain text
Open variables.tf as plain text
Open versions.tf as plain text
HardenedReady
org_id. Numeric ID of the Google Cloud organisation linked to the Workspace account.security_project. Project that contains the log bucket, alerts, and saved queries. Keep it separate from workloads.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 = "" 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-06 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
Give a test user the Help Desk Admin role in the Admin console, then remove it. The admin-granted alert emails within a few minutes.
Google documents the sharing switch only in the Admin console, so Terraform cannot turn it on or see that it is off. The silence alert is how you find out.
OAuth and SAML entries are shared only from the Enterprise, Education, Voice Premier, and Cloud Identity Premium editions.
The entries live in a bucket Logs Explorer does not search by default. Choose Refine scope, then Scope by storage, and pick workspace-signals.
Google shows OAuth events in the Admin console up to a few hours late, so OAuth entries may reach Cloud Logging late too.
How to undo it
terraform destroy removes the sink, the metrics, the alerts, and the saved queries. The log bucket is deleted with its copy; Workspace keeps its own entries at the organisation.
What it costs
Cloud Logging charges to store what the sink copies, after the first 50 GiB a month in the project, and log-based metrics are billed as custom metrics.
Terraform. Microsoft Sentinel's Microsoft 365 connector filling OfficeActivity in Log Analytics, with scheduled query alerts
What you need first
- Auditing on in the tenant: Get-AdminAuditLogConfig | Format-List UnifiedAuditLogIngestionEnabled reads True.
- Global Administrator or Security Administrator in the tenant for whoever runs apply, and Contributor on the resource group. Standard and Hardened give each alert a reader role on the workspace, which needs Owner or User Access Administrator.
- An existing resource group, and an email address that reaches the security team.
What it creates
- A Log Analytics workspace of its own, with Microsoft Sentinel on and the Microsoft 365 connector for Exchange, SharePoint, and Teams
- Four alerts on Exchange: mail forwarded by inbox rule or mailbox setting, a mail flow rule that copies or redirects, mailbox or send-as access granted, and audit settings changed
- An alert when no Microsoft 365 records arrive for 12 hours
- Named admins left out of the admin alerts, and an identity per rule (Standard)
- Alerts on a guest added to a team, and on one user downloading or syncing more files than a set number in an hour (Standard)
- Saved queries for each alert, one user, and when each workload last sent a record (Standard)
See the seven alerts this creates
Saved queries this installs
Standard and Hardened install these eight, ready for the first hour of a case. Quick start installs none.
| Saved query | What it answers | Where to open it |
|---|---|---|
m365-mail-forwarded | The search behind the mail-forwarded alert, over the last seven days. | Log Analytics workspace, Logs, Queries, category Identity provider signals |
m365-transport-rule-redirect | The search behind the transport-rule-redirect alert, over the last seven days. | Log Analytics workspace, Logs, Queries, category Identity provider signals |
m365-mailbox-access-granted | The search behind the mailbox-access-granted alert, over the last seven days. | Log Analytics workspace, Logs, Queries, category Identity provider signals |
m365-audit-weakened | The search behind the audit-weakened alert, over the last seven days. | Log Analytics workspace, Logs, Queries, category Identity provider signals |
m365-guest-added-to-team | The search behind the guest-added-to-team alert, over the last seven days. | Log Analytics workspace, Logs, Queries, category Identity provider signals |
m365-bulk-download | Users ranked by distinct files downloaded or synced in the last hour. | Log Analytics workspace, Logs, Queries, category Identity provider signals |
m365-signals-silent | When each Microsoft 365 workload last sent a record. | Log Analytics workspace, Logs, Queries, category Identity provider signals |
m365-one-user | Everything one user did in Microsoft 365, last seven days. Replace the UPN first. | Log Analytics workspace, Logs, Queries, category Identity provider signals |
The code
Quick startReady
subscription_id = "00000000-0000-0000-0000-000000000000"main.tf, line 30resource_group_name = "rg-security"main.tf, line 31alert_email = "security-alerts@example.com"main.tf, line 32
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 passedLint passed
Security scan: zero checks passed, and none flagged.
Last run 2026-10-06 with OpenTofu v1.12.6 against hashicorp/azurerm 5.6.0.
Open main.tf as plain text
StandardReady
subscription_id. Subscription for the workspace and alerts, as a GUID.resource_group_name. An existing resource group for the workspace, alerts, and saved queries. Keep it apart from workloads.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 = "" resource_group_name = "" 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: zero checks passed, and none flagged.
Last run 2026-10-06 with OpenTofu v1.12.6 against hashicorp/azurerm 5.6.0.
Open detections.tf as plain text
Open main.tf as plain text
Open outputs.tf as plain text
Open queries.tf as plain text
Open variables.tf as plain text
Open versions.tf as plain text
HardenedReady
subscription_id. Subscription for the workspace and alerts, as a GUID.resource_group_name. An existing resource group for the workspace, alerts, and saved queries. Keep it apart from workloads.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 = "" resource_group_name = "" 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: zero checks passed, and none flagged.
Last run 2026-10-06 with OpenTofu v1.12.6 against hashicorp/azurerm 5.6.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
In Outlook on the web, on a test mailbox, add an inbox rule that forwards to an outside address, then delete it. The m365-mail-forwarded email follows once the record reaches the workspace.
Turning on Sentinel puts every table in the workspace under Sentinel billing, which is why this source gets a workspace of its own. Do not point other logs at it.
Exchange admin actions are recorded under the cmdlet's name, so a rule made in Outlook on the web shows as New-InboxRule. Check your own data for how other clients record rules before relying on the alert alone.
The connector reads only the tenant that runs apply.
Forwarding alerts fire for everyone, admins included, so an attacker who takes an admin account is still seen forwarding its mail. Clearing forwarding names the same parameter, so it alerts too.
How to undo it
terraform destroy removes the connector, Sentinel, the workspace, and the alerts. The workspace goes with its data, so export what you need first.
What it costs
Sentinel and Log Analytics bill what the workspace ingests. After the first day, run OfficeActivity | summarize sum(_BilledSize) by _IsBillable to see which records you pay for.
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.