Las Te
Las Te

Reputation: 43

javascript make bucket of google cloud storage public to a specific URL or website

Firebase hosting my website. Website has a <iframe> element, it will load aaa.html from bucket in google cloud storage.

<iframe src="https://storage.googleapis.com/bucket/aaa.html" />

And aaa.html will also load other files (js files or img files) stored in the same bucket.

When I use gsutil iam ch allUsers:objectViewer gs://bucket to set bucket public and all files public, website works perfectly. But I do not want that users could link aaa.html without my website. Set bucket public is seems to be incorrect.

So, is there a way to make bucket public to a specific website?

Upvotes: 1

Views: 1305

Answers (1)

Kevin Quinzel
Kevin Quinzel

Reputation: 1428

Ok. You mentioned you don't want to make your bucket public. Singed URLs are not for you.

I think you can achieve your goal by doing the following:

  1. Define a service account with the roles and permissions you need to get the stored objects in your bucket. This service account will be used by your application.

  2. Use the GCS API to get into the stored files in your bucket. Here is how to Use a service account to call an API in your code

Hope this is helpful :D

Upvotes: 1

Related Questions