IAM Least-Privilege Hardener
Overview
This skill turns broad Google Cloud IAM into reviewable, evidence-backed
recommendations. It inventories bindings and service-account keys, reads IAM
Recommender observations where authorized, maps actual job needs to narrower
roles, and proposes Terraform only. It never applies a policy, deletes a key,
or removes roles/owner/roles/editor automatically: these changes can
break workloads, emergency access, or organization controls.
Prerequisites
Authorized project/folder scope, principal/binding inventory, and a change
owner who can validate required permissions before removal.
Optional Application Default Credentials for live Recommender read mode;
otherwise use the script's built-in mock or a reviewed response fixture.
Treat policy exports, service-account email addresses, and recommender
evidence as confidential. Never place private keys or tokens in reports.
Workflow
Step 1: Establish scope and collect read-only evidence
List project-level and inherited bindings, service accounts, user-managed
keys (metadata only), and workload identity usage. Define a rollback owner
and observation window before proposing any change. Do not infer unused from
absence in one short log window.
Step 2: Obtain recommendation evidence
Run a safe local schema check/mock:
scripts/get_iam_recommendations.py --mock --project PROJECT_ID
For a live read, use an OAuth bearer token supplied through stdin (never an
argument or committed file):
printf '%s' "$ACCESS_TOKEN" | scripts/get_iam_recommendations.py --project PROJECT_ID --token-stdin
The script calls only the Recommender REST list endpoint and redacts token
handling from output. A SUCCEEDED recommendation is evidence to review, not
authorization to change a binding.
Step 3: Map job intent to minimum role
Read references/predefined_roles_map.md. Replace primitive roles with the
narrowest predefined role that covers the confirmed action; use a custom role
only when no predefined role fits, with explicit included permissions and an
owner/review date. Review service agents separately: do not remove roles
granted to Google-managed service accounts merely because their use is opaque.
Step 4: Prefer federation over downloadable keys
For external CI/CD, GKE, or on-premises identity, read
references/workload_identity_setup.md and design Workload Identity
Federation or GKE Workload Identity. Inventory and disable user-managed keys
only after the federated path has passed a non-production proof and a rollback
window exists. Never export, decode, or log a service-account private key.
Step 5: Produce a review-only Terraform plan
Copy the appropriate blocks from
assets/least_privilege_terraform_templates.tf, replace placeholders, and
show the old binding, proposed binding, evidence, affected workload, rollback,
and test. Do not run terraform apply or gcloud projects set-iam-policy.
Examples
Example 1: Project Editor right-sizing
For a CI service account with roles/editor, inspect its proven deployment
actions and Recommender evidence, then propose only needed deploy/artifact
roles plus scoped resource bindings. Preserve break-glass access until the
owner approves and validates a staged rollout.
Example 2: Static key hardening
For a GitHub pipeline with a downloaded key, map GitHub OIDC attributes to a
Workload Identity pool/provider and service-account impersonation binding.
Do not revoke the existing key until the new authentication is verified.
Error Handling
Recommender returns 403: report the missing read permission and use mock
mode; never ask for Owner as a diagnostic shortcut.
No recommendation returned: it is not proof the binding is safe; document
missing usage evidence and retain it pending owner review.
A narrow role breaks a staged test: restore the prior approved binding,
capture the missing permission, and revise the proposal; do not add
roles/editor back as the default fix.
A referenced role map or federation guide is unavailable: do not infer a
replacement permission set. Return the evidence as review-only and obtain
the current versioned reference before proposing a binding.
Reference Files
references/predefined_roles_map.md: role replacement map and cautions.
references/workload_identity_setup.md: federation migration sequence.
scripts/get_iam_recommendations.py: mock or read-only REST API client.
assets/least_privilege_terraform_templates.tf: review-only HCL blocks.
Output Format
Return scoped inventory; evidence; proposed role/federation change; Terraform
snippet; validation/rollback plan; and residual risks. Mark all changes
review-only until an authorized human approves them.
1---2name: gcp-iam-privilege-audit3description: Audits Google Cloud IAM bindings and service-account key exposure, interprets IAM Recommender evidence, and proposes reviewable least-privilege predefined/custom roles or Workload Identity Federation migration without changing access. TRIGGER when users ask to 'audit GCP IAM permissions', 'harden service account keys', 'implement least-privilege roles', 'configure Workload Identity', 'rightsize project-level editor bindings', or review IAM Recommender output. DO NOT TRIGGER for granting new broad production access, rotating secrets without an IAM audit objective, or AWS/Azure IAM reviews.4license: Apache-2.05---67- IAM Least-Privilege Hardener89- Overview10This skill turns broad Google Cloud IAM into reviewable, evidence-backed11recommendations. It inventories bindings and service-account keys, reads IAM12Recommender observations where authorized, maps actual job needs to narrower13roles, and proposes Terraform only. It never applies a policy, deletes a key,14or removes `roles/owner`/`roles/editor` automatically: these changes can15break workloads, emergency access, or organization controls.1617- Prerequisites18- Authorized project/folder scope, principal/binding inventory, and a change19 owner who can validate required permissions before removal.20- Optional Application Default Credentials for live Recommender read mode;21 otherwise use the script's built-in mock or a reviewed response fixture.22- Treat policy exports, service-account email addresses, and recommender23 evidence as confidential. Never place private keys or tokens in reports.2425- Workflow2627- Step 1: Establish scope and collect read-only evidence28List project-level and inherited bindings, service accounts, user-managed29keys (metadata only), and workload identity usage. Define a rollback owner30and observation window before proposing any change. Do not infer unused from31absence in one short log window.3233- Step 2: Obtain recommendation evidence34Run a safe local schema check/mock:35```36scripts/get_iam_recommendations.py --mock --project PROJECT_ID37```38For a live read, use an OAuth bearer token supplied through stdin (never an39argument or committed file):40```41printf '%s' "$ACCESS_TOKEN" | scripts/get_iam_recommendations.py --project PROJECT_ID --token-stdin42```43The script calls only the Recommender REST list endpoint and redacts token44handling from output. A `SUCCEEDED` recommendation is evidence to review, not45authorization to change a binding.4647- Step 3: Map job intent to minimum role48Read `references/predefined_roles_map.md`. Replace primitive roles with the49narrowest predefined role that covers the confirmed action; use a custom role50only when no predefined role fits, with explicit included permissions and an51owner/review date. Review service agents separately: do not remove roles52granted to Google-managed service accounts merely because their use is opaque.5354- Step 4: Prefer federation over downloadable keys55For external CI/CD, GKE, or on-premises identity, read56`references/workload_identity_setup.md` and design Workload Identity57Federation or GKE Workload Identity. Inventory and disable user-managed keys58only after the federated path has passed a non-production proof and a rollback59window exists. Never export, decode, or log a service-account private key.6061- Step 5: Produce a review-only Terraform plan62Copy the appropriate blocks from63`assets/least_privilege_terraform_templates.tf`, replace placeholders, and64show the old binding, proposed binding, evidence, affected workload, rollback,65and test. Do not run `terraform apply` or `gcloud projects set-iam-policy`.6667- Examples6869- Example 1: Project Editor right-sizing70For a CI service account with `roles/editor`, inspect its proven deployment71actions and Recommender evidence, then propose only needed deploy/artifact72roles plus scoped resource bindings. Preserve break-glass access until the73owner approves and validates a staged rollout.7475- Example 2: Static key hardening76For a GitHub pipeline with a downloaded key, map GitHub OIDC attributes to a77Workload Identity pool/provider and service-account impersonation binding.78Do not revoke the existing key until the new authentication is verified.7980- Error Handling81- Recommender returns `403`: report the missing read permission and use mock82 mode; never ask for `Owner` as a diagnostic shortcut.83- No recommendation returned: it is not proof the binding is safe; document84 missing usage evidence and retain it pending owner review.85- A narrow role breaks a staged test: restore the prior approved binding,86 capture the missing permission, and revise the proposal; do not add87 `roles/editor` back as the default fix.88- A referenced role map or federation guide is unavailable: do not infer a89 replacement permission set. Return the evidence as review-only and obtain90 the current versioned reference before proposing a binding.9192- Reference Files93- **references/predefined_roles_map.md**: role replacement map and cautions.94- **references/workload_identity_setup.md**: federation migration sequence.95- **scripts/get_iam_recommendations.py**: mock or read-only REST API client.96- **assets/least_privilege_terraform_templates.tf**: review-only HCL blocks.9798- Output Format99Return scoped inventory; evidence; proposed role/federation change; Terraform100snippet; validation/rollback plan; and residual risks. Mark all changes101review-only until an authorized human approves them.