Installation
copilot plugin marketplace add samueltauil/skills-hub
copilot plugin install iam-helper-for-policy-management@skills-hub
Works with GitHub Copilot CLI and VS Code (enable chat.plugins.enabled).
Plugin iam-helper-for-policy-management v1.0.0 follows the Agent Plugins spec.
gh skills-hub install iam-helper-for-policy-management Don't have the extension? Run gh extension install samueltauil/skills-hub first.
Download and extract to your repository:
.github/skills/iam-helper-for-policy-management/ Extract the ZIP to .github/skills/ in your repo. The folder name must match iam-helper-for-policy-management for Copilot to auto-discover it.
Skill Files (4)
SKILL.md 5.5 KB
---
name: iam-helper-for-policy-management
description: >-
Streamlines the creation, modification, and management of IAM allow policies
(v1) and deny policies (v2). Manages access control across Resource Manager
resources (Organization, Folder, Project) and individual resources. Use when
creating, updating, listing, or deleting IAM allow policies or deny policies.
Don't use for access denial troubleshooting (use
iam-helper-for-troubleshooting), temporary privileged access (use
iam-helper-for-privileged-access-management), configuring VPC Service
Controls, or managing network firewall rules.
metadata:
version: "1.0.1"
category: Security
---
# IAM Helper for Policy Management
Orchestrates the lifecycle and management of IAM allow and deny policies across
IAM v1 (allow policies) and IAM v2 (deny policies).
## Usage Attribution
**MUST READ**: Before executing any `gcloud`, REST API, or MCP command, you
MUST read and follow the instructions in
[Usage Attribution](references/attribution.md).
--------------------------------------------------------------------------------
## Core Concepts & Paradigms
IAM operates across two policy paradigms:
1. **IAM v1 (Allow Policies)**: Grants roles to principals (users, service
accounts, groups, domains) on specific resources. Supports Resource Manager
resources (organizations, folders, projects) as well as individual resources
across supported Google Cloud services.
2. **IAM v2 (Deny Policies)**: Sets explicit organization-, folder-, or
project-level guardrails that prevent specified principals from using
designated permissions, regardless of any allow policies granted. Evaluated
before allow policies.
--------------------------------------------------------------------------------
## Workflow & Decision Tree
When receiving a policy management request, determine whether the operation is
**Read-Only** or **Mutating**, and whether it targets **IAM v1 (Allow
Policies)** or **IAM v2 (Deny Policies)**:
### 1. Read-Only Operations (Autonomous Execution)
Read-only actions include the following:
- **IAM v1 Allow Policies**: `get-iam-policy` on project/folder/organization,
or `gcloud iam list-testable-permissions
//cloudresourcemanager.googleapis.com/projects/PROJECT_ID`.
- **IAM v2 Deny Policies**: `gcloud iam policies list` or `gcloud iam policies
get` with `--attachment-point` and `--kind=denypolicies`.
For read-only actions, execute the command autonomously to inspect state, and
present the query results clearly to the user.
### 2. Mutating Operations (Plan & Confirm Protocol)
Mutating operations include the following:
- **IAM v1 Allow Policies**: `add-iam-policy-binding`,
`remove-iam-policy-binding`, or `set-iam-policy` across project, folder,
organization, or resource levels (see
[references/v1-allow-policies.md](references/v1-allow-policies.md)).
- **IAM v2 Deny Policies**: `create`, `update`, or `delete` deny policies on
attachment points
(`cloudresourcemanager.googleapis.com/projects/PROJECT_ID`,
`cloudresourcemanager.googleapis.com/folders/FOLDER_ID`, or
`cloudresourcemanager.googleapis.com/organizations/ORG_ID`) using YAML/JSON
policy files (see
[references/v2-deny-policies.md](references/v2-deny-policies.md)).
For mutating operations, follow the **Plan & Confirm Protocol** below. **DO
NOT** execute mutating commands autonomously without prior user approval.
--------------------------------------------------------------------------------
## Execution & Safety Protocol
- **Plan and Confirm (No Autonomous Mutation)**: Mutating allow and deny
policy changes modify live security perimeters and access controls. You MUST
NOT execute mutating `gcloud` commands directly via tool calls without
explicit prior confirmation from the user. When asked to apply a mutating
change, do the following:
1. **Formulate the Command**: Generate the exact, fully constructed
`gcloud` command (including all parameters such as `--member`, `--role`,
`--attachment-point`, `--kind=denypolicies`, and `--policy-file`).
2. **Warn of Impact & Propagation**: Issue a general warning that the
change could impact access in a live environment and takes time to
propagate across Google Cloud global infrastructure.
3. **Request User Confirmation**: Prompt the user for approval before
applying the changes to the live environment.
- **Post-Execution Verification**: After the user approves and the mutating
policy change is executed, run the corresponding verification command (see
[references/v1-allow-policies.md](references/v1-allow-policies.md) and
[references/v2-deny-policies.md](references/v2-deny-policies.md) for exact
verification steps) to verify that the active state matches expectations
before reporting completion.
- **Security Guardrail (Public & Blanket Access Refusal)**: Never grant
`allUsers` or `allAuthenticatedUsers` basic roles (`roles/owner`,
`roles/editor`, `roles/viewer`, `roles/admin`, `roles/writer`, and
`roles/reader`) or broad permissions. Explicitly refuse blanket public
access requests, explain the severe security risks of public project
ownership/access, and propose scoped, least-privileged role bindings for
specific authenticated identities instead.
--------------------------------------------------------------------------------
## Supporting Links
- [IAM Overview](https://cloud.google.com/iam/docs/overview)
- [IAM Deny Policies](https://cloud.google.com/iam/docs/deny-overview)
attribution.md 1.9 KB
# Usage Attribution
**MUST READ**: Before executing any `gcloud`, REST API, or MCP command with
this skill, follow these usage attribution instructions. Tag every command you
execute directly in the terminal so usage can be attributed. The tag identifies
only the skill and its version; it carries no user data.
- **`gcloud` CLI Commands**: Prefix every `gcloud` invocation, whatever the
subcommand, with the metrics environment variable. Set it inline on each
command because shell state may not persist between commands:
```bash
CLOUDSDK_METRICS_REQUEST_ATTRIBUTION="agent-skills/1.0 (skill:iam-helper-for-policy-management)" \
gcloud <command> [flags]
```
Do not use `gcloud config set` for this: it would persist beyond the current
task and mislabel unrelated usage.
- **Direct HTTP, REST, and MCP Requests**: On direct HTTP calls to Google
Cloud APIs (for example with `curl`) or HTTP requests to a remote MCP
server, include
`agent-skills/1.0 (skill:iam-helper-for-policy-management)`
in the `User-Agent` header. If a `User-Agent` header is already specified,
append this string to the end of it rather than overwriting existing
`User-Agent` data — the collection pipeline parses the
`agent-skills/<version>` and `skill:<name>` tokens, so any rewording breaks
attribution:
```
User-Agent: <existing_user_agent> agent-skills/1.0 (skill:iam-helper-for-policy-management)
```
- **Constraint for Generated Code**: The tracking prefix is strictly for
commands you execute directly in the terminal. Do NOT include this tracking
prefix in generated scripts, Terraform templates, or code provided to the
user for their own repositories.
- **User Opt-Out**: If the user asks to disable or remove tracking or
attribution tags, omit the `CLOUDSDK_METRICS_REQUEST_ATTRIBUTION` variable
and custom `User-Agent` suffix from all commands.
v1-allow-policies.md 6.1 KB
# IAM v1 Allow Policies
This reference guide details how to manage IAM v1 allow policies across Resource
Manager hierarchy levels (Organization, Folder, Project) and individual
resources using `gcloud` CLI.
--------------------------------------------------------------------------------
## Table of Contents
- [1. Overview](#1-overview)
- [2. Managing Allow Policies via gcloud CLI](#2-managing-allow-policies-via-gcloud-cli)
- [3. Verification Plan](#3-verification-plan)
--------------------------------------------------------------------------------
## 1. Overview
IAM v1 allow policies define who (principals) has what access (roles) on which
Google Cloud resources.
### Principals (Who Is Granted Access)
The following are examples of principal types that are supported in allow
policies (see
[Principal Identifiers Overview](https://docs.cloud.google.com/iam/docs/principals-overview)
for a comprehensive list):
* **Users**: Google accounts (e.g., `user:alice@example.com`).
* **Service Accounts**: Application identities (e.g.,
`serviceAccount:my-sa@PROJECT_ID.iam.gserviceaccount.com`).
* **Google Groups**: Groups of users (e.g.,
`group:security-team@example.com`).
* **Domains**: Google Workspace or Cloud Identity domains (e.g.,
`domain:example.com`).
* **Special Identifiers**: `allUsers` (public) and `allAuthenticatedUsers`
(authenticated Google accounts).
### Resources (Where Policies Apply)
* **Resource Manager Resources**: Applies at the organization, folder, and
project resource levels. Permissions inherit down the resource hierarchy.
* **Service-specific Resources**: Applies to individual resources across
supported services. These allow policies complement policies inherited from
ancestor resources (projects, folders, and organizations).
### Roles (What Is Granted)
* **Predefined Roles**: Managed by Google Cloud, providing curated collections
of permissions for common use cases.
* **Custom Roles**: User-defined collections of granular permissions tailored
to specific least-privilege requirements.
--------------------------------------------------------------------------------
## 2. Managing Allow Policies via gcloud CLI
### A. Resource Manager Resources
#### 1. Project Level
```bash
# Add Policy Binding
gcloud projects add-iam-policy-binding PROJECT_ID \
--member="user:alice@example.com" \
--role="roles/viewer"
# Remove Policy Binding
gcloud projects remove-iam-policy-binding PROJECT_ID \
--member="user:alice@example.com" \
--role="roles/viewer"
# Set Policy (bulk replacement)
gcloud projects set-iam-policy PROJECT_ID policy.json
# Get Policy
gcloud projects get-iam-policy PROJECT_ID --format=json
# List Testable Permissions for Resource
gcloud iam list-testable-permissions //cloudresourcemanager.googleapis.com/projects/PROJECT_ID
```
#### 2. Folder Level
```bash
# Add Policy Binding
gcloud resource-manager folders add-iam-policy-binding FOLDER_ID \
--member="serviceAccount:my-sa@PROJECT_ID.iam.gserviceaccount.com" \
--role="roles/resourcemanager.folderViewer"
# Set Policy (bulk replacement)
gcloud resource-manager folders set-iam-policy FOLDER_ID policy.json
# Get Policy
gcloud resource-manager folders get-iam-policy FOLDER_ID --format=yaml
# Remove Policy Binding
gcloud resource-manager folders remove-iam-policy-binding FOLDER_ID \
--member="serviceAccount:my-sa@PROJECT_ID.iam.gserviceaccount.com" \
--role="roles/resourcemanager.folderViewer"
```
#### 3. Organization Level
```bash
# Add Policy Binding
gcloud organizations add-iam-policy-binding ORG_ID \
--member="group:security-team@example.com" \
--role="roles/iam.securityReviewer"
# Set Policy (bulk replacement)
gcloud organizations set-iam-policy ORG_ID policy.json
# Get Policy
gcloud organizations get-iam-policy ORG_ID --format=json
# Remove Policy Binding
gcloud organizations remove-iam-policy-binding ORG_ID \
--member="group:security-team@example.com" \
--role="roles/iam.securityReviewer"
```
--------------------------------------------------------------------------------
### B. Service-specific Resources
For services supporting allow policies for service-specific resources, the
command structure follows a consistent pattern across Google Cloud services:
```bash
# Add role binding for a service-specific resource
gcloud <service> <resource-type> add-iam-policy-binding <RESOURCE_ID> \
--member="<MEMBER>" \
--role="<ROLE>"
# Get allow policy for a service-specific resource
gcloud <service> <resource-type> get-iam-policy <RESOURCE_ID>
# Set allow policy for a service-specific resource
gcloud <service> <resource-type> set-iam-policy <RESOURCE_ID> policy.json
# Remove role binding for a service-specific resource
gcloud <service> <resource-type> remove-iam-policy-binding <RESOURCE_ID> \
--member="<MEMBER>" \
--role="<ROLE>"
```
--------------------------------------------------------------------------------
## 3. Verification Plan
Depending on which mutating allow policy operation was executed
(`add-iam-policy-binding`, `remove-iam-policy-binding`, or `set-iam-policy`),
run **only** its corresponding verification step before reporting completion:
1. **After `add-iam-policy-binding`**:
* **Action**: Run `get-iam-policy` on the target resource (project,
folder, organization, or resource).
* **Verification**: Ensure the target principal is listed under the
assigned role in the policy bindings.
2. **After `remove-iam-policy-binding`**:
* **Action**: Run `get-iam-policy` on the target resource.
* **Verification**: Ensure the target principal is no longer listed under
the role in the policy bindings (or that the binding is removed if no
other members remain).
3. **After `set-iam-policy`**:
* **Action**: Run `get-iam-policy` on the target resource.
* **Verification**: Verify that the returned policy matches the full
intended policy state defined in the applied policy file.
After verifying the mutating change, remind the user that IAM allow policy
changes take up to 7 minutes or longer to propagate across Google Cloud global
infrastructure.
v2-deny-policies.md 7.6 KB
# IAM v2 Deny Policies
This reference guide details how to create, update, list, inspect, and delete
IAM v2 deny policies across Resource Manager attachment points (Organization,
Folder, Project) using the `gcloud` CLI.
--------------------------------------------------------------------------------
## Table of Contents
- [1. IAM v2 Overview & Mechanics](#1-iam-v2-overview-mechanics)
- [2. Deny Rule Structure & Specifications](#2-deny-rule-structure-specifications)
- [3. Deny Policy Commands via gcloud CLI](#3-deny-policy-commands-via-gcloud-cli)
- [4. Long-Running Operations (LRO) & Polling](#4-long-running-operations-lro-polling)
- [5. Verification Plan](#5-verification-plan)
--------------------------------------------------------------------------------
## 1. IAM v2 Overview & Mechanics
IAM deny policies define guardrails that prevent designated principals from
using specified permissions, regardless of any roles granted by IAM allow
policies.
* **Precedence**: Deny rules are evaluated **before** allow rules. If a
permission is denied by a v2 policy, access is blocked even if an allow
policy grants the role.
* **Attachment Points**:
* **Organization**:
`cloudresourcemanager.googleapis.com/organizations/ORG_ID` (numeric ID)
* **Folder**: `cloudresourcemanager.googleapis.com/folders/FOLDER_ID`
(numeric ID)
* **Project**: `cloudresourcemanager.googleapis.com/projects/PROJECT_ID`
* **Required Permissions**: `roles/iam.denyAdmin` (Deny Admin) on the target
attachment point.
--------------------------------------------------------------------------------
## 2. Deny Rule Structure & Specifications
A deny policy contains rules specifying denied principals, exception principals,
denied permissions, and optional CEL conditions.
### Deny Policy File Specification (YAML)
```yaml
displayName: Block Public Deletion
rules:
- denyRule:
deniedPrincipals:
- "principalSet://goog/public:all"
exceptionPrincipals:
- "principal://goog/subject/admin@example.com"
deniedPermissions:
- "iam.googleapis.com/roles.delete"
- "resourcemanager.projects.delete"
denialCondition:
title: "Block_Public_Access"
expression: "request.time < timestamp('2030-01-01T00:00:00Z')"
```
#### Principal Identifiers in v2
* `principalSet://goog/public:all` (All users on the internet)
* `principal://goog/subject/USER_EMAIL` (Specific user)
* `principalSet://iam.googleapis.com/projects/PROJECT_NUMBER/serviceaccounts/SA_EMAIL`
(Specific service account)
* `principalSet://goog/group/GROUP_EMAIL` (Google Group)
#### Permission Identifiers in v2
v2 denied permissions take the format `SERVICE.googleapis.com/PERMISSION_NAME`,
for example:
* `iam.googleapis.com/roles.delete`
* `resourcemanager.projects.delete`
* `storage.googleapis.com/buckets.delete`
--------------------------------------------------------------------------------
## 3. Deny Policy Commands via gcloud CLI
### A. Create Deny Policy
```bash
# Project Level
gcloud iam policies create POLICY_NAME \
--attachment-point="cloudresourcemanager.googleapis.com/projects/PROJECT_ID" \
--kind=denypolicies \
--policy-file=deny_policy.yaml
# Folder Level
gcloud iam policies create POLICY_NAME \
--attachment-point="cloudresourcemanager.googleapis.com/folders/FOLDER_ID" \
--kind=denypolicies \
--policy-file=deny_policy.yaml
# Organization Level
gcloud iam policies create POLICY_NAME \
--attachment-point="cloudresourcemanager.googleapis.com/organizations/ORG_ID" \
--kind=denypolicies \
--policy-file=deny_policy.yaml
```
### B. Update Deny Policy
```bash
# Project Level
gcloud iam policies update POLICY_NAME \
--attachment-point="cloudresourcemanager.googleapis.com/projects/PROJECT_ID" \
--kind=denypolicies \
--policy-file=updated_deny_policy.yaml
# Folder Level
gcloud iam policies update POLICY_NAME \
--attachment-point="cloudresourcemanager.googleapis.com/folders/FOLDER_ID" \
--kind=denypolicies \
--policy-file=updated_deny_policy.yaml
# Organization Level
gcloud iam policies update POLICY_NAME \
--attachment-point="cloudresourcemanager.googleapis.com/organizations/ORG_ID" \
--kind=denypolicies \
--policy-file=updated_deny_policy.yaml
```
### C. List & Get Deny Policies
```bash
# List Deny Policies
# Project Level
gcloud iam policies list \
--attachment-point="cloudresourcemanager.googleapis.com/projects/PROJECT_ID" \
--kind=denypolicies
# Folder Level
gcloud iam policies list \
--attachment-point="cloudresourcemanager.googleapis.com/folders/FOLDER_ID" \
--kind=denypolicies
# Organization Level
gcloud iam policies list \
--attachment-point="cloudresourcemanager.googleapis.com/organizations/ORG_ID" \
--kind=denypolicies
# Get Deny Policy Details
# Project Level
gcloud iam policies get POLICY_NAME \
--attachment-point="cloudresourcemanager.googleapis.com/projects/PROJECT_ID" \
--kind=denypolicies
# Folder Level
gcloud iam policies get POLICY_NAME \
--attachment-point="cloudresourcemanager.googleapis.com/folders/FOLDER_ID" \
--kind=denypolicies
# Organization Level
gcloud iam policies get POLICY_NAME \
--attachment-point="cloudresourcemanager.googleapis.com/organizations/ORG_ID" \
--kind=denypolicies
```
### D. Delete Deny Policy
```bash
# Project Level
gcloud iam policies delete POLICY_NAME \
--attachment-point="cloudresourcemanager.googleapis.com/projects/PROJECT_ID" \
--kind=denypolicies
# Folder Level
gcloud iam policies delete POLICY_NAME \
--attachment-point="cloudresourcemanager.googleapis.com/folders/FOLDER_ID" \
--kind=denypolicies
# Organization Level
gcloud iam policies delete POLICY_NAME \
--attachment-point="cloudresourcemanager.googleapis.com/organizations/ORG_ID" \
--kind=denypolicies
```
--------------------------------------------------------------------------------
## 4. Long-Running Operations (LRO) & Polling
Mutating deny policy commands (`create`, `update`, `delete`) execute
asynchronously as Long-Running Operations.
1. **Automatic Wait**: `gcloud` CLI automatically polls and waits for
operations to complete before returning.
2. **Manual LRO Inspection**: To check the status of an operation explicitly,
run the following command:
```bash
gcloud iam operations describe OPERATION_ID
```
Check that the returned status has `done: true` and contains no error
payload.
--------------------------------------------------------------------------------
## 5. Verification Plan
Depending on which mutating deny policy operation was executed (`create`,
`update`, or `delete`), run **only** its corresponding verification step to
confirm the change:
1. **After `create`**:
* **Action**: Run `gcloud iam policies get POLICY_NAME
--attachment-point="<ATTACHMENT_POINT>" --kind=denypolicies`.
* **Verification**: Ensure the deny policy is returned with the specified
rules and principal/permission bindings.
2. **After `update`**:
* **Action**: Run `gcloud iam policies get POLICY_NAME
--attachment-point="<ATTACHMENT_POINT>" --kind=denypolicies`.
* **Verification**: Verify that the rules and metadata reflect the updated
configuration.
3. **After `delete`**:
* **Action**: Run `gcloud iam policies list
--attachment-point="<ATTACHMENT_POINT>" --kind=denypolicies`.
* **Verification**: Ensure the deleted policy name is no longer listed
under the attachment point.
After verifying the mutating change, remind the user that IAM deny policy
changes take up to 7 minutes or longer to propagate across Google Cloud global
infrastructure.
License (Apache-2.0)
View full license text
Licensed under the Apache License, Version 2.0. See https://github.com/google/skills/blob/main/LICENSE