'Firebase functions: cloud storage triggers not working because of insufficient permissions

I have a cloud function that is triggered by updates to storage. when I deploy any function that utilises cloud storage, I get an error code 7 and an insufficient permissions message in the functions logs.

I have tried following the advice ont he above page and granted Cloud Functions Service Agent to an account I created called <PROJECT_ID>@appspot.gserviceaccount.com - I believe this is what the troubleshooting page means by "runtime service account", as that's what I've seen discussed online. I've also given it Storage Legacy Bucket Owner access.

Also the advice I've found online (like here and here) seems to be outdated as they did not work for me or invlove account naming formats that don't exist - I'm not even sure if creating a new service account as described above was the right move.

My storage rules are also completely open while I'm developing:

service firebase.storage {
  match /b/{bucket}/o {
    match /{allPaths=**} {
      allow read, write;
    }
  }
}

All other functions work fine, so it's jsut working with storage that's an issue. How do I grant the correct permissions?

EDIT: Various service accounts Various service accounts



Solution 1:[1]

crevulus was trying to access the bucket using:

storage.object().bucket('MY_BUCKET_NAME')

There was an error entering the bucket (He used the directory as the bucket name)

By using the directory as a bucket, he was trying to access a GCP bucket/resource that did not exist.

The solution was to remove the bucket part and that solved the problem.

Sources

This article follows the attribution requirements of Stack Overflow and is licensed under CC BY-SA 3.0.

Source: Stack Overflow

Solution Source
Solution 1