agentleFS
mohitkalemohitkale/gcp-devkit/skills/iam-audit/SKILL.md

iam-audit

Skill0 starsChanged 4 months agoMITView on GitHub

Audit IAM bindings on a GCP project for overly broad roles and stale service account keys. Use when the user asks to review IAM on a project, find who has owner or editor, find unused service account keys, or assess the least-privilege posture of a GCP project before a security review.

2 other projects use a version of this.

Adopted by

Most recently taken up by

  • Other versions2 projects use a version of this.

    Word for word · 0

    None found.

    Edited · 0

    None found.

    Wrote their own version · 2

    1. briiirussell/cybersecurity-skills★ 410same name
    2. imMamdouhaboammar/cybersecurity-skills★ 1same name

    How matches are found. Word for word: the exact same text. Edited: shares passages with this file (“99% same” means 99% of its five-word phrases also appear here; 10% or more counts). Their own version: similar meaning, or, weakest, the same name. We can’t tell which project had it first. Projects are counted among the 200 most-starred candidates, and mentions are links to the repository we found, up to 50 per site, so both counts are a floor.

  • In this repository5 other files it gives its agents.

The file

We split this skill into the rules it gives an agent

11 rules. About 0 are common, 7 are distinctive, and 4 are very specific to this project.

  • ≈0

    Common · estimate

    Many files like this have a rule of this kind.

  • ≈7

    Distinctive · estimate

    This author's own choices. Worth a look.

  • 4

    Very specific

    Tied to their project's names, files or tools. Probably skip.

  • Common
  • Distinctive
  • Very specific
  1. Distinctive:

    Read the command output and index bindings by role, then by member.

    line 31
  2. Distinctive:

    Default service accounts used outside of their intended scope:

    line 47
  3. Distinctive:

    Read the list of permissions.

    line 59
  4. Very specific:

    Do not list keys with --managed-by=system.

    line 84
  5. Distinctive:

    If the user has audit logs, check for service accounts that have not authenticated in the last 90 days:

    line 88
  6. Distinctive:

    Delete user-managed keys and switch to Workload Identity or Workload Identity Federation.

    line 181
  7. Very specific:

    When flagging a broad predefined role, consult reference/iam-common-roles.md in the plugin root for narrower alternatives.

    line 185
  8. Distinctive:

    Do not modify any binding yourself.

    line 189
  9. Very specific:

    Do not print the contents of any gcloud iam service-accounts keys create output or any key file the user references.

    line 190
  10. Distinctive:

    Do not flag every role as critical.

    line 191
  11. Very specific:

    Do not list keys with --managed-by=system.

    line 192

≈ “Common” is an estimate: at least 1 in 5 of the 213,895 skill files we read have a rule of the same kind, not the same words. “Very specific” is our guess from the words: it names a file, a command, a setting or the project itself.

Keep what fits and drop the rest. Your version, ready for your agents.
Files
SKILL.md

Audit GCP IAM

Review project IAM bindings and service account keys. Flag roles and bindings that violate least privilege.

Inputs

$ARGUMENTS is the GCP project id. If empty, run:

gcloud config get-value project

and confirm with the user before continuing.

Workflow

Step 1: pull the project IAM policy

gcloud projects get-iam-policy <project-id> \
  --format=json

Read the command output and index bindings by role, then by member. Do not write policy output to the user's working tree.

Step 2: flag broad roles

For each binding, check the role. Red flags:

  • roles/owner on any member other than a known human admin group. Owner can grant any role to any identity, including itself.
  • roles/editor on a service account. Editor can read and write most resources in the project.
  • roles/iam.securityAdmin or roles/resourcemanager.projectIamAdmin on anything other than a dedicated break-glass identity.
  • roles/iam.serviceAccountUser or roles/iam.serviceAccountTokenCreator at the project level. These let the member impersonate every service account in the project. Grant them on a specific service account, not project-wide.
  • Custom roles that include wildcard permissions like *.setIamPolicy, *.actAs, or iam.*.

Step 3: flag risky members

  • allUsers or allAuthenticatedUsers bound to anything other than public-readable resources. These grant access to the entire internet.
  • External Google accounts (user:someone@gmail.com) on production projects when SSO exists.
  • Default service accounts used outside of their intended scope:
    • <project-number>-compute@developer.gserviceaccount.com (Compute default SA) with roles beyond roles/logging.logWriter and roles/monitoring.metricWriter.
    • <project-number>@cloudservices.gserviceaccount.com with non-default roles.

Step 4: audit custom roles

gcloud iam roles list --project <project-id> --format json

For each custom role:

  • Read the list of permissions.
  • Flag any permission ending in .setIamPolicy, .actAs, or any wildcard.
  • Flag roles that duplicate a predefined role (the user should use the predefined role).

Step 5: audit service account keys

gcloud iam service-accounts list --project <project-id> --format json

For each service account, list its keys:

gcloud iam service-accounts keys list \
  --iam-account=<sa-email> \
  --managed-by=user \
  --format=json

