Google Cloud Storage removes entity/user after successful upload

126 Views Asked by At

I've been developing an Express/Firebase application for a few weeks now. All has worked fine until I ran into the following issue:

TypeError: firebase.storage is not a function

A quick search led me to TypeError: firebase.storage is not a function. So using the solution gathered there, I configured @google-cloud/storage succesffuly. But then, I ran into:

Caller does not have storage.objects.create access to bucket example.appspot.com

After some more googling I learned that I must manually add my firebase-admin user to the example.appspot.com bucket on https://console.cloud.google.com/storage/

enter image description here

Once that's done I test the following:

bucket.upload('./package.json')
  .then((file) => {
    console.log(file)
  })
  .catch((error) => {
    console.log(error)
  })

This works perfectly. The issue arises when I stop the Express app and rerun it to try to do the upload again which results in Caller does not have... error again. Checking the bucket permissions, I see that the user I added previously is now gone:

enter image description here

I don't know if I'm missing something here, a bug in the @google-cloud/storage package, or a bug somewhere else. Any ideas?

1

There are 1 best solutions below

0
On BEST ANSWER

GCS considers each upload to be a brand new object. If the object shares the name as an existing object, the previously-existing object will be deleted, and the new ones properties, including ACL, will have no relation to the old one.

You can fix this in a few ways. The easiest one would be to add firebase-storage to the bucket's "default object ACL", which will cause all newly created objects to have an ACL that includes that service account, unless otherwise specified. From the command-line, if you have the gcloud SDK installed, you could do this like so:

gsutil defacl ch -u [email protected]:O gs://bucketname

Another option would be to explicitly set the ACL as part of the upload or immediately afterward.