Agent Skillsgoogle/skills › iam-helper-for-policy-simulator

iam-helper-for-policy-simulator

GitHub

辅助安全修改 Google Cloud IAM v1 允许策略。通过 Policy Simulator 重放历史访问日志,验证拟议变更是否会影响现有工作负载,确保安全应用策略更改。

skills/cloud/iam-helper-for-policy-simulator/SKILL.md google/skills

Trigger Scenarios

模拟或应用 Google Cloud IAM v1 允许策略 在更改前检查 IAM 策略变更对现有工作负载的影响

Install

npx skills add google/skills --skill iam-helper-for-policy-simulator -g -y
More Options

Non-standard path

npx skills add https://github.com/google/skills/tree/main/skills/cloud/iam-helper-for-policy-simulator -g -y

Use without installing

npx skills use google/skills@iam-helper-for-policy-simulator

指定 Agent (Claude Code)

npx skills add google/skills --skill iam-helper-for-policy-simulator -a claude-code -g -y

安装 repo 全部 skill

npx skills add google/skills --all -g -y

预览 repo 内 skill

npx skills add google/skills --list

SKILL.md

Frontmatter
{
    "name": "iam-helper-for-policy-simulator",
    "metadata": {
        "category": "Security"
    },
    "description": "Safely simulates and applies Google Cloud IAM v1 (Allow) policy changes. Uses the Policy Simulator to replay historical access logs against proposed policies to prevent breaking active workloads before applying the changes. Use when simulating or applying IAM v1 allow policies across Projects, Folders, or Organizations. Don't use for analyzing IAM v2 deny policies, VPC Service Controls, or performing general policy troubleshooting."
}

IAM Policy Simulator (v1 Allow)

You are an advanced security assistant helping users safely modify Google Cloud IAM policies. You must NEVER apply a modifying policy change without first running a Policy Simulation to ensure existing workloads are not disrupted. You must only use standard public gcloud commands.

Core Concepts & Prerequisites

  • IAM v1 (Allow Policies): Specifies who has access (a role) to a resource.
  • Policy Simulator: Replays the last 90 days of access logs against a proposed policy to verify if any historical access would be blocked by the change.
  • Required Permissions: The execution environment must have roles/policysimulator.admin, roles/cloudasset.viewer, and the appropriate IAM Admin roles for the target resource.
  • Resource Scope: Changes can target Projects, Folders, or Organizations.

Execution Workflow: Plan, Simulate, Analyze, Apply

Step 1: Retrieve Current Policy (Plan)

Fetch the baseline IAM v1 policy for the target resource (Project, Folder, or Organization) and save it to the /tmp/ directory:

For Projects:

gcloud projects get-iam-policy TARGET_PROJECT_ID --format=json > /tmp/current_policy.json

For Folders:

gcloud resource-manager folders get-iam-policy TARGET_FOLDER_ID --format=json > /tmp/current_policy.json

For Organizations:

gcloud organizations get-iam-policy TARGET_ORG_ID --format=json > /tmp/current_policy.json

CRUCIAL SAFETY GATE: Verify that the policy was successfully retrieved. If the command fails or the resulting JSON is empty, you MUST terminate the workflow immediately and inform the user. Do not proceed to prepare or simulate an empty or partial policy.

Step 2: Prepare Proposed Policy

Create a /tmp/proposed_policy.json file. Modify /tmp/current_policy.json by adding or removing role bindings in the bindings array to match the requested change.

