Skip to main content

Event Information

  • What it is: resourcemanager.folders.setIamPolicy is a Google Cloud Resource Manager API call that sets (overwrites) the IAM policy on a Folder resource. It is typically triggered by commands like gcloud resource-manager folders set-iam-policy or via the REST API/Client libraries.
  • Security & impact:
    • It can add, remove, or replace roles and member bindings (including custom roles, service accounts, external identities) on the folder.
    • Because IAM is inherited, this can cascade to all projects and resources under that folder, potentially granting or revoking broad access.
  • Compliance considerations (e.g., ISO 27001, SOC 2, PCI, HIPAA):
    • Treat this event as high‑sensitivity and log/monitor it via Cloud Audit Logs + SIEM.
    • Require strong change control (approval workflow, ticket linkage) and least privilege (only Org/Folder Admins with business justification).
    • Periodically review folder IAM policies and compare changes against policy-as-code baselines (e.g., Terraform, CSPM tools) to detect unauthorized or non-compliant modifications.

Examples

  • Overly broad folder-level access (e.g., roles/owner / roles/editor to a group)
    • Impact: Users gain inherited control over all child projects/resources (compute, storage, BigQuery) enabling data exfiltration, service deletion, or privilege escalation.
    • Compliance: Violates least privilege in ISO 27001 / SOC 2; risks non-compliant access to regulated data (HIPAA, PCI DSS).
  • Granting external identities access at folder scope (e.g., user:personal@gmail.com, domain:partner.com)
    • Impact: Third parties can create/modify resources or IAM at project level, potentially exposing customer data or production systems.
    • Compliance: Breaches data residency / third-party access controls (GDPR, HIPAA BAA terms, PCI DSS 7) due to unmanaged external accounts.
  • Misconfigured service account / CI pipeline role at folder level (e.g., roles/resourcemanager.folderAdmin)
    • Impact: Compromised pipeline or service account can rewrite IAM across all projects in the folder, disable logging, or backdoor access.
    • Compliance: Undermines separation of duties and change control (ISO 27001 A.6/A.8, SOC 2 CC6, PCI DSS 7.2) and can invalidate audit trails.

Remediation

Using Console

  • Remove overly broad folder-level access (roles/owner, roles/editor, etc.)
    • In Console: Go to IAM & Admin → IAM, click Resource type filter → Folders, select the target folder → click Show inherited permissions. Identify principals (e.g., groups) with Owner, Editor, or other broad roles at folder level.
    • For each risky binding: click Edit principal (pencil icon) → remove Owner / Editor / other broad role → Save. Then re-add only required granular roles at project or resource level (e.g., roles/storage.objectViewer, roles/bigquery.dataViewer) based on job function.
    • Validate: Use IAM → Policy Analyzer (if available) or export IAM policies (Security → IAM Recommender / Policy Troubleshooter) to confirm that inherited broad roles are removed. Document the change for ISO 27001 / SOC 2 access review, and ensure any regulated projects (HIPAA/PCI) now only use least‑privilege roles.
  • Restrict external identities at folder scope
    • In Console: IAM & Admin → IAM, filter to the folder as above. In the principals list, search for @gmail.com, @yahoo.com, or partner domains (e.g., @partner.com, or type domain:partner.com into the filter).
    • For each external identity found at folder level: click Edit principal → remove folder‑level roles → Save. Re‑grant access, if strictly needed, at the specific project or lower resource scope with minimal roles, ideally via Cloud Identity / managed accounts under your org domain and, for vendors, using Cloud Identity federation with conditional access.
    • Validate and document: Confirm no personal accounts or unmanaged domains retain folder‑ or org‑level access. Capture screenshots / export IAM policy for GDPR, HIPAA, PCI DSS 7 evidence (third‑party access, data residency).
  • Tighten service account / CI pipeline roles at folder level
    • Identify high‑risk roles: In IAM & Admin → IAM at folder scope, filter Principal type → Service accounts and look for roles like roles/resourcemanager.folderAdmin, roles/owner, roles/editor, or other powerful IAM / org roles.
    • For each CI/service account: click Edit principal → remove folder‑level admin roles → Save. Then:
      • Move permissions to the specific projects the pipeline needs.
      • Replace powerful roles with custom or predefined least‑privilege roles (e.g., roles/deploymentmanager.editor, roles/storage.admin on specific buckets).
      • If a folder‑level role is truly required, use a narrowly scoped custom role without IAM‑write or logging‑disable permissions.
    • Governance: Enable and verify Cloud Audit Logs for Admin Activity and Data Access on the folder and child projects; ensure that pipeline changes go through Change Management (e.g., approvals in Cloud Build / GitHub Actions). Record this in your ISO 27001 / SOC 2 change and SoD documentation.

