Make data public Stay organized with collections Save and categorize content based on your preferences.
This page shows you how to make objects you own readable to everyone onthe public internet and how to remove public access from your bucket. To learnhow to access data that has been made public, seeAccessing Public Data.
When an object is shared publicly, any user with knowledge of theobject URI can access the object for as long as the object is public.
Important: You cannot publicly share an object if the bucket it's stored inis subject topublic access prevention.Required roles
In order to get the required permissions for making objects publicly readable,ask your administrator to grant you the following roles for the bucket thatcontains the data you want to make public:
To make all objects in a bucket publicly readable: Storage Admin(
roles/storage.admin)To make individual objects publicly readable: Storage Object Admin(
roles/storage.objectAdmin)- If you plan on using the Google Cloud console, you'll need theStorage Admin (
roles/storage.admin) role instead of the Storage ObjectAdmin role.
- If you plan on using the Google Cloud console, you'll need theStorage Admin (
To remove public access from all objects in a bucket: Storage Admin(
roles/storage.admin)
These roles contain the permissions required to make objects public. To see theexact permissions that are required, expand theRequired permissionssection:
Required permissions
storage.buckets.getstorage.buckets.getIamPolicystorage.buckets.setIamPolicystorage.buckets.updatestorage.objects.getstorage.objects.getIamPolicystorage.objects.setIamPolicystorage.objects.update
The following permissions are only required for using theGoogle Cloud console to perform the tasks on this page:
storage.buckets.liststorage.objects.list
You might also be able to get these permissions with otherpredefined roles orcustom roles.
For instructions on granting roles on buckets, seeSet and manage IAM policies on buckets.
Make all objects in a bucket publicly readable
To make all objects in a bucket readable to everyone on the public internet,grant the principalallUsers the Storage Object Viewer(roles/storage.objectViewer) role:
roles/storage.objectViewer) role includesthe permission required to list the objects in the bucket. For a less permissiverole that only allows your users to get objects without listing them, granttheStorage Legacy Object Reader (roles/storage.legacyObjectReader) roleinstead.Console
- In the Google Cloud console, go to the Cloud StorageBuckets page.
In the list of buckets, click the name of the bucket that you want tomake public.
Select thePermissions tab near the top of the page.
In thePermissions section, click theGrant access button.
TheGrant access dialog appears.
In theNew principals field, enter
allUsers.In theSelect a role drop down, enter
Storage Object Viewerinthe filter box and select theStorage Object Viewer from thefiltered results.ClickSave.
ClickAllow public access.
Once public access has been granted, aCopy URL button appears for eachobject in thepublic access column. You can click this button to get thepublic URL for the object. The public URL is different from the linkyou get from directly right-clicking an object. Both links provideaccess to an object, but the public URL works without the user having tosign into a user account. SeeRequest endpoints for more information.
To learn how to get detailed error information about failed Cloud Storage operations in the Google Cloud console, seeTroubleshooting.
To learn how to resolve organization policy error and permission error, seeTroubleshoot making data public.Command line
Note: Cloud Shell provisions a temporary virtual machine. If you wantto upload objects to Cloud Storage or download objects fromCloud Storage, use a local development environment.In the Google Cloud console, activate Cloud Shell.
At the bottom of the Google Cloud console, aCloud Shell session starts and displays a command-line prompt. Cloud Shell is a shell environment with the Google Cloud CLI already installed and with values already set for your current project. It can take a few seconds for the session to initialize.
In your development environment, run the
buckets add-iam-policy-bindingcommand:gcloud storage buckets add-iam-policy-binding gs://BUCKET_NAME --member=allUsers --role=roles/storage.objectViewer
Where
BUCKET_NAMEis the name of the bucketwhose objects you want to make public. For example,my-bucket.
Client libraries
For more information, see theCloud StorageC++ API reference documentation. To authenticate to Cloud Storage, set up Application Default Credentials. For more information, seeSet up authentication for client libraries. For more information, see theCloud StorageC# API reference documentation. To authenticate to Cloud Storage, set up Application Default Credentials. For more information, seeSet up authentication for client libraries. For more information, see theCloud StorageGo API reference documentation. To authenticate to Cloud Storage, set up Application Default Credentials. For more information, seeSet up authentication for client libraries. For more information, see theCloud StorageJava API reference documentation. To authenticate to Cloud Storage, set up Application Default Credentials. For more information, seeSet up authentication for client libraries. For more information, see theCloud StorageNode.js API reference documentation. To authenticate to Cloud Storage, set up Application Default Credentials. For more information, seeSet up authentication for client libraries. For more information, see theCloud StoragePHP API reference documentation. To authenticate to Cloud Storage, set up Application Default Credentials. For more information, seeSet up authentication for client libraries. For more information, see theCloud StoragePython API reference documentation. To authenticate to Cloud Storage, set up Application Default Credentials. For more information, seeSet up authentication for client libraries. For more information, see theCloud StorageRuby API reference documentation. To authenticate to Cloud Storage, set up Application Default Credentials. For more information, seeSet up authentication for client libraries.C++
namespacegcs=::google::cloud::storage;using::google::cloud::StatusOr;[](gcs::Clientclient,std::stringconst&bucket_name){autocurrent_policy=client.GetNativeBucketIamPolicy(bucket_name,gcs::RequestedPolicyVersion(3));if(!current_policy)throwstd::move(current_policy).status();current_policy->set_version(3);current_policy->bindings().emplace_back(gcs::NativeIamBinding("roles/storage.objectViewer",{"allUsers"}));autoupdated=client.SetNativeBucketIamPolicy(bucket_name,*current_policy);if(!updated)throwstd::move(updated).status();std::cout <<"Policy successfully updated: " <<*updated <<"\n";}C#
usingGoogle.Apis.Storage.v1.Data;usingGoogle.Cloud.Storage.V1;usingSystem;usingSystem.Collections.Generic;publicclassMakeBucketPublicSample{publicvoidMakeBucketPublic(stringbucketName="your-unique-bucket-name"){varstorage=StorageClient.Create();Policypolicy=storage.GetBucketIamPolicy(bucketName);policy.Bindings.Add(newPolicy.BindingsData{Role="roles/storage.objectViewer",Members=newList<string>{"allUsers"}});storage.SetBucketIamPolicy(bucketName,policy);Console.WriteLine(bucketName+" is now public ");}}Go
import("context""fmt""io""cloud.google.com/go/iam""cloud.google.com/go/iam/apiv1/iampb""cloud.google.com/go/storage")// setBucketPublicIAM makes all objects in a bucket publicly readable.funcsetBucketPublicIAM(wio.Writer,bucketNamestring)error{// bucketName := "bucket-name"ctx:=context.Background()client,err:=storage.NewClient(ctx)iferr!=nil{returnfmt.Errorf("storage.NewClient: %w",err)}deferclient.Close()policy,err:=client.Bucket(bucketName).IAM().V3().Policy(ctx)iferr!=nil{returnfmt.Errorf("Bucket(%q).IAM().V3().Policy: %w",bucketName,err)}role:="roles/storage.objectViewer"policy.Bindings=append(policy.Bindings,&iampb.Binding{Role:role,Members:[]string{iam.AllUsers},})iferr:=client.Bucket(bucketName).IAM().V3().SetPolicy(ctx,policy);err!=nil{returnfmt.Errorf("Bucket(%q).IAM().SetPolicy: %w",bucketName,err)}fmt.Fprintf(w,"Bucket %v is now publicly readable\n",bucketName)returnnil}Java
importcom.google.cloud.Identity;importcom.google.cloud.Policy;importcom.google.cloud.storage.Storage;importcom.google.cloud.storage.StorageOptions;importcom.google.cloud.storage.StorageRoles;publicclassMakeBucketPublic{publicstaticvoidmakeBucketPublic(StringprojectId,StringbucketName){// The ID of your GCP project// String projectId = "your-project-id";// The ID of your GCS bucket// String bucketName = "your-unique-bucket-name";Storagestorage=StorageOptions.newBuilder().setProjectId(projectId).build().getService();PolicyoriginalPolicy=storage.getIamPolicy(bucketName);storage.setIamPolicy(bucketName,originalPolicy.toBuilder().addIdentity(StorageRoles.objectViewer(),Identity.allUsers())// All users can view.build());System.out.println("Bucket "+bucketName+" is now publicly readable");}}Node.js
/** * TODO(developer): Uncomment the following lines before running the sample. */// The ID of your GCS bucket// const bucketName = 'your-unique-bucket-name';// Imports the Google Cloud client libraryconst{Storage}=require('@google-cloud/storage');// Creates a clientconststorage=newStorage();asyncfunctionmakeBucketPublic(){awaitstorage.bucket(bucketName).makePublic();console.log(`Bucket${bucketName} is now publicly readable`);}makeBucketPublic().catch(console.error);PHP
use Google\Cloud\Storage\StorageClient;/** * Update the specified bucket's IAM configuration to make it publicly accessible. * * @param string $bucketName The name of your Cloud Storage bucket. * (e.g. 'my-bucket') */function set_bucket_public_iam(string $bucketName): void{ $storage = new StorageClient(); $bucket = $storage->bucket($bucketName); $policy = $bucket->iam()->policy(['requestedPolicyVersion' => 3]); $policy['version'] = 3; $role = 'roles/storage.objectViewer'; $members = ['allUsers']; $policy['bindings'][] = [ 'role' => $role, 'members' => $members ]; $bucket->iam()->setPolicy($policy); printf('Bucket %s is now public', $bucketName);}Python
fromtypingimportListfromgoogle.cloudimportstoragedefset_bucket_public_iam(bucket_name:str="your-bucket-name",members:List[str]=["allUsers"],):"""Set a public IAM Policy to bucket"""# bucket_name = "your-bucket-name"storage_client=storage.Client()bucket=storage_client.bucket(bucket_name)policy=bucket.get_iam_policy(requested_policy_version=3)policy.bindings.append({"role":"roles/storage.objectViewer","members":members})bucket.set_iam_policy(policy)print(f"Bucket{bucket.name} is now publicly readable")Ruby
defset_bucket_public_iambucket_name:# The ID of your GCS bucket# bucket_name = "your-unique-bucket-name"require"google/cloud/storage"storage=Google::Cloud::Storage.newbucket=storage.bucketbucket_namebucket.policydo|p|p.add"roles/storage.objectViewer","allUsers"endputs"Bucket#{bucket_name} is now publicly readable"end
Terraform
You can use aTerraform resource to make all objects in abucket public.
# Make bucket publicresource "google_storage_bucket_iam_member" "member" { provider = google bucket = google_storage_bucket.default.name role = "roles/storage.objectViewer" member = "allUsers"}REST APIs
JSON API
Have gcloud CLIinstalled and initialized, which lets you generate an access token for the
Authorizationheader.Create a JSON file that contains the following information:
{"bindings":[{"role":"roles/storage.objectViewer","members":["allUsers"]}]}
Use
cURLto call theJSON API with aPUTBucket request:curl -X PUT --data-binary @JSON_FILE_NAME \ -H "Authorization: Bearer $(gcloud auth print-access-token)" \ -H "Content-Type: application/json" \ "https://storage.googleapis.com/storage/v1/b/BUCKET_NAME/iam"
Where:
JSON_FILE_NAMEis the path for the filethat you created in Step 2.BUCKET_NAMEis the name of the bucketwhose objects you want to make public. For example,my-bucket.
XML API
Making all objects in a bucket publicly readable is not supported bythe XML API. Use the Google Cloud console orgcloud storage.
Make a portion of a bucket publicly readable
Important: To complete this task, the target bucket must useuniform bucket-level access. If uniform bucket-level access is disabled forthe bucket, you canenable it, or you can useaccess control lists (ACLs) instead to grant access to individual objects.Use amanaged folder to control access to objects whose name prefix matchthe name of the managed folder. For example, a managed folder namedmy-foldercan be used to control access to objects namedmy-folder/cats.jpg andmy-folder/dogs.jpg.
To make such objects publicly accessible, first create the managed folder, andthen set an IAM policy on the folder that grantsallUsers theStorage Object Viewer (roles/storage.objectViewer) role:
Console
- In the Google Cloud console, go to the Cloud StorageBuckets page.
Click the name of the bucket that contains the objects you want tomake public.
Create a folder, using the following steps:
Click theCreate folder button.
Enter theName for the folder. Once the folder is converted to amanaged folder, objects whose name start with this name will besubject to IAM roles set on the folder.
ClickCreate.
Convert the folder to a managed folder, using the following steps:
In the pane that shows the bucket's contents, find the name of thefolder you created, and click theMore options icon.
ClickEdit access.
In the window that appears, clickEnable.
Add an IAM policy to the folder that grants
allUserstheStorage Object Viewer (roles/storage.objectViewer) role, using thefollowing steps:If thePermissions pane for your managed folder isn't alreadyopen, click theMore options icon for the managedfolder, and then clickEdit access.
In thePermissions pane, click theAdd principalbutton.
In theNew principals field, enter
allUsers.In theSelect a role drop down, enter
Storage Object Viewerin the filter box, and selectStorage Object Viewer from thefiltered results.ClickSave.
ClickAllow public access.
Once public access has been granted, aCopy URL button appears for eachapplicable object in thepublic access column. You can click this buttonto get the public URL for the object. The public URL is different from thelink you get from directly right-clicking an object. Both links provideaccess to an object, but the public URL works without the user having tosign into a user account. SeeRequest endpoints for more information.
To learn how to get detailed error information about failed Cloud Storage operations in the Google Cloud console, seeTroubleshooting.
To learn how to resolve organization policy error and permission error, seeTroubleshoot making data public.Command line
Note: Cloud Shell provisions a temporary virtual machine. If youwant to upload objects to Cloud Storage or download objects fromCloud Storage, use a local development environment.In the Google Cloud console, activate Cloud Shell.
At the bottom of the Google Cloud console, aCloud Shell session starts and displays a command-line prompt. Cloud Shell is a shell environment with the Google Cloud CLI already installed and with values already set for your current project. It can take a few seconds for the session to initialize.
In your development environment, create a managed folder using the
gcloud storage managed-folders createcommand:gcloud storage managed-folders create gs://BUCKET_NAME/MANAGED_FOLDER_NAME/
Where:
BUCKET_NAMEis the name of the bucket in whichyou want to create a managed folder. For example,my-bucket.MANAGED_FOLDER_NAMEis the name of the managedfolder you want to create. For example,my-managed-folder.
In your development environment, add
allUsersto the managed folder'sIAM policy using thegcloud storage managed-folders add-iam-policy-bindingcommand:gcloud storage managed-folders add-iam-policy-binding gs://BUCKET_NAME/MANAGED_FOLDER_NAME --member=allUsers --role=roles/storage.objectViewer
Where:
BUCKET_NAMEis the name of the bucketcontaining the managed folder you're adding the IAMpolicy to. For example,my-bucket.MANAGED_FOLDER_NAMEis the name of the managedfolder that you want to add public access to. For example,my-managed-folder.
REST APIs
JSON API
Have gcloud CLIinstalled and initialized, which lets you generate an access token for the
Authorizationheader.Create a JSON file that contains the following information:
{"name":"MANAGED_FOLDER_NAME"}
Where
MANAGED_FOLDER_NAMEis the name of themanaged folder you want to create. For example,my-managed-folder.Use
cURLto call theJSON API with aInsert ManagedFolderrequest:curl -X POST --data-binary @JSON_FILE_NAME \ -H "Authorization: Bearer $(gcloud auth print-access-token)" \ -H "Content-Type: application/json" \ "https://storage.googleapis.com/storage/v1/b/BUCKET_NAME/managedFolders"
Where:
JSON_FILE_NAMEis the path for the filethat you created in the previous step.BUCKET_NAMEis the name of the bucketin which you want to create a managed folder. For example,my-bucket.
Create a JSON file that contains the following information:
{"bindings":[{"role":"roles/storage.objectViewer","members":["allUsers"]}]}
Use
cURLto call theJSON API with asetIamPolicyManagedFolder request:curl -X PUT --data-binary @JSON_FILE_NAME \ -H "Authorization: Bearer $(gcloud auth print-access-token)" \ -H "Content-Type: application/json" \ "https://storage.googleapis.com/storage/v1/b/BUCKET_NAME/managedFolders/MANAGED_FOLDER_NAME/iam"
Where:
JSON_FILE_NAMEis the path for the filethat you created in the previous step.BUCKET_NAMEis the name of the bucketcontaining the managed folder you're adding the IAMpolicy to. For example,my-bucket.MANAGED_FOLDER_NAMEis the name of themanaged folder you're adding the IAM policy to.For example,my-managed-folder.
XML API
The XML API does not support working with managed folders. Use adifferent tool, such as the Google Cloud console, or set ACLs onindividual objects usingSet Object ACL requests. The followingis an example ACL file the would grantallUsers access to an object:
<AccessControlList> <Entries> <Entry> <Scope type="AllUsers"/> <Permission>READ</Permission> </Entry> </Entries></AccessControlList>
Remove public access for all objects within a bucket
To remove public access for all objects within a bucket, remove theIAM policy that grantsallUsers the Storage Object Viewer(roles/storage.objectViewer) role:
Console
- In the Google Cloud console, go to the Cloud StorageBuckets page.
In the list of buckets, click the name of the bucket you want toremove public access from.
Select thePermissions tab.
The IAM policy that applies to the bucket appears inthePermissions section.
In theView by principals tab, select the checkbox for the
allUsersprincipal you're removing.Click the- Remove access button.
In the overlay window that appears, clickConfirm.
To learn how to get detailed error information about failed Cloud Storage operations in the Google Cloud console, seeTroubleshooting.
Command line
In the Google Cloud console, activate Cloud Shell.
At the bottom of the Google Cloud console, aCloud Shell session starts and displays a command-line prompt. Cloud Shell is a shell environment with the Google Cloud CLI already installed and with values already set for your current project. It can take a few seconds for the session to initialize.
In your development environment, run the
buckets remove-iam-policy-bindingcommand:
gcloud storage buckets remove-iam-policy-binding gs://BUCKET_NAME --member=allUsers --role=roles/storage.objectViewer
WhereBUCKET_NAME is the name of the bucket you are revoking access to. For example,my-bucket.
REST APIs
JSON
Have gcloud CLIinstalled and initialized, which lets you generate an access token for the
Authorizationheader.Get the existing policy applied to your bucket. To do so, use
cURLto call theJSON API with aGET getIamPolicyrequest:curl -X GET \-H "Authorization: Bearer $(gcloud auth print-access-token)" \"https://storage.googleapis.com/storage/v1/b/BUCKET_NAME/iam"
Where
BUCKET_NAMEis the name of the bucketwhose IAM policy you want to view. For example,my-bucket.Create a JSON file that contains the policy you retrieved in theprevious step and edit the file to remove the binding of the
allUsersprincipal from the policy.Use
cURLto call theJSON API with aPUT setIamPolicyrequest:curl -X PUT --data-binary @JSON_FILE_NAME \-H "Authorization: Bearer $(gcloud auth print-access-token)" \-H "Content-Type: application/json" \"https://storage.googleapis.com/storage/v1/b/BUCKET_NAME/iam"
Where:
JSON_FILE_NAMEis the path for the filethat you created in Step 3.BUCKET_NAMEis the name of the bucket fromwhich you want to remove access. For example,my-bucket.
What's next
- Access data that has been made public.
- Learn about moreaccess control options for your buckets and objects.
Except as otherwise noted, the content of this page is licensed under theCreative Commons Attribution 4.0 License, and code samples are licensed under theApache 2.0 License. For details, see theGoogle Developers Site Policies. Java is a registered trademark of Oracle and/or its affiliates.
Last updated 2026-02-19 UTC.