Cloud Storage is where most Google Cloud data ends up: exports, backups, logs, user uploads, data lake files and Terraform state. The failures are well known. A bucket gets an allUsers binding so a front-end can load images, then someone drops a database export into it. An old bucket without uniform bucket-level access keeps per-object ACLs that nobody audits. An HMAC key created for an S3-compatible tool lives on in a config file for years. A script with write access deletes or encrypts the backups, and nothing stops it. Bucket names are global and guessable, and attackers scan for public ones at scale, which is why MITRE ATT&CK tracks data from cloud storage as its own collection technique. Most of the controls below can be enforced for the whole organization with a few policies.
Baseline controls
Apply these to every bucket, and the stricter ones to buckets holding sensitive data or logs. CIS IDs refer to the CIS GCP Foundations Benchmark v5.0.1.
| Control | Why | How to check | CIS / SCC |
|---|---|---|---|
| Block public access with public access prevention | No allUsers grants, even by admins | gcloud storage buckets describe gs://BUCKET | CIS 5.1, PUBLIC_BUCKET_ACL |
| Enable uniform bucket-level access | Disables unauditable object ACLs | gcloud storage buckets describe gs://BUCKET | CIS 5.2, BUCKET_POLICY_ONLY_DISABLED |
| Grant narrow roles at bucket level | Project grants reach future buckets | gcloud storage buckets get-iam-policy gs://BUCKET | n/a |
| Minimize HMAC keys | Long-lived secrets tied to accounts | gcloud storage hmac list | n/a |
| Lengthen soft delete on important buckets | Recover from deletion or ransomware | soft_delete_policy on the bucket | n/a |
| Lock retention and version log sink buckets | Logs cannot be erased or overwritten | retention_policy, versioning_enabled | CIS 2.4, LOCKED_RETENTION_POLICY_NOT_SET, OBJECT_VERSIONING_DISABLED |
| Keep log sink buckets private | Logs reveal your whole environment | Asset search for public bindings | PUBLIC_LOG_BUCKET |
| Encrypt sensitive buckets with CMEK | Key-level control and audit trail | default_kms_key on the bucket | BUCKET_CMEK_DISABLED |
| Enable Data Access logs for sensitive data | Answer "who downloaded what" | Project audit config for storage.googleapis.com | CIS 2.1 |
| Alert on bucket IAM changes | Catch a bucket going public | Log-based metric exists | CIS 2.11, BUCKET_IAM_NOT_MONITORED |
| Restrict bucket locations | Data residency | gcp.resourceLocations policy | n/a |
Find what is exposed today
A bucket or object is public when an IAM binding or ACL grants a role to allUsers (anyone on the internet) or allAuthenticatedUsers (anyone with any Google account, which is effectively public). Search the whole organization with Cloud Asset Inventory:
gcloud asset search-all-iam-policies \
--scope=organizations/ORG_ID \
--asset-types=storage.googleapis.com/Bucket \
--query="policy:(allUsers OR allAuthenticatedUsers)" \
--format="table(resource,policy.bindings.role)"
For one bucket:
gcloud storage buckets get-iam-policy gs://BUCKET --format="json(bindings)"
gcloud storage buckets describe gs://BUCKET \
--format="yaml(uniform_bucket_level_access,public_access_prevention,soft_delete_policy,default_kms_key)"
Buckets without uniform bucket-level access can also have object ACLs granting public read, which the IAM search does not show. Security Command Center reports both as PUBLIC_BUCKET_ACL. Remove a public binding:
gcloud storage buckets remove-iam-policy-binding gs://BUCKET \
--member=allUsers --role=roles/storage.objectViewer
Public access prevention and uniform bucket-level access
Public access prevention
Public access prevention blocks any grant to allUsers or allAuthenticatedUsers on the bucket and its objects, even by someone with roles/storage.admin. If a public grant already exists, enforcing prevention makes it ineffective immediately.
gcloud storage buckets update gs://BUCKET --public-access-prevention
Uniform bucket-level access
Cloud Storage historically had two permission systems: IAM on buckets and ACLs on buckets and individual objects. Uniform bucket-level access disables ACLs so IAM alone controls access.
gcloud storage buckets update gs://BUCKET --uniform-bucket-level-access
Before enabling it on a bucket that uses ACLs, list what the ACLs grant and recreate legitimate access as IAM bindings, otherwise those grants silently stop working. You can revert within 90 days; after that the setting is permanent.
Enforce both org-wide
# storage-pap.yaml
name: organizations/ORG_ID/policies/storage.publicAccessPrevention
spec:
rules:
- enforce: true
---
# storage-ubla.yaml
name: organizations/ORG_ID/policies/storage.uniformBucketLevelAccess
spec:
rules:
- enforce: true
gcloud org-policies set-policy storage-pap.yaml
gcloud org-policies set-policy storage-ubla.yaml
For the few buckets that must be public (static website assets), grant an exception on one project or with a tag condition, and prefer serving them through an external Application Load Balancer with Cloud CDN, so the bucket is not the public endpoint. Also enforce storage.secureHttpTransport, which denies unencrypted HTTP to the XML API.
Console: Cloud Storage > Buckets > bucket > Permissions.
Grant access precisely
With IAM as the only mechanism, the usual least-privilege rules apply (see IAM):
- Grant at bucket level, not project level. A project-level
roles/storage.objectViewerreads every bucket in the project, including ones created next year. - Use the narrow predefined roles.
roles/storage.objectViewer(read),roles/storage.objectCreator(write without overwrite or delete),roles/storage.objectUser(read, write, delete), androles/storage.adminonly for administrators. - Use IAM Conditions for prefixes:
gcloud storage buckets add-iam-policy-binding gs://shared-exports \
--member="serviceAccount:partner-sync@prj-website-prod.iam.gserviceaccount.com" \
--role="roles/storage.objectViewer" \
--condition='expression=resource.name.startsWith("projects/_/buckets/shared-exports/objects/partner-a/"),title=partner-a-prefix'
Signed URLs and HMAC keys
Signed URLs give time-limited access to one object without an IAM grant. Keep their lifetime short and sign through the IAM Credentials API by impersonating the service account, rather than with a downloaded key:
gcloud storage sign-url gs://shared-exports/partner-a/report.csv \
--duration=15m \
--impersonate-service-account=signer@prj-website-prod.iam.gserviceaccount.com
HMAC keys provide S3-compatible access and are long-lived secrets tied to a service account. Inventory and remove the ones you do not need:
gcloud storage hmac list --project=PROJECT_ID
gcloud storage hmac update ACCESS_ID --deactivate
gcloud storage hmac delete ACCESS_ID
Where nobody needs HMAC, block it org-wide with storage.restrictAuthTypes and the value in:ALL_HMAC_SIGNED_REQUESTS.
Protect against deletion and ransomware
An attacker with write access, or a broken script, can delete or overwrite data. Layer these features:
Soft delete keeps deleted objects (and deleted buckets) recoverable for a window. New buckets get seven days by default. Lengthen it for important data, and set an org-wide floor with storage.softDeletePolicySeconds (or the managed storage.managed.softDeletePolicySeconds):
gcloud storage buckets update gs://BUCKET --soft-delete-duration=30d
gcloud storage objects list gs://BUCKET --soft-deleted
gcloud storage restore gs://BUCKET/path/object#GENERATION
Object versioning keeps noncurrent versions when objects are overwritten. Pair it with lifecycle rules so old versions do not pile up:
gcloud storage buckets update gs://BUCKET --versioning
Retention policies with Bucket Lock make objects undeletable until they reach a minimum age. Locking makes the policy permanent, and the bucket cannot be deleted while it holds retained objects. Use it for log sink buckets (CIS 2.4) and compliance archives:
gcloud storage buckets update gs://audit-archive --retention-period=1y
gcloud storage buckets update gs://audit-archive --lock-retention-period
Locking is irreversible: test the period on an unlocked bucket first. Object retention lock applies per-object retention, and object holds freeze individual objects during an investigation or legal hold. Backups that must survive a compromised project belong in a separate project with its own administrators, with its own retention policy.
Encrypt with customer-managed keys
All data is encrypted at rest with Google-managed keys by default. CMEK adds control: disabling or destroying the key makes data unreadable, and every key use can be logged.
gcloud storage service-agent --project=prj-website-prod --authorize-cmek=projects/prj-c-kms-prod/locations/europe-west1/keyRings/kr-storage-europe-west1/cryptoKeys/k-website-data
gcloud storage buckets update gs://BUCKET \
--default-encryption-key=projects/prj-c-kms-prod/locations/europe-west1/keyRings/kr-storage-europe-west1/cryptoKeys/k-website-data
The first command grants the project's Cloud Storage service agent roles/cloudkms.cryptoKeyEncrypterDecrypter on the key. The key location must match the bucket location. A default key applies to new objects only; rewrite existing objects to re-encrypt them. Key layout, rotation and the org policies that require CMEK are on the Cloud KMS page.
Reduce what is stored, and where
Every object you keep is something that can leak.
Lifecycle rules delete data you no longer need, such as temporary exports and noncurrent versions:
{
"rule": [
{ "action": { "type": "Delete" }, "condition": { "age": 30, "matchesPrefix": ["tmp/"] } },
{ "action": { "type": "Delete" }, "condition": { "daysSinceNoncurrentTime": 90 } }
]
}
gcloud storage buckets update gs://BUCKET --lifecycle-file=lifecycle.json
Location constraints keep data in approved regions: gcp.resourceLocations applies to new buckets. Sensitive Data Protection discovery profiles buckets and flags those containing personal data or credentials, which tells you where the strictest controls belong. And do not treat unguessable names as access control: assume attackers can guess example-backups.
Contain data with VPC Service Controls
IAM and public access prevention stop unauthorized identities. They do not stop an authorized identity, whose credentials were stolen, from copying data to an attacker's project. A VPC Service Controls perimeter with storage.googleapis.com restricted blocks that path.
Logging and detection
Admin Activity logs record bucket configuration and IAM changes and are always on. Object reads and writes are only in Data Access logs (DATA_READ, DATA_WRITE), which are off by default. Enable them for storage.googleapis.com on projects holding sensitive data by adding this to the project or folder IAM policy:
auditConfigs:
- service: storage.googleapis.com
auditLogConfigs:
- logType: DATA_READ
- logType: DATA_WRITE
Alert on bucket IAM changes (CIS 2.11):
resource.type="gcs_bucket" AND protoPayload.methodName="storage.setIamPermissions"
gcloud logging metrics create gcs-iam-changes \
--description="Cloud Storage IAM changes" \
--log-filter='resource.type="gcs_bucket" AND protoPayload.methodName="storage.setIamPermissions"'
Other queries worth an alert:
- A binding to
allUsersorallAuthenticatedUsers: addAND protoPayload.serviceData.policyDelta.bindingDeltas.member=("allUsers" OR "allAuthenticatedUsers")to the filter above. - Changes to public access prevention, retention or soft delete:
protoPayload.methodName="storage.buckets.update"on production buckets. - HMAC key creation or reactivation:
protoPayload.serviceName="storage.googleapis.com" AND protoPayload.methodName:"hmac"(the:operator is a case-insensitive substring match). - A spike of
storage.objects.getfrom one principal in Data Access logs, the signature of bulk download.
In Security Command Center, route PUBLIC_BUCKET_ACL and PUBLIC_LOG_BUCKET to an immediate notification. Logs go to the central project described on the Cloud Logging page.
Common mistakes
- Granting storage roles at project level. Every future bucket in the project inherits the grant, including the one that later holds backups.
- Enabling uniform bucket-level access without migrating ACLs. Legitimate object-level grants stop working, and the fix under pressure is often a broad project-level role.
- One public bucket for "assets" that becomes a dumping ground. Keep public buckets in their own project with a documented exception, and nothing else in them.
- Leaving HMAC keys and signed URLs with long lifetimes. Both are bearer credentials that bypass your identity provider.
- Locking a retention policy without testing. Bucket Lock cannot be undone, and a wrong period means paying to store data you cannot delete.
- Relying on soft delete as the only backup. Soft delete lives in the same bucket and project; someone with enough rights can shorten it or delete the project.
- Skipping Data Access logs on sensitive buckets. Without them, you cannot tell which objects were read after a credential leak.
References
- Public access prevention, Google Cloud documentation
- Uniform bucket-level access, Google Cloud documentation
- Soft delete, Google Cloud documentation
- Retention policies and Bucket Lock, Google Cloud documentation
- Customer-managed encryption keys for Cloud Storage, Google Cloud documentation
- CIS Google Cloud Platform Foundation Benchmark, Center for Internet Security
- T1530 Data from Cloud Storage, MITRE ATT&CK
- GCPBucketBrute, Rhino Security Labs
- OWASP Cloud-Native Application Security Top 10, OWASP
About the author
Florian AmetteSecurity engineer writing practical, benchmark-aligned guides to hardening Google Cloud organizations, projects and workloads.