Using CLI

  • Tighten folder-level IAM to least privilege
    • List current bindings and identify broad roles / external principals:
      • gcloud alpha resource-manager folders get-iam-policy FOLDER_ID --format=json > folder-iam.json
    • Remove roles/owner, roles/editor, and overly broad roles from groups and users; replace with least-privilege custom / predefined roles at folder or project scope:
      • gcloud alpha resource-manager folders remove-iam-policy-binding FOLDER_ID --member="group:example-group@org.com" --role="roles/editor"
      • gcloud projects add-iam-policy-binding PROJECT_ID --member="group:example-group@org.com" --role="roles/compute.viewer"
    • For ISO 27001 / SOC 2 / PCI DSS alignment, document role design and access reviews (e.g., quarterly) and enforce org policies to block legacy roles:
      • gcloud org-policies set-policy org-policy-least-privilege.yaml --organization=ORG_ID
  • Restrict external identities and third-party access at folder scope
    • Enumerate and remove external members (personal Gmail, partner domains) at folder level; re-grant via managed groups or workload identity federation at project level only:
      • gcloud alpha resource-manager folders get-iam-policy FOLDER_ID --flatten="bindings[].members" --filter="bindings.members:(user: OR domain:)" --format="table(bindings.role, bindings.members)"
      • gcloud alpha resource-manager folders remove-iam-policy-binding FOLDER_ID --member="user:personal@gmail.com" --role="roles/viewer"
    • Enforce domain restriction + external account controls (GDPR / HIPAA / PCI DSS 7) using org policies:
      • gcloud org-policies set-policy domain_restriction.yaml --organization=ORG_ID
    • For partners, use dedicated projects + VPC-SC / per-project IAM, not folder-scope; ensure DPAs/BAAs cover access and log all access via Cloud Audit Logs + CMEK.
  • Constrain service accounts / CI roles and monitor IAM changes
    • Remove high-impact roles (e.g., roles/owner, roles/editor, roles/resourcemanager.folderAdmin) from service accounts/CI at folder scope; assign minimal, task-specific roles at project scope:
      • gcloud alpha resource-manager folders remove-iam-policy-binding FOLDER_ID --member="serviceAccount:ci-sa@PROJECT_ID.iam.gserviceaccount.com" --role="roles/resourcemanager.folderAdmin"
      • gcloud projects add-iam-policy-binding PROJECT_ID --member="serviceAccount:ci-sa@PROJECT_ID.iam.gserviceaccount.com" --role="roles/deployments.deployAgent"
    • Disable direct key usage where possible and use Workload Identity Federation; restrict IAM write permissions and logging configuration to a small break-glass admin group to maintain audit integrity (ISO 27001 A.6/A.8, SOC 2 CC6, PCI DSS 7.2).
    • Implement continuous detection for risky folder-level grants using SCC / Cloud Asset Inventory and alert on SetIamPolicy / SetOrgPolicy events: e.g.,
      • gcloud asset search-all-iam-policies --scope="folders/FOLDER_ID" --query="policy:(roles/owner OR roles/editor OR roles/resourcemanager.folderAdmin)" --format="table(resource, policy.bindings.role, policy.bindings.members)"

Using Python

  • Tighten folder-level IAM & remove broad roles (owner / editor / broad custom roles) from groups and externals
    • Discover and review bindings on the target folder (and optionally recursively) and generate a report of high‑risk principals and roles:
    • Remediate by: (1) designing least‑privilege custom roles at project level, (2) migrating groups to scoped roles (roles/viewer, per‑service roles like roles/bigquery.dataViewer), (3) then editing the folder IAM policy to remove the high‑risk bindings:
    • Map to compliance: document the role redesign and approval (change tickets), and keep the script output as evidence for ISO 27001 / SOC 2 / PCI DSS least‑privilege reviews.
  • Remove / restrict external identities at folder scope & enforce org‑level controls
    • Enumerate and flag all external members and external domain: bindings at folder level (to satisfy GDPR / HIPAA / PCI DSS 7 third‑party access controls):
    • After confirming business need and BAA/DPA/PCI agreements, either: (1) move access down to specific projects/resources, (2) replace personal accounts with managed identities in a dedicated group, or (3) remove the binding entirely via set_iam_policy (similar pattern as above, filtering is_external(member)).
    • At the org level, configure:
      • constraints/iam.allowedPolicyMemberDomains to restrict which domains can appear in IAM policies.
      • constraints/iam.disableServiceAccountKeyCreation and workload identity for partners.
        Use policy export as audit evidence that external access is controlled.
  • Constrain service accounts / CI roles at folder scope & implement SoD and logging guardrails
    • Inventory service accounts and automated principals bound at folder level with elevated roles (e.g., roles/resourcemanager.folderAdmin, roles/iam.securityAdmin), then downgrade to least‑privilege project‑level roles:
    • For each CI/service account:
      • Move permissions to per‑project custom roles aligned with pipeline stages (build/test/deploy), and use per‑env SAs (dev/stage/prod) to enforce separation of duties.
      • Remove folder‑level admin roles and replace with narrowly scoped permissions (e.g., roles/deploymentmanager.editor, roles/clouddeploy.releaseManager) only where needed.
    • Ensure compliance and auditability:
      • Require approvals (e.g., via Cloud Build/Cloud Deploy gates) for IAM‑affecting changes.
      • Enable Cloud Audit Logs for Admin Activity and Data Access on the org/folder and monitor for SetIamPolicy / SetOrganizationPolicy by CI/service accounts, feeding into SIEM with alerts for ISO 27001 A.6/A.8, SOC 2 CC6, PCI DSS 7.2 evidence.