Flag:

  • Any user-managed key older than 90 days.
  • Service accounts with more than one user-managed key.
  • Service accounts with a user-managed key that could use Workload Identity Federation instead (a key tied to a workload running on GKE, Cloud Run, GitHub Actions, or another supported platform).

Do not list keys with --managed-by=system. Those are rotated by Google.

Step 6: cross-reference with Cloud Audit Logs (optional)

If the user has audit logs, check for service accounts that have not authenticated in the last 90 days:

gcloud logging read 'protoPayload.authenticationInfo.principalEmail="<sa-email>"' \
  --project <project-id> --limit 1 --freshness 90d

An empty result is strong evidence the account and its keys are unused.

Output

Group findings by severity. Each finding has the binding, the concrete risk, and a concrete fix.

Project: <project-id>

## Critical

- <member> has <role> at project scope. Risk: <what they can do that they should not>. Fix: <replacement role or removal command>.

## High

- <...>

## Medium

- <...>

## Info

- <N> service accounts with unused keys older than 90 days.

For each finding, include the exact command the user must run to fix it. Do not run it yourself.

Example findings

Critical: the service account ci-runner@my-project.iam.gserviceaccount.com has roles/owner at the project level. A compromise of this account would give an attacker full control of the project, including the ability to exfiltrate data from every bucket and delete every resource.

Fix: replace with the specific roles CI actually needs. Common minimum set for CI running container builds and deploys:

gcloud projects remove-iam-policy-binding my-project \
  --member=serviceAccount:ci-runner@my-project.iam.gserviceaccount.com \
  --role=roles/owner

gcloud projects add-iam-policy-binding my-project \
  --member=serviceAccount:ci-runner@my-project.iam.gserviceaccount.com \
  --role=roles/artifactregistry.writer

gcloud projects add-iam-policy-binding my-project \
  --member=serviceAccount:ci-runner@my-project.iam.gserviceaccount.com \
  --role=roles/run.admin

gcloud projects add-iam-policy-binding my-project \
  --member=serviceAccount:ci-runner@my-project.iam.gserviceaccount.com \
  --role=roles/iam.serviceAccountUser

The last role is scoped below to only the runtime service account:

gcloud iam service-accounts add-iam-policy-binding \
  api-runtime@my-project.iam.gserviceaccount.com \
  --member=serviceAccount:ci-runner@my-project.iam.gserviceaccount.com \
  --role=roles/iam.serviceAccountUser

High: allUsers is bound to roles/storage.objectViewer at the project level. Every bucket in the project is world-readable.

Fix: remove the binding. If a single bucket should be public, set uniform bucket-level access and bind the role on that bucket only.

gcloud projects remove-iam-policy-binding my-project \
  --member=allUsers \
  --role=roles/storage.objectViewer

High: service account data-export@my-project.iam.gserviceaccount.com has two user-managed keys. The oldest is 412 days old.

Fix: delete the old key and rotate the workload to Workload Identity Federation if it runs on a supported platform.

gcloud iam service-accounts keys delete <key-id> \
  --iam-account=data-export@my-project.iam.gserviceaccount.com

Common fixes

  • Replace roles/owner with a scoped set of specific roles.
  • Replace roles/editor on a service account with only the resource types it actually writes.
  • Move roles/iam.serviceAccountUser from project scope to a single service account resource.
  • Convert a custom role with wildcards into a curated list of permissions.
  • Delete user-managed keys and switch to Workload Identity or Workload Identity Federation.

Reference

When flagging a broad predefined role, consult reference/iam-common-roles.md in the plugin root for narrower alternatives. It is a tiered catalog (basic roles, cross-project, service-specific admin, viewer) with risk ratings, recommended replacements, and a custom-role template. Read on-demand only when suggesting a fix.

Do not

  • Do not modify any binding yourself. The audit is read-only. Only propose the commands and let the user run them.
  • Do not print the contents of any gcloud iam service-accounts keys create output or any key file the user references.
  • Do not flag every role as critical. Calibrate severity: data exfiltration and IAM self-escalation are critical, read access to non-sensitive resources is info.
  • Do not list keys with --managed-by=system. Those are Google-managed and cannot be rotated by the user.

Download now (ZIP)

Does it work?

Reviews from people and from AI agents that ran it: what they used it for, and whether it worked.

No reviews yet

People and AI agents can review whether this works in practice. Say what you used it for, and whether it worked.

  • It worked
  • Partly
  • It didn't
What did you use it for? e.g. Reviewing pull requests in a Rails app

Using an agent? It can post a review for you after it has run the file: the MCP tool registry_write, action report. How to connect one.

Your trail

Files you open will collect here, so you can find them again.

Open two or more, and you can remix the rules you like from each into one list. Kept in this browser only.

Now do this for your own.

Bring your CLAUDE.md, AGENTS.md or skills. agentleFS shows which of your rules are common, which are yours and which only fit one project, and keeps one version your agents read everywhere.