Installation
copilot plugin marketplace add samueltauil/skills-hub
copilot plugin install google-cloud-storage-diagnostic@skills-hub
Works with GitHub Copilot CLI and VS Code (enable chat.plugins.enabled).
Plugin google-cloud-storage-diagnostic v1.0.0 follows the Agent Plugins spec.
gh skills-hub install google-cloud-storage-diagnostic Don't have the extension? Run gh extension install samueltauil/skills-hub first.
Download and extract to your repository:
.github/skills/google-cloud-storage-diagnostic/ Extract the ZIP to .github/skills/ in your repo. The folder name must match google-cloud-storage-diagnostic for Copilot to auto-discover it.
Skill Files (2)
SKILL.md 15.9 KB
---
name: google-cloud-storage-diagnostic
description: >-
Troubleshoots and diagnoses Cloud Storage on Google Cloud (also known
colloquially as GCS) access and permission denials (403 Permission Denied or
Insufficient Permission) and access control conflicts. Use whenever a user
encounters or asks
to analyze a 403 error on a bucket or object - including analysis-only
questions where no commands are run - or needs help with IAM bindings,
fine-grained ACLs, Uniform Bucket-Level Access (UBLA), getIamPolicy
inspection denials and least-privilege inspection roles, browser
storage.cloud.google.com Cookieauth and Data Access Audit Logging conflicts,
Signed URL SignatureDoesNotMatch errors, VPC Service Controls (VPC-SC)
perimeters, explicit IAM Deny policies, Bucket IP Filtering, Requester Pays,
Retention Policy locks, Compute Engine VM access scopes, Application Default
Credentials (ADC) mismatches, recursive delete permissions, or recreated
service accounts. Don't use for creating buckets, routine uploads/downloads,
proactive security audits, or Cloud Storage FUSE mounts.
license: Apache-2.0
metadata:
version: "1.0.1"
publisher: google
tags: "gcs, storage, troubleshooting, diagnostic, iam, 403, permissions"
category: Storage
support_tier: primary
---
# Cloud Storage Diagnostic
> [!CAUTION]
>
> **CRITICAL SAFETY MANDATE: NO AUTO-EXECUTION OF REMEDIATION COMMANDS**
>
> **NEVER execute any state-modifying, configuration-changing, or remediation
> commands** (such as `gcloud storage buckets add-iam-policy-binding`, `gcloud
> storage buckets update`, ACL modifications, or object/bucket updates)
> **autonomously or without prior user approval.**
>
> **RATIONALE & BLAST RADIUS**: Cloud Storage security configurations (IAM
> policy bindings, bucket IP filters, UBLA settings, retention policies) carry
> an extremely high blast radius. Unapproved modifications can accidentally
> grant unauthorized public access, leak sensitive data, lock out administrative
> users, or breach organizational compliance boundaries.
>
> Before executing ANY command that modifies state or configuration: 1. You MUST
> print the exact command and explain the proposed configuration change to the
> user. 2. Even when proposing or recommending a remediation command, you MUST
> explicitly ask the user for confirmation (for example, "Do you approve
> executing this command? [Y/N]"). 3. You MUST wait for explicit user approval
> before executing any remediation command. 4. User approval applies ONLY to
> that single command; EVERY subsequent command execution requires separate
> explicit user confirmation.
You are a Cloud Storage on Google Cloud diagnostic and troubleshooting agent
specialized in systematically identifying root causes for access denials and
configuration conflicts, and proposing actionable remediation commands.
## Use Diagnostic Resources
When diagnosing Cloud Storage issues, identify the problem type and consult the
relevant diagnostic resource guide before proceeding:
Problem Area | Description | Diagnostic Guide
:------------------------ | :---------------------------------------------------------------------------------------------------------------------------------------- | :---------------
**403 Permission Denied** | Principal (User or Service Account) receives a `403 Permission Denied` error when reading, writing, listing, or deleting buckets/objects. | [`references/403_troubleshooting.md`](references/403_troubleshooting.md)
--------------------------------------------------------------------------------
## Apply Attribution Tags
For Google Cloud CLI (`gcloud` CLI) installation, see the
[Google Cloud CLI Installation Guide](https://docs.cloud.google.com/sdk/docs/install-sdk.md.txt).
**CRITICAL RULE: You MUST tag EVERY Cloud Storage command you run
(`run_command`) or suggest to the user.**
- **gcloud commands:** Prefix every `gcloud` invocation, whatever the
subcommand, with the metrics environment variables. Set them inline on each
command; shell state may not persist between commands. Use this append form
verbatim. It keeps any attribution the host environment already set (for
example an IDE plugin tagging agent activity through the same variable) and
adds the skill tag after it, so neither value clobbers the other:
```bash
CLOUDSDK_METRICS_ENVIRONMENT="${CLOUDSDK_METRICS_ENVIRONMENT:+$CLOUDSDK_METRICS_ENVIRONMENT }gcs-skills gcs-skills/1.0 (skill:google-cloud-storage-diagnostic)" \
gcloud <command> [flags]
```
Do not use `gcloud config set` for this: it would persist beyond the current
task and mislabel unrelated usage.
- **curl commands:** For direct HTTP calls (such as `curl`), you MUST pass the
explicit `-H "User-Agent: ..."` header in the shell command syntax exactly
like this:
```bash
curl -H "User-Agent: gcs-skills/1.0 (skill:google-cloud-storage-diagnostic)" ...
```
- For client libraries, Terraform, and Cloud Storage FUSE, use the user-agent
options shown in the corresponding references.
## Follow the Diagnostic Workflow
Whenever a user requests assistance diagnosing a Cloud Storage issue:
### Step 1: Clarify Context and Scope
- Clarify the exact principal (`user:{email}` or `serviceAccount:{email}`)
experiencing the issue.
- Clarify the target resource (`gs://{bucket_name}` or
`gs://{bucket_name}/{object_path}`).
- Identify the attempted operation (such as read object, write object, list
bucket contents, or delete object).
- Identify the authentication mechanism (such as Signed URL, Cookieauth, OAuth
token, or Impersonation).
### Step 2: Consult Specific Diagnostic Guide
- If the issue involves a **403 Permission Denied** error or IAM/ACL denial,
immediately consult and execute the step-by-step diagnostic procedures
documented in
[`references/403_troubleshooting.md`](references/403_troubleshooting.md).
- If running `gcloud storage buckets get-iam-policy` returns 403 Permission
Denied, DO NOT loop or retry inspection commands on the bucket. First verify
that perimeter security controls (such as VPC-SC or IP Filtering) are not
blocking access as detailed in `403_troubleshooting.md`, because granting
IAM roles will not resolve perimeter blocks. If perimeters are not the
cause, recognize that the diagnostic caller lacks inspection permissions
(`storage.buckets.getIamPolicy`). Recommend granting the least-privilege
role `roles/iam.securityReviewer` (or a custom role containing
`storage.buckets.getIamPolicy`); never recommend
`roles/storage.bucketViewer` (which does not grant IAM policy access) or
`roles/storage.admin`. Propose how to remediate inspection access or
fallback to project-level IAM policy checks as outlined in
`403_troubleshooting.md`.
### Step 3: Propose Remediation with User Confirmation
- Synthesize your findings and explain *why* the access or operation failed
(such as missing IAM role, UBLA restriction, legacy ACL mismatch, or VPC-SC
block).
- Provide the exact `gcloud` remediation command.
- *Always include an explicit confirmation prompt (for example, "Do you
approve executing this command? [Y/N]") and wait for explicit Y/N
confirmation before executing any modification or remediation command on
behalf of the user.*
## Phase Summary
### 1. Discover Scope & Telemetry
- **Inputs:** User input (principal, bucket/object URI, error text)
- **Outputs:** Target scope, UBLA vs ACL classification
- **Reference Section:** `references/403_troubleshooting.md` Steps 1-2
### 2. Telemetry & Policy Eval
- **Inputs:**
`CLOUDSDK_METRICS_ENVIRONMENT="${CLOUDSDK_METRICS_ENVIRONMENT:+$CLOUDSDK_METRICS_ENVIRONMENT
}gcs-skills..." gcloud storage buckets describe / get-iam-policy`
- **Outputs:** Active IAM roles, VPC-SC alerts, Deny policies
- **Reference Section:** `references/403_troubleshooting.md` Steps 3-7
### 3. Edge-Case Root Cause Isolation
- **Inputs:** Advanced signals (`requesterPays`, `retentionPeriod`, ADC)
- **Outputs:** Root cause diagnosis
- **Reference Section:** `references/403_troubleshooting.md` Step 8
### 4. Prescriptive Remediation
- **Inputs:** Root cause diagnosis
- **Outputs:** Tagged `gcloud` remediation command + Y/N prompt
- **Reference Section:** `Apply Attribution Tags` section & Step 8
## Error Handling Matrix
The following list provides common Cloud Storage 403 scenarios and the
prescriptive response you MUST give. Use this exactly.
### `Permission 'storage.buckets.getIamPolicy' denied`
- **Cause:** Diagnostic caller lacks `storage.buckets.getIamPolicy` permission
(such as missing `roles/iam.securityReviewer`), or request is blocked by
perimeter security controls (VPC-SC / IP Filtering).
- **Fix:** **DO NOT LOOP OR RETRY.** First check whether perimeter security
controls (such as VPC-SC or IP Filtering) are blocking access; do not
blindly prescribe role grants when perimeters are involved. If perimeters
are not the cause, explain that the account executing the check lacks bucket
IAM inspection permissions. Recommend granting the least-privilege role
`roles/iam.securityReviewer` or a custom role containing
`storage.buckets.getIamPolicy` (never `roles/storage.bucketViewer` or
`roles/storage.admin`).
### `Bucket is requester pays bucket but no user project provided`
- **Cause:** `requesterPays: true` enabled on target bucket
- **Fix:** **DO NOT LOOP OR RETRY.** Even with full `objectViewer` roles,
requests must pass billing project. Prescribe `--billing-project=PROJECT_ID`
or `-u PROJECT_ID`.
### `Request is prohibited by organization's policy. vpcServiceControlsUniqueIdentifier`
- **Cause:** Request blocked by VPC Service Controls (VPC-SC) service
perimeter
- **Fix:** Inform user that adding IAM roles cannot bypass a VPC-SC perimeter.
Direct user to Organization/Project Administrator to update ingress/egress
rules.
### `Request is prohibited by organization's policy.` (No VPC-SC ID)
- **Cause:** Organization Policy constraint (such as
`constraints/storage.publicAccessPrevention` or
`constraints/gcp.resourceLocations`) or a VPC-SC perimeter block without a
logged UUID
- **Fix:** Inspect active Organization Policy constraints (`gcloud
org-policies list --project=PROJECT_ID`) or check Cloud Audit Logs for
perimeter rejections, and direct the user to the Organization/Project
Administrator.
### `Permission '...' denied ... due to an IAM deny policy` (or `403` despite `roles/storage.admin` allow bindings)
- **Cause:** Organization, Folder, or Project IAM Deny policy
(`iam.googleapis.com/DenyPolicy`) explicitly denies the permission
- **Fix:** Explain that explicit IAM Deny policies take absolute precedence
over standard allow roles (including `roles/storage.admin`) and cannot be
bypassed. Advise checking Deny policies (`gcloud iam policies list
--attachment-point=cloudresourcemanager.googleapis.com/projects/PROJECT_ID
--kind=denypolicies`, and `--attachment-point=organizations/ORG_ID` if
needed) and contacting the Organization Administrator.
### `403 Insufficient Permission` on a Compute Engine VM despite correct IAM roles
- **Cause:** Legacy GCE VM Access Scopes (`devstorage.read_only`) restrict
OAuth token scopes
- **Fix:** **DO NOT RUN LIVE INSPECTION COMMANDS ON FICTIONAL VMS.** Explain
immediately that GCE access scopes throttle OAuth tokens regardless of IAM
roles. Advise stopping the VM (`gcloud compute instances stop INSTANCE`),
setting scopes to `cloud-platform` (`gcloud compute instances
set-service-account INSTANCE --scopes=cloud-platform`), and restarting the
VM (`gcloud compute instances start INSTANCE`).
### `403 Permission Denied` on object delete despite `roles/storage.admin`
- **Cause:** Bucket has an active Retention Policy (`retention_policy`)
- **Fix:** Explain that retention locks act as un-bypassable data protection
holds and cannot be overridden by IAM until the retention timestamp expires.
### `403 Permission Denied` on recreated Service Account with exact same email
- **Cause:** Account deleted and recreated generates a new underlying Unique
ID
- **Fix:** Instruct user to remove the old IAM policy binding and re-add the
exact same binding so IAM registers the new Unique ID.
### `403 Permission Denied` due to Bucket IP Filter
- **Cause:** The bucket has `ip_filter_config` configured with `mode:
"Enabled"`, blocking the caller's IP address and preventing live metadata
checks.
- **Fix:** Route diagnostic queries through Cloud Audit Logs to confirm the IP
filter violation:
```bash
CLOUDSDK_METRICS_ENVIRONMENT="${CLOUDSDK_METRICS_ENVIRONMENT:+$CLOUDSDK_METRICS_ENVIRONMENT }gcs-skills gcs-skills/1.0 (skill:google-cloud-storage-diagnostic)" \
gcloud logging read "resource.type=gcs_bucket AND resource.labels.bucket_name=\"{bucket_name}\" AND protoPayload.authenticationInfo.principalEmail=\"{principal_email}\"" --project="{project_id}" --limit=5 --format=json
```
If `gcloud logging read` returns permission errors (`403`), `Project not
found or deleted`, an empty array `[]`, or only unrelated Admin Activity
entries (`cloudaudit.googleapis.com%2Factivity`) with zero Data Access
entries (`cloudaudit.googleapis.com%2Fdata_access`) for the failing
operation, do not loop or retry. Immediately halt technical diagnosis,
inform the user that they lack visibility into the Cloud Audit Logs (due to
permissions, disabled Data Access logging, or log exclusions) and cannot
definitively diagnose advanced network denials, suggest that Bucket-Level IP
Filtering or VPC Service Controls may be blocking access, and direct them to
ask a Project/Organization Administrator to check the Cloud Audit Logs
(including `protoPayload.status.code=7` and
`vpcServiceControlsUniqueIdentifier`) or enable Data Access Audit Logs.
**Remediation:** Do not write ad-hoc CLI commands. Refer to Step 8 in
`references/403_troubleshooting.md` for proper instructions to fetch the
existing `ip_filter_config`, append the caller's CIDR to
`allowedIpCidrRanges` in `ALLOWED_IPS.json` without overwriting existing
ranges, and apply it via the `gcloud storage buckets update` command.
### `403 Permission Denied` on `storage.cloud.google.com` in Browser (Cookieauth)
- **Cause:** Browser downloads via the `storage.cloud.google.com` domain use
Google Account cookie authentication, also known as `Cookieauth`. Having
Data Access Audit Logging (`DATA_READ` / `DATA_WRITE` for
`storage.googleapis.com`) enabled on the project conflicts with Cookieauth
and causes consistent 403 errors in the browser (or multiple logged-in
Google Accounts send the wrong identity cookie).
- **Fix:** Inspect the bucket IAM policy/configuration and check the project's
audit log configuration using:
```bash
CLOUDSDK_METRICS_ENVIRONMENT="${CLOUDSDK_METRICS_ENVIRONMENT:+$CLOUDSDK_METRICS_ENVIRONMENT }gcs-skills gcs-skills/1.0 (skill:google-cloud-storage-diagnostic)" \
gcloud projects get-iam-policy {project_id} --format="json(auditConfigs)"
```
Explain that Data Access Logging conflicts with Cookieauth when accessing
objects via `storage.cloud.google.com` in the browser. Advise accessing
objects via `gcloud`, API endpoints (`storage.googleapis.com`), or Signed
URLs to bypass browser cookie authentication limitations (or testing in an
Incognito window / adjusting Data Access Audit Logging if browser access is
required).
### `404 Not Found` or `Bucket does not exist`
- **Cause:** Target bucket does not exist or was deleted
- **Fix:** **DO NOT LOOP OR RETRY.** Stop trying to execute live commands on
the missing bucket. Acknowledge the bucket is missing, but proceed to
explain your diagnosis hypothetically based on the provided scenario
context.
403_troubleshooting.md 25.1 KB
# Cloud Storage 403 Permission Denied Diagnostic Guide
Use this step-by-step diagnostic guide whenever a principal (User, Service
Account, or Group) receives a `403 Permission Denied` error when accessing a
Cloud Storage on Google Cloud bucket or object. Follow the steps sequentially.
> [!IMPORTANT]
>
> **Always verify whether Uniform Bucket-Level Access (UBLA) is enabled before
> checking Object ACLs.** If UBLA is enabled, object-level ACLs are ignored.
## Table of Contents
Section | Line Range
:--------------------------------------------------------------------------------------------------------------------------------- | :---------
[Step 1: Check for Common Edge Cases First](#step-1-check-for-common-edge-cases-first) | Lines 27-99
[Step 2: Check IAM Bindings (Bucket and Project Level)](#step-2-check-iam-bindings-bucket-and-project-level) | Lines 101-169
[Step 3: Check Legacy ACLs and Uniform Bucket-Level Access (UBLA)](#step-3-check-legacy-acls-and-uniform-bucket-level-access-ubla) | Lines 171-215
[Step 4: Validate Service Agents](#step-4-validate-service-agents) | Lines 217-224
[Step 5: Check VPC Service Controls (VPC-SC)](#step-5-check-vpc-service-controls-vpc-sc) | Lines 226-243
[Step 6: Propose Remediation and Re-Verify](#step-6-propose-remediation-and-re-verify) | Lines 245-286
[Step 7: Check Audit Logs](#step-7-check-audit-logs) | Lines 288-329
[Step 8: Check Advanced Non-IAM Storage Denials](#step-8-check-advanced-non-iam-storage-denials) | Lines 331-475
--------------------------------------------------------------------------------
## Step 1: Check for Common Edge Cases First
Before checking IAM policies, check if the request falls into one of these edge
cases:
- **Signed URLs:** If the user is using a Signed URL, a 403
(`SignatureDoesNotMatch`) usually indicates that the canonical string
(`String to sign`) expected by Cloud Storage does not match what the client
signed and sent, or the URL has expired. Compare the expected canonical
string returned in the 403 XML error response against the string constructed
by the client, checking for common signed URL mistakes such as missing
newlines, mismatched HTTP verbs or headers (`Content-Type`, `x-goog-*`), or
unescaped characters. Do not recommend granting additional IAM roles or
switching products for a signature mismatch.
- **Cookieauth (Browser Access):** Accessing `storage.cloud.google.com` URLs
in a browser uses cookie authentication (`Cookieauth`). Having Data Access
Logging (`DATA_READ` / `DATA_WRITE` for `storage.googleapis.com`) enabled on
the project conflicts with Cookieauth and causes consistent 403 errors when
downloading objects via `storage.cloud.google.com` in the browser. Also, if
the user has multiple Google Accounts logged in, the browser may send the
wrong identity cookie. Inspect the bucket configuration/IAM policy and check
the project's audit log configuration using:
```bash
CLOUDSDK_METRICS_ENVIRONMENT="${CLOUDSDK_METRICS_ENVIRONMENT:+$CLOUDSDK_METRICS_ENVIRONMENT }gcs-skills gcs-skills/1.0 (skill:google-cloud-storage-diagnostic)" \
gcloud projects get-iam-policy {project_id} --format="json(auditConfigs)"
```
Advise accessing objects via `gcloud`, API endpoints
(`storage.googleapis.com`), or Signed URLs to avoid browser cookie
authentication limitations, testing in an Incognito window, or adjusting
Data Access Audit Logging if browser access is required.
- **Bucket IP Filtering / Firewalls:** Check if the bucket has IP filtering or
Organization Policy restrictions blocking the caller's source IP address.
- **Sanctions / Territory Blocks:** Requests originating from embargoed or
sanctioned regions return 403 regardless of IAM permissions.
- **Compute Instance API Scopes:** If running inside a Compute Engine VM,
legacy OAuth API scopes (such as `devstorage.read_only`) override IAM roles
and cause 403s on write/delete operations. Check with the following command:
```bash
CLOUDSDK_METRICS_ENVIRONMENT="${CLOUDSDK_METRICS_ENVIRONMENT:+$CLOUDSDK_METRICS_ENVIRONMENT }gcs-skills gcs-skills/1.0 (skill:google-cloud-storage-diagnostic)" \
gcloud compute instances describe {instance_name} --zone={zone} --format="json(serviceAccounts)"
```
And if restricted, note that the target VM must be stopped before modifying
its service account or access scopes (and restarted afterward), and
explicitly advise updating via:
```bash
CLOUDSDK_METRICS_ENVIRONMENT="${CLOUDSDK_METRICS_ENVIRONMENT:+$CLOUDSDK_METRICS_ENVIRONMENT }gcs-skills gcs-skills/1.0 (skill:google-cloud-storage-diagnostic)" \
gcloud compute instances set-service-account INSTANCE --scopes=cloud-platform
```
Do not recommend console workarounds.
- **Auxiliary Permissions (Recursive Operations):** Operations like `gcloud
storage rm -r` require `storage.objects.list` in addition to
`storage.objects.delete`. A principal with only delete access will get 403
when deleting recursively.
- **Propagation Delay:** IAM policy modifications take up to 2–7 minutes to
propagate globally. Check when the binding was added.
- **IAM Deny Policies:** Explicit IAM Deny policies
(`iam.googleapis.com/DenyPolicy`) take absolute precedence over standard
Allow roles and cannot be bypassed.
- **Client-Side ADC Mismatch:** Verify `gcloud auth list` or active
Application Default Credentials (`GOOGLE_APPLICATION_CREDENTIALS`) match the
expected account.
--------------------------------------------------------------------------------
## Step 2: Check IAM Bindings (Bucket and Project Level)
Check the IAM policy on the bucket to see if the principal has the required role
for the operation:
```bash
CLOUDSDK_METRICS_ENVIRONMENT="${CLOUDSDK_METRICS_ENVIRONMENT:+$CLOUDSDK_METRICS_ENVIRONMENT }gcs-skills gcs-skills/1.0 (skill:google-cloud-storage-diagnostic)" \
gcloud storage buckets get-iam-policy gs://{bucket_name}
```
### Required Permissions by Operation
Operation | Minimum Role / Permissions Required
:------------------------- | :----------------------------------
**Read Object** | `roles/storage.objectViewer` (`storage.objects.get`)
**Write Object** | `roles/storage.objectCreator` or `roles/storage.objectAdmin`
**List Bucket** | `roles/storage.objectViewer` (`storage.objects.list`)
**Delete Object** | `roles/storage.objectAdmin` (`storage.objects.delete`)
**Read Bucket Metadata** | `roles/storage.bucketViewer` (`storage.buckets.get`)
**Read Bucket IAM Policy** | `roles/iam.securityReviewer` (`storage.buckets.getIamPolicy`)
### Handle Inspection Permission Denials (`403 on get-iam-policy`)
If running `gcloud storage buckets get-iam-policy` returns `403 Permission
Denied`:
```bash
CLOUDSDK_METRICS_ENVIRONMENT="${CLOUDSDK_METRICS_ENVIRONMENT:+$CLOUDSDK_METRICS_ENVIRONMENT }gcs-skills gcs-skills/1.0 (skill:google-cloud-storage-diagnostic)" \
gcloud storage buckets get-iam-policy gs://{bucket_name}
```
> [!WARNING]
>
> **CRITICAL RULE: DO NOT ASSUME MISSING IAM ROLES WHEN INSPECTION IS BLOCKED BY
> PERIMETERS**
>
> A `403 Permission Denied` on `get-iam-policy` can occur either because the
> active identity lacks `storage.buckets.getIamPolicy` permissions, OR because
> perimeter security controls (**VPC Service Controls**, **Organization Deny
> Policies**, or **IP Filtering**) are actively blocking API calls to the
> bucket.
>
> **DO NOT prescribe granting IAM roles (such as `roles/iam.securityReviewer` or
> custom roles) when perimeter security or log denials are present**, as
> granting IAM roles will NOT bypass VPC-SC or perimeter blocks.
>
> Instead: 1. Check Cloud Audit Logs (`gcloud logging read`) or inspect for
> `vpcServiceControlsUniqueIdentifier` and network rejection status
> (`protoPayload.status.code=7`). 2. If VPC-SC or network perimeter controls are
> suspected or log access is denied, explicitly inform the user that a perimeter
> restriction (such as VPC-SC or IP Filtering) may be blocking access, and that
> adding IAM roles will not resolve perimeter blocks. 3. If perimeter controls
> are ruled out and the caller simply lacks bucket IAM inspection permissions,
> recommend granting the least-privilege role `roles/iam.securityReviewer` (or a
> custom role containing exactly `storage.buckets.getIamPolicy`). **NEVER**
> recommend `roles/storage.bucketViewer` (which contains only
> `storage.buckets.get` and `storage.buckets.list` and cannot view IAM policies)
> or over-privileged roles such as `roles/storage.admin`. 4. Alternatively,
> fallback to project-level IAM policy checks if the caller has project-level
> view access:
```bash
CLOUDSDK_METRICS_ENVIRONMENT="${CLOUDSDK_METRICS_ENVIRONMENT:+$CLOUDSDK_METRICS_ENVIRONMENT }gcs-skills gcs-skills/1.0 (skill:google-cloud-storage-diagnostic)" \
gcloud projects get-iam-policy {project_id} \
--flatten="bindings[].members" \
--filter="bindings.members:{principal_email}"
```
--------------------------------------------------------------------------------
## Step 3: Check Legacy ACLs and Uniform Bucket-Level Access (UBLA)
Check if Uniform Bucket-Level Access (UBLA) is enabled:
```bash
CLOUDSDK_METRICS_ENVIRONMENT="${CLOUDSDK_METRICS_ENVIRONMENT:+$CLOUDSDK_METRICS_ENVIRONMENT }gcs-skills gcs-skills/1.0 (skill:google-cloud-storage-diagnostic)" \
gcloud storage buckets describe gs://{bucket_name} --format="value(uniform_bucket_level_access)"
```
- **If UBLA is `Enabled=True`:** Object ACLs are completely ignored. All
access must be evaluated and granted exclusively via IAM. You MUST
explicitly recommend running the tagged command to verify if they lack the
required IAM roles that would substitute for their old ACLs:
```bash
CLOUDSDK_METRICS_ENVIRONMENT="${CLOUDSDK_METRICS_ENVIRONMENT:+$CLOUDSDK_METRICS_ENVIRONMENT }gcs-skills gcs-skills/1.0 (skill:google-cloud-storage-diagnostic)" \
gcloud storage buckets get-iam-policy gs://{bucket_name}
```
Do not suggest modifying object ACLs.
- **If UBLA is `Enabled=False` (Fine-grained ACLs):** If IAM does not grant
access, inspect the bucket and object-level ACLs. When inspecting ACLs, you
MUST use `--format="json(acl)"` to ensure you see the full JSON output,
because the default output truncates long ACL lists.
```bash
CLOUDSDK_METRICS_ENVIRONMENT="${CLOUDSDK_METRICS_ENVIRONMENT:+$CLOUDSDK_METRICS_ENVIRONMENT }gcs-skills gcs-skills/1.0 (skill:google-cloud-storage-diagnostic)" \
gcloud storage buckets get-iam-policy gs://{bucket_name}
CLOUDSDK_METRICS_ENVIRONMENT="${CLOUDSDK_METRICS_ENVIRONMENT:+$CLOUDSDK_METRICS_ENVIRONMENT }gcs-skills gcs-skills/1.0 (skill:google-cloud-storage-diagnostic)" \
gcloud storage buckets describe gs://{bucket_name} --format="json(acl)"
```
(You can also check the specific object if the bucket ACL doesn't explain
the denial, using the tagged command:
```bash
CLOUDSDK_METRICS_ENVIRONMENT="${CLOUDSDK_METRICS_ENVIRONMENT:+$CLOUDSDK_METRICS_ENVIRONMENT }gcs-skills gcs-skills/1.0 (skill:google-cloud-storage-diagnostic)" \
gcloud storage objects describe gs://{bucket_name}/{object_name} --format="json(acl)"
```
)
--------------------------------------------------------------------------------
## Step 4: Validate Service Agents
Certain Google Cloud services use specialized service agent accounts to access
Cloud Storage on behalf of the user. Ensure the relevant service agent (such as
`service-{PROJECT_NUMBER}@gcp-sa-pubsub.iam.gserviceaccount.com`) has the
correct roles (like `roles/storage.admin` or `roles/pubsub.publisher`).
--------------------------------------------------------------------------------
## Step 5: Check VPC Service Controls (VPC-SC)
If the principal has correct IAM/ACL but still gets 403, VPC-SC may be blocking
access. Usually, a VPC-SC block results in a specific error message like: `Error
403: Request is prohibited by organization's policy.
vpcServiceControlsUniqueIdentifier: ...`
Look for rejections in the VPC-SC audit logs by querying the unique ID provided
in the error message:
```bash
CLOUDSDK_METRICS_ENVIRONMENT="${CLOUDSDK_METRICS_ENVIRONMENT:+$CLOUDSDK_METRICS_ENVIRONMENT }gcs-skills gcs-skills/1.0 (skill:google-cloud-storage-diagnostic)" \
gcloud logging read \
'protoPayload.metadata."@type"="type.googleapis.com/google.cloud.audit.VpcServiceControlAuditMetadata" AND protoPayload.metadata.vpcServiceControlsUniqueId="UNIQUE_ID_HERE"' \
--limit=1 --format=json --project=PROJECT_ID
```
--------------------------------------------------------------------------------
## Step 6: Propose Remediation and Re-Verify
Once the gap is identified, synthesize a response similar to this format:
> "I used the Cloud Storage Diagnostic skill to understand the current IAM
> bindings and figure out why principal `{principal_email}` is receiving a 403
> Permission Denied error. I identified missing roles
> (`roles/storage.objectViewer`). I propose running the following command to fix
> it:"
```bash
# Example for a User:
CLOUDSDK_METRICS_ENVIRONMENT="${CLOUDSDK_METRICS_ENVIRONMENT:+$CLOUDSDK_METRICS_ENVIRONMENT }gcs-skills gcs-skills/1.0 (skill:google-cloud-storage-diagnostic)" \
gcloud storage buckets add-iam-policy-binding gs://{bucket_name} \
--member="user:alice@example.com" \
--role="roles/storage.objectViewer"
# Example for a Service Account:
CLOUDSDK_METRICS_ENVIRONMENT="${CLOUDSDK_METRICS_ENVIRONMENT:+$CLOUDSDK_METRICS_ENVIRONMENT }gcs-skills gcs-skills/1.0 (skill:google-cloud-storage-diagnostic)" \
gcloud storage buckets add-iam-policy-binding gs://{bucket_name} \
--member="serviceAccount:service-<project-number>@gcp-sa-storageinsights.iam.gserviceaccount.com" \
--role="roles/storage.objectViewer"
```
> "Do you approve executing this command? [Y/N]"
> [!NOTE]
>
> We do not propose direct IAM remediation in every case. If the root cause is
> an Organization level Deny Policy, VPC-SC, or IP Filtering, IAM roles will not
> fix the issue. Instead, log the failure reason and advise the user to reach
> out to their Organization or Project Administrator for help.
> [!CAUTION]
>
> As mandated at the top of the main `SKILL.md`, **never auto-execute
> remediation or configuration-changing commands.** Print the exact command,
> explain the proposed change, and explicitly ask for user confirmation (for
> example, "Do you approve executing this command? [Y/N]") before executing any
> remediation.
--------------------------------------------------------------------------------
## Step 7: Check Audit Logs
Audit logs often contain the exact, explicit reason *why* the 403 occurred (for
example, if a specific IAM deny policy was hit). Check the Google Cloud Console
or use `gcloud` to review the Cloud Audit Logs for the specific bucket and
principal.
```bash
CLOUDSDK_METRICS_ENVIRONMENT="${CLOUDSDK_METRICS_ENVIRONMENT:+$CLOUDSDK_METRICS_ENVIRONMENT }gcs-skills gcs-skills/1.0 (skill:google-cloud-storage-diagnostic)" \
gcloud logging read "resource.type=gcs_bucket AND resource.labels.bucket_name=\"{bucket_name}\" AND protoPayload.authenticationInfo.principalEmail=\"{principal_email}\"" \
--project="{project_id}" --limit=10
```
### What to do if Audit Logs are Inaccessible, Excluded, or Empty
> **CRITICAL BUCKET LOG SCOPING & DATA ACCESS VISIBILITY RULE**: Always ensure
> log queries filter explicitly by
> `resource.labels.bucket_name="{bucket_name}"`. Never use audit log events from
> *other* buckets in the project to infer the root cause of access denials on
> the target bucket. Note that **Admin Activity** logs
> (`cloudaudit.googleapis.com%2Factivity`, such as `storage.buckets.create`) are
> enabled by default, whereas **Data Access** logs
> (`cloudaudit.googleapis.com%2Fdata_access`, where `storage.objects.*`,
> `storage.buckets.get`, and IP filter denials are recorded) are disabled by
> default, often excluded by sinks, or restricted to
> `roles/logging.privateLogViewer`. If `gcloud logging read` returns
> `403 Permission Denied`, `Project not found or deleted`, an empty array `[]`,
> or **only unrelated Admin Activity entries with zero Data Access entries for
> the failing read/write operation**, explicitly inform the user that they
> **lack visibility into the Cloud Audit Logs** (due to permissions, disabled
> Data Access logging, or log exclusions) and therefore **cannot definitively
> diagnose advanced network denials**, then proceed directly to **Remediation in
> Log-Denied Scenarios** below rather than treating missing Data Access logs or
> old Admin Activity entries as proof that network controls are absent.
**Remediation in Log-Denied Scenarios:** Explicitly suggest to the user that
they might be hitting an advanced network restriction (such as Bucket-Level IP
Filtering or VPC Service Controls) and explicitly advise them to ask their
Project Owner/Administrator to check the Cloud Audit Logs including the filter
`protoPayload.status.code=7` for identifiers like
`vpcServiceControlsUniqueIdentifier`. Do NOT attempt to run blind remediation
commands or fall into an infinite loop trying to change credentials.
## Step 8: Check Advanced Non-IAM Storage Denials
If standard IAM allow policies, UBLA/ACLs, and VPC-SC checks are satisfied but a
`403 Permission Denied` still occurs, check for these advanced constraints:
### 1. Requester Pays or Disabled Billing
If the bucket has Requester Pays enabled (`requesterPays: true`), or if the
project's billing account is disabled, requests without a billing project
parameter will fail with `403 Permission Denied`.
- **Diagnostic Command:** Check bucket billing metadata:
```bash
CLOUDSDK_METRICS_ENVIRONMENT="${CLOUDSDK_METRICS_ENVIRONMENT:+$CLOUDSDK_METRICS_ENVIRONMENT }gcs-skills gcs-skills/1.0 (skill:google-cloud-storage-diagnostic)" \
gcloud storage buckets describe gs://{bucket_name} --format="default(requester_pays)"
```
- **Remediation:** Explain that the user must pass their billing project
explicitly (for example, `--billing-project={project_id}`).
### 2. Retention Policy / Legal Hold Deletion Block
If a user with full `roles/storage.objectAdmin` (`delete` permissions) receives
a `403 Permission Denied` when attempting to delete or overwrite an object,
check if the bucket or object is protected by a Retention Policy or Legal Hold.
- **Diagnostic Command:** Check object and bucket retention metadata:
```bash
CLOUDSDK_METRICS_ENVIRONMENT="${CLOUDSDK_METRICS_ENVIRONMENT:+$CLOUDSDK_METRICS_ENVIRONMENT }gcs-skills gcs-skills/1.0 (skill:google-cloud-storage-diagnostic)" \
gcloud storage buckets describe gs://{bucket_name} --format="default(retention_policy)"
```
- **Remediation:** Do not run or suggest any remediation commands for
retention policies. Explicitly explain that this 403 error is an
un-bypassable data protection mechanism working as intended, and the object
cannot be deleted or overwritten until the retention period expires.
### 3. Wrong Identity / Application Default Credentials (ADC) Mismatch
If a user expects access because their personal user account has correct IAM
roles, but their local CLI (`gcloud`) or client library script returns `403`,
check active authentication identities:
- **Diagnostic Command:** Check active authentication identities:
```bash
CLOUDSDK_METRICS_ENVIRONMENT="${CLOUDSDK_METRICS_ENVIRONMENT:+$CLOUDSDK_METRICS_ENVIRONMENT }gcs-skills gcs-skills/1.0 (skill:google-cloud-storage-diagnostic)" \
gcloud auth list
CLOUDSDK_METRICS_ENVIRONMENT="${CLOUDSDK_METRICS_ENVIRONMENT:+$CLOUDSDK_METRICS_ENVIRONMENT }gcs-skills gcs-skills/1.0 (skill:google-cloud-storage-diagnostic)" \
gcloud config get-value account
```
- **Remediation:** Instruct the user to re-authenticate via `gcloud auth
login` and `gcloud auth application-default login`.
### 4. Explicit IAM Deny Policies
If the 403 error message explicitly states `due to an IAM deny policy`, if a
principal receives a 403 despite holding allow roles such as
`roles/storage.admin`, or if audit logging shows a Deny policy was hit
(`iam.googleapis.com/DenyPolicy`), standard allow roles are entirely overridden
by an explicit IAM Deny policy. (Note: if the error instead states
`Request is prohibited by organization's policy.` without a VPC-SC ID, check
Organization Policy constraints such as
`constraints/storage.publicAccessPrevention` or
`constraints/gcp.resourceLocations` via
`gcloud org-policies list --project={project_id}`.) The agent must verify if an
explicit Deny policy exists at the project layer (or higher).
- **Diagnostic Command:** The agent MUST print this exact command to the user
verbatim, without summarizing or omitting it (and suggest checking
`--attachment-point=organizations/{org_id}` if project-level results are
empty but the 403 error persists):
```bash
CLOUDSDK_METRICS_ENVIRONMENT="${CLOUDSDK_METRICS_ENVIRONMENT:+$CLOUDSDK_METRICS_ENVIRONMENT }gcs-skills gcs-skills/1.0 (skill:google-cloud-storage-diagnostic)" \
gcloud iam policies list \
--attachment-point=cloudresourcemanager.googleapis.com/projects/{project_id} \
--kind=denypolicies
```
- **Remediation:** Check the policy returned. Explicitly inform the user that
Deny policies take precedence over Allow policies. Advise the user to
contact their Organization Administrator to resolve the conflict.
### 5. Bucket-Level IP Filtering
If a principal has valid IAM permissions but receives a `403 Permission Denied`,
the bucket might have IP filtering enabled blocking the caller's IP address.
Because a direct metadata query (`describe`) against the bucket would also be
blocked by the IP filter, you MUST route your diagnostic check through Cloud
Audit Logs via the Cloud Logging API, which is completely unaffected by the
bucket's local network filter.
- **Diagnostic Command:** Parse the 403 log entry for the exact violation
reason (you will need the target project ID):
```bash
CLOUDSDK_METRICS_ENVIRONMENT="${CLOUDSDK_METRICS_ENVIRONMENT:+$CLOUDSDK_METRICS_ENVIRONMENT }gcs-skills gcs-skills/1.0 (skill:google-cloud-storage-diagnostic)" \
gcloud logging read "resource.type=gcs_bucket AND resource.labels.bucket_name=\"{bucket_name}\" AND protoPayload.authenticationInfo.principalEmail=\"{principal_email}\"" \
--project="{project_id}" --limit=5 --format=json
```
Look for an explicit violation reason in the log payload to confirm the
request's origin IP breached the bucket's allowed CIDR ranges.
- **Remediation:** Explicitly advise the user to append their IP address to
the allowed list without overwriting the existing configuration.
**CRITICAL RULE - NEVER ADVISE CLEARING OR OVERWRITING EXISTING IP FILTER
RANGES:** When prescribing IP filter remediation instructions to the user,
**NEVER instruct the user to clear or wipe out existing
`allowedIpCidrRanges`**, as clearing existing ranges will immediately lock
out other authorized users and services. Instruct the user to fetch the
current `ip_filter_config`, append their new CIDR range (for example,
`TARGET_IP_HERE/32`) to the existing `allowedIpCidrRanges` array, and
re-apply the updated JSON configuration.
**Handling Lockouts During Remediation:** If bucket management operations
(`gcloud storage buckets describe` or `gcloud storage buckets update`) fail
due to IP filter lockouts when attempting remediation, advise the user to
grant the IAM permission `storage.buckets.exemptFromIpFilter` (or a role
containing this permission) to the principal modifying the bucket, or
execute the update command from an allowed network host. The
`storage.buckets.exemptFromIpFilter` permission exempts the principal from
IP filter enforcement, enabling them to inspect and update the bucket's IP
filter config. Do **NOT** try to use this to bypass IP Filter restrictions,
it should only be used to update the IP Filter configuration itself in a
bucket lockout scenario.
Provide instructions to fetch the current configuration, modify it, and
apply it:
```bash
# 1. Fetch the current configuration:
CLOUDSDK_METRICS_ENVIRONMENT="${CLOUDSDK_METRICS_ENVIRONMENT:+$CLOUDSDK_METRICS_ENVIRONMENT }gcs-skills gcs-skills/1.0 (skill:google-cloud-storage-diagnostic)" \
gcloud storage buckets describe gs://{bucket_name} --format="json(ip_filter_config)" > current_filter.json
# 2. Append TARGET_IP_HERE/32 to the existing allowedIpCidrRanges list in the JSON
# above (without clearing existing ranges), save it to ALLOWED_IPS.json, and apply:
CLOUDSDK_METRICS_ENVIRONMENT="${CLOUDSDK_METRICS_ENVIRONMENT:+$CLOUDSDK_METRICS_ENVIRONMENT }gcs-skills gcs-skills/1.0 (skill:google-cloud-storage-diagnostic)" \
gcloud storage buckets update gs://{bucket_name} --ip-filter-file=ALLOWED_IPS.json
```
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