CRUCIAL NO-OP CHECK: Compare the proposed policy to the current policy. If no changes were actually made (e.g., you are trying to remove a role the user doesn't hold, or add a role they already have), you MUST inform the user that no changes are necessary and terminate the workflow immediately. Do not run a simulation.

Step 3: Run Policy Simulation

Run the simulator to replay the last 90 days of access logs against the proposed policy change. Execute the exact command for your resource type:

For Projects:

gcloud iam simulator replay-recent-access //cloudresourcemanager.googleapis.com/projects/TARGET_PROJECT_ID /tmp/proposed_policy.json --project=TARGET_PROJECT_ID --format=json > /tmp/simulation_results.json

For Folders:

gcloud iam simulator replay-recent-access //cloudresourcemanager.googleapis.com/folders/TARGET_FOLDER_ID /tmp/proposed_policy.json --format=json > /tmp/simulation_results.json

For Organizations:

gcloud iam simulator replay-recent-access //cloudresourcemanager.googleapis.com/organizations/TARGET_ORG_ID /tmp/proposed_policy.json --format=json > /tmp/simulation_results.json

(Note: If the Policy Simulator API is not enabled, it will prompt you to enable it. Select Yes. Do not use placeholders verbatim; replace TARGET_PROJECT_ID, TARGET_FOLDER_ID, or TARGET_ORG_ID with the actual resource ID).

CRUCIAL SAFETY GATE: Verify the command exited successfully. If the simulator command crashes, times out, or returns a non-zero exit code, you MUST NOT treat the failure as a "safe" result. Terminate the workflow immediately and report the simulator failure to the user.

Step 4: Analyze Simulation Results

Analyze the contents of /tmp/simulation_results.json using the provided helper script. Do not write custom scripts on the fly. You MUST execute the following command:

python3 scripts/analyze_simulation.py
  • SAFE (No Breakage): If the script outputs REVOKED_COUNT=0, the change is safe.
  • UNSAFE (Breakage): If the script outputs REVOKED_COUNT > 0 (meaning the logs contain ACCESS_REVOKED or ACCESS_MAYBE_REVOKED):
    • Identify the principal, permission, and fullResourceName from the printed JSON.
    • Do NOT apply the policy.
    • The change will break an active workload. Inform the user of the specific disrupted accesses.

Step 5: Apply Policy (Only if Safe)

If and only if the simulation in Step 4 was SAFE (No Breakage), prompt the user: "The simulation showed no disrupted access. Do you want to apply this policy change? (Yes/No)".

  • If Yes: Apply the policy using the correct command for the resource type:

For Projects:

gcloud projects set-iam-policy TARGET_PROJECT_ID /tmp/proposed_policy.json

For Folders:

gcloud resource-manager folders set-iam-policy TARGET_FOLDER_ID /tmp/proposed_policy.json

For Organizations:

gcloud organizations set-iam-policy TARGET_ORG_ID /tmp/proposed_policy.json
  • If No: Terminate the workflow.

Step 6: Cleanup (Always Run)

After applying the policy, declining the prompt, or terminating early due to a NO-OP/failure, always delete the temporary files to prevent cross-contamination in future runs:

rm -f /tmp/current_policy.json /tmp/proposed_policy.json /tmp/simulation_results.json

Version History

  • d08678b Current 2026-08-27 13:41

Same Skill Collection

plugins/cloud/gemini-api/skills/gemini-api/SKILL.md
plugins/cloud/gemini-api/skills/gemini-interactions-api/SKILL.md
plugins/cloud/gemini-enterprise-agent-platform/skills/agent-platform-endpoint-management/SKILL.md
plugins/cloud/gemini-enterprise-agent-platform/skills/agent-platform-migrate-from-ai-studio/SKILL.md
plugins/cloud/gemini-enterprise-agent-platform/skills/agent-platform-model-registry/SKILL.md
plugins/cloud/gemini-enterprise-agent-platform/skills/agent-platform-prompt-management/SKILL.md
plugins/cloud/gemini-enterprise-agent-platform/skills/agent-platform-rag-engine-management/SKILL.md
plugins/cloud/gemini-enterprise-agent-platform/skills/agent-platform-skill-registry/SKILL.md
plugins/cloud/gemini-enterprise-agent-platform/skills/agent-platform-troubleshooting/SKILL.md
plugins/cloud/gemini-enterprise-agent-platform/skills/agent-platform-tuning-management/SKILL.md
plugins/cloud/gemini-enterprise-agent-platform/skills/agent-platform-tuning/SKILL.md
plugins/cloud/gemini-enterprise-agent-platform/skills/gemini-agents-api/SKILL.md
plugins/cloud/google-cloud-core/skills/gcloud/SKILL.md
plugins/cloud/google-cloud-core/skills/google-cloud-recipe-auth/SKILL.md
plugins/cloud/google-cloud-core/skills/google-cloud-recipe-onboarding/SKILL.md
plugins/cloud/google-cloud-developer/skills/gcloud/SKILL.md
plugins/cloud/google-cloud-developer/skills/google-cloud-recipe-auth/SKILL.md
plugins/cloud/google-cloud-developer/skills/google-cloud-recipe-onboarding/SKILL.md
plugins/cloud/google-cloud-gke-workloads/skills/gke-ai-troubleshooting-jobset-interruption/SKILL.md
plugins/cloud/google-cloud-gke-workloads/skills/gke-ai-troubleshooting-tpu-dynamic-slices-monitoring/SKILL.md
plugins/cloud/google-cloud-gke-workloads/skills/gke-ai-troubleshooting-tpu-metrics-monitoring/SKILL.md
plugins/cloud/google-cloud-gke-workloads/skills/gke-batch-hpc/SKILL.md
plugins/cloud/google-cloud-gke-workloads/skills/gke-cluster-autoscaler/SKILL.md
plugins/cloud/google-cloud-gke-workloads/skills/gke-compute-classes/SKILL.md
plugins/cloud/google-cloud-gke-workloads/skills/gke-cost-optimization/SKILL.md
plugins/cloud/google-cloud-gke-workloads/skills/gke-inference/SKILL.md
plugins/cloud/google-cloud-gke-workloads/skills/gke-multitenancy/SKILL.md
plugins/cloud/google-cloud-gke-workloads/skills/gke-workload-scaling/SKILL.md
plugins/cloud/google-cloud-gke-workloads/skills/gke-workload-troubleshooting/SKILL.md
plugins/cloud/google-cloud-gke/skills/gke-app-onboarding/SKILL.md
plugins/cloud/google-cloud-gke/skills/gke-backup-dr/SKILL.md
plugins/cloud/google-cloud-gke/skills/gke-basics/SKILL.md
plugins/cloud/google-cloud-gke/skills/gke-cluster-creation/SKILL.md
plugins/cloud/google-cloud-gke/skills/gke-golden-path/SKILL.md
plugins/cloud/google-cloud-gke/skills/gke-networking/SKILL.md
plugins/cloud/google-cloud-gke/skills/gke-observability/SKILL.md
plugins/cloud/google-cloud-gke/skills/gke-reliability/SKILL.md
plugins/cloud/google-cloud-gke/skills/gke-service-networking/SKILL.md
plugins/cloud/google-cloud-gke/skills/gke-storage/SKILL.md
plugins/cloud/google-cloud-run/skills/cloud-run-basics/SKILL.md
plugins/cloud/google-cloud-well-architected/skills/google-cloud-waf-cost-optimization/SKILL.md
plugins/cloud/google-cloud-well-architected/skills/google-cloud-waf-operational-excellence/SKILL.md
plugins/cloud/google-cloud-well-architected/skills/google-cloud-waf-performance-optimization/SKILL.md
plugins/cloud/google-cloud-well-architected/skills/google-cloud-waf-reliability/SKILL.md
plugins/cloud/google-cloud-well-architected/skills/google-cloud-waf-security/SKILL.md
plugins/cloud/google-cloud-well-architected/skills/google-cloud-waf-sustainability/SKILL.md
skills/ads/data-manager-api-audience-ingestion/SKILL.md
skills/ads/data-manager-api-event-ingestion/SKILL.md
skills/ads/data-manager-api-setup/SKILL.md
skills/ads/data-manager-api/data-manager-api-audience-ingestion/SKILL.md

Metadata

Files
0
Version
b5ed0a2
Hash
98a3ca17
Indexed
2026-08-27 13:41

trang chủ - Wiki
Copyright © 2011-2026 iteam. Current version is 2.155.2. UTC+08:00, 2026-08-30 16:39
浙ICP备14020137号-1 $bản đồ khách truy cập$