Allow Public Read access on a GCS bucket?
M

7

50

I am trying to allow anonymous (or just from my applications domain) read access for files in my bucket.

When trying to read the files I get

```

<Error>
    <Code>AccessDenied</Code>
    <Message>Access denied.</Message>
    <Details>
        Anonymous users does not have storage.objects.get access to object.
    </Details>
</Error>

```

I also tried to add a domain with the object default permissions dialog in the google cloud console. that gives me the error "One of your permissions is invalid. Make sure that you enter an authorized id or email for the groups and users and a domain for the domains"

I have also looked into making the ACL for the bucket public-read. My only problem with this is that it removes my ownership over the bucket. I need to have that ownership since I want to allow uploading from a specific Google Access Id.

Mcdowell answered 25/10, 2016 at 5:45 Comment(0)
M
46

You can use gsutil to make new objects created in the bucket publicly readable without removing your ownership. To make new objects created in the bucket publicly readable:

gsutil defacl ch -u AllUsers:R gs://yourbucket

If you have existing objects in the bucket that you want to make publicly readable, you can run:

gsutil acl ch -u AllUsers:R gs://yourbucket/**

Mastaba answered 25/10, 2016 at 20:6 Comment(2)
Thank you. What about restricting to a domain?Palmation
You can use domains: see "gsutil help acl ch". In particular, see the section that says: Groups may also be specified as as a full domain, as in "-g my-company.com:r"Mastaba
K
51

You can also do it from the console.
https://console.cloud.google.com/storage/
Choose edit the bucket permissions:
Input "allUsers" in Add Members option and "Storage Object Viewer" as the role. Then go to "Select a role" and set "Storage" and "Storage Object Legacy" to "Storage Object View"

GCS bucket access

Kisung answered 13/4, 2018 at 5:34 Comment(1)
yeAH, Christ! It was telling it was using uniform permission and that the bucket was public but not working. Had to add allUsers and give view optionsThwack
M
46

You can use gsutil to make new objects created in the bucket publicly readable without removing your ownership. To make new objects created in the bucket publicly readable:

gsutil defacl ch -u AllUsers:R gs://yourbucket

If you have existing objects in the bucket that you want to make publicly readable, you can run:

gsutil acl ch -u AllUsers:R gs://yourbucket/**

Mastaba answered 25/10, 2016 at 20:6 Comment(2)
Thank you. What about restricting to a domain?Palmation
You can use domains: see "gsutil help acl ch". In particular, see the section that says: Groups may also be specified as as a full domain, as in "-g my-company.com:r"Mastaba
B
12

Using IAM roles, to make the files readable, and block listing:

gsutil iam ch allUsers:legacyObjectReader gs://bucket-name

To make the files readable, and allow listing:

gsutil iam ch allUsers:objectViewer gs://bucket-name
Banket answered 7/7, 2018 at 17:23 Comment(2)
Is there a benefit of using IAM over ACLs? I'm not familiar with their differences, yet.Auriferous
Also, since this is the recommended approach by Google, you might provide the link: cloud.google.com/storage/docs/access-control/…Auriferous
F
8
  1. Open the Cloud Storage browser in the Google Cloud Platform Console.
  2. In the list of buckets, click on the name of the bucket that contains the object you want to make public, and navigate to the object if it's in a subdirectory.
  3. Click the drop-down menu associated with the object that you want to make public.
  4. The drop-down menu appears as three vertical dots to the far right of the object's row.
  5. Select Edit permissions from the drop-down menu.
  6. In the overlay that appears, click the + Add item button.
  7. Add a permission for allUsers.

    • Select User for the Entity.
    • Enter allUsers for the Name.
    • Select Reader for the Access.
    • Click Save.
  8. Once shared publicly, a link icon appears in the public access column. You can click on this icon to get the URL for the object.

Instruction on Making Data Public from Google Cloud Docs

Frerichs answered 28/11, 2018 at 18:53 Comment(0)
C
3

If you upload files in firebase functions you'll need to call makePublic() on the reference object in order to make it accessible without passing token.

Cubby answered 1/5, 2019 at 9:12 Comment(0)
F
2

Apr, 2022 Update:

You can allow all users to read files in your bucket on Cloud Storage.

First, in Bucket details, click on "PERMISSIONS" then "ADD":

enter image description here

Then, type "allUsers":

enter image description here

Then, select the role "Storage Legacy Object Reader" so that all users can read files:

enter image description here

Then, click on "SAVE":

enter image description here

Then, you should be asked as shown below so click on "ALLOW PUBLIC ACCESS":

enter image description here

Finally, you can allow all users to read files in your bucket:

enter image description here

Furan answered 26/4, 2022 at 16:45 Comment(0)
S
0

If you want to allow specific bucket to be accessible with the specific "folder/content" then you have to specify in the command: gsutil iam -r ch allUsers:legacyObjectReader gs://your-bucket/your-files/**

  • But this is for specific content inside a bucket that is not public!
Schenk answered 29/10, 2019 at 16:6 Comment(0)

© 2022 - 2024 — McMap. All rights reserved.