# identity-provider-signals / workspace / t1 "Standard" # # The quick start's five alerts and the silence alert, with named admins # left out, plus an alert on an admin resetting a user's password, and saved # Logs Explorer queries for working the case. # # Before you start, a Workspace super admin turns sharing on, once, in the # Admin console: Account > Account settings > Legal and compliance > Sharing # options > Enabled. Google documents this switch only in the Admin console, # so Terraform cannot turn it on. OAuth and SAML entries are shared only # from the Enterprise, Education, Voice Premier, and Cloud Identity Premium # editions. # # Of what this creates, only the alert policies and notification channels # take labels, and they carry the label contract. # # The bucket is global and uses Google-managed encryption. A key of your own # on a log bucket needs a regional bucket location. locals { labels = merge({ owner = var.owner environment = var.environment data_classification = "confidential" managed_by = "terraform" }, var.extra_labels) admin = "google.admin.AdminService" login = "google.login.LoginService" not_expected = length(var.expected_admins) == 0 ? "" : " AND NOT protoPayload.authenticationInfo.principalEmail=(${join(" OR ", [for p in var.expected_admins : "\"${p}\""])})" matches = { admin-granted = { match = "protoPayload.methodName=(\"${local.admin}.assignRole\" OR \"${local.admin}.grantAdminPrivilege\" OR \"${local.admin}.grantDelegatedAdminPrivileges\" OR \"${local.admin}.authorizeApiClientAccess\")" skip_expected = true doc = "An admin role or admin privileges were granted, or an API client was given domain-wide access." } sign-in-changed = { match = "protoPayload.methodName=(\"${local.admin}.enforceStrongAuthentication\" OR \"${local.admin}.allowStrongAuthentication\" OR \"${local.admin}.changeAllowedTwoStepVerificationMethods\" OR \"${local.admin}.toggleSsoEnabled\" OR \"${local.admin}.changeSsoSettings\")" skip_expected = true doc = "2-Step Verification enforcement, the allowed 2SV methods, or single sign-on settings changed." } two-step-off = { match = "protoPayload.methodName=(\"${local.admin}.turnOff2StepVerification\" OR \"${local.login}.2svDisable\")" skip_expected = false doc = "2-Step Verification was turned off for a user, by an admin or by the user." } # With 2SV off, a reset password is the whole account. password-reset-by-admin = { match = "protoPayload.methodName=(\"${local.admin}.changePassword\" OR \"${local.admin}.changePasswordOnNextLogin\")" skip_expected = true doc = "An admin set a user's password, or made them change it at next sign-in." } account-warning = { match = "protoPayload.methodName=(\"${local.login}.suspiciousLogin\" OR \"${local.login}.suspiciousProgrammaticLogin\" OR \"${local.login}.govAttackWarning\" OR \"${local.login}.accountDisabledHijacked\" OR \"${local.login}.accountDisabledPasswordLeak\")" skip_expected = false doc = "Google flagged a sign-in as suspicious, warned of a government-backed attack, or disabled an account as hijacked or leaked." } mail-forwarded-out = { match = "protoPayload.metadata.event.eventName=\"email_forwarding_out_of_domain\"" skip_expected = false doc = "A user turned on forwarding of their mail to an address outside the domain." } } detections = { for k, d in local.matches : k => { filter = "(${d.match})${d.skip_expected ? local.not_expected : ""}" doc = d.doc } } workspace_logs = "logName=(\"organizations/${var.org_id}/logs/cloudaudit.googleapis.com%2Factivity\" OR \"organizations/${var.org_id}/logs/cloudaudit.googleapis.com%2Fdata_access\") AND protoPayload.serviceName=(\"admin.googleapis.com\" OR \"login.googleapis.com\" OR \"cloudidentity.googleapis.com\" OR \"oauth2.googleapis.com\")" } resource "google_logging_project_bucket_config" "workspace" { project = var.security_project location = "global" bucket_id = "workspace-signals" retention_days = var.retention_days locked = false description = "Every Google Workspace Admin, Login, Groups, and OAuth audit entry for the organisation." } # Workspace entries belong to the organisation itself, so the sink does not # need its children's logs. resource "google_logging_organization_sink" "workspace" { org_id = var.org_id name = "workspace-signals" destination = "logging.googleapis.com/${google_logging_project_bucket_config.workspace.id}" filter = local.workspace_logs include_children = false } resource "google_project_iam_member" "sink_writes" { project = var.security_project role = "roles/logging.bucketWriter" member = google_logging_organization_sink.workspace.writer_identity } resource "google_monitoring_notification_channel" "email" { for_each = toset(var.alert_emails) project = var.security_project display_name = "Workspace signals: ${each.value}" type = "email" user_labels = local.labels labels = { email_address = each.value } }