Custom IAM role changes should raise an alert through a log-based metric
This check looks for a log-based metric that counts custom IAM role create, update and delete events, with an alerting policy attached to it. The safe setting is to have both, so a change to a custom role is noticed quickly.
Why it matters
A custom IAM role is a list of permissions you define yourself. Changing one can quietly widen what every holder of that role can do, across every place the role is granted. Google Cloud writes such changes to its audit logs, but nobody reads those logs unless something prompts them to.
Google describes log-based metrics as Cloud Monitoring metrics derived from the content of log entries; a counter metric tallies how many entries match a filter, and alerting policies can monitor the result. Pairing a counter on custom-role changes with an alert turns a silent edit into a notification. Source: Log-based metrics overview (Google Cloud documentation). Note that a metric only counts logs received after it was created.
How to check it yourself
Portal: in Logging > Log-based metrics look for a user-defined counter whose filter mentions custom role changes. Then open Monitoring > Alerting and confirm an alerting policy uses that metric.
gcloud (read-only):
gcloud logging metrics list --project <project-id> --format="table(name,filter)"Look for a filter covering the IAM admin role methods, for example google.iam.admin.v1.CreateRole, UpdateRole and DeleteRole. Then check the alerting side in the portal, since a metric nobody is alerted on does not meet the safe setting.
How to fix it
Portal: in Logging > Log-based metrics choose Create metric, type Counter, paste a filter for the role methods and save. Then create an alerting policy on logging.googleapis.com/user/<metric-name> with a notification channel your team reads.
gcloud, which changes the project, so run it yourself (ConfigCobra only reports and suggests, it never changes your environment):
gcloud logging metrics create custom-role-changes \
--project <project-id> \
--description="Counts custom IAM role create, update and delete events" \
--log-filter='resource.type="iam_role" AND (protoPayload.methodName="google.iam.admin.v1.CreateRole" OR protoPayload.methodName="google.iam.admin.v1.UpdateRole" OR protoPayload.methodName="google.iam.admin.v1.DeleteRole")'Create the alerting policy next, and set how it treats missing data, because a counter that sees no events produces gaps, which Google recommends handling explicitly.
What changes when you fix it
Nothing changes for running workloads or for people who use the roles. The only visible effect is a notification when someone edits a custom role.
- Security and platform admins receive alerts and need a routine for reviewing them.
- Teams that edit custom roles often may find the alert noisy at first; agree with them on which changes are expected.
- Monitoring owners must pick the notification channel and keep it current.
Metrics and policies live in a project, so decide which project holds them and whether a metric is needed in each project or at a broader scope. Test it by making a harmless edit to a role in a test project and confirming the alert fires.
Included in
| Benchmark | CIS ID | Profile |
|---|---|---|
| CIS Google Cloud Platform Foundation v5.0.0 | 2.7 | Level 1 |
More checks in Logging and Monitoring
- Configure Cloud Audit Logging across all services and usersCIS 2.1
- Enable Workspace/Cloud Identity data sharing for admin audit loggingCIS 2.2
- Configure sinks to export copies of all log entriesCIS 2.3
- Apply Bucket Lock retention policies to log-export storage bucketsCIS 2.4
- Alert on project-ownership assignments/changes via log metric filterCIS 2.5
Go further
- Logging and Monitoring17 controls in this section
- CIS Google Cloud Platform Foundation v5.0.093 controls
- CIS Google Cloud Platform Foundation checklistEvery control in one list, as CSV
- RemediationSee what a fix changes in your tenant before you apply it, then use the generated script
- Monitoring & DriftScheduled scans, drift detection and email alerts when a control regresses
Check this on your Google Cloud
ConfigCobra runs this check with every other control of the CIS Google Cloud Platform Foundation Benchmark, read-only.