Search code examples
firebasefirebase-storagefirebase-securityfirebase-cli

How to deploy Firebase Storage rules to specific buckets?


I'd like to know how storage rules deployment works in Firebase.

In Firebase Storage I have 2 buckets app.appspot.com and app-mybucket. On my local machine I have a storage.rules file which looks something like this:

service firebase.storage {
  match /b/app.appspot.com/o {
    match /{allPaths=**} {
      allow read, write: if request.auth != null;
    }
  }
  match /b/app-mybucket/o {
    match /{userId}/{allPaths=**} {
      allow read, write: if request.auth.uid == userId;
    }
  }
}

When I firebase deploy --only storage these rules get sent to the default app.appshpot.com bucket and nothing seems to get sent to app-mybucket. I'd like to know of a way I can deploy rules to all buckets.


Solution

  • In your firebase.json file, you can specify something like this:

      "storage": [{
        "rules": "my-appspot.rules",
        "bucket": "app.appspot.com"
      },
      {
        "rules": "my-bucket.rules",
        "bucket": "app-mybucket"
      }]
    

    The example above uses different rules per bucket, you can use the same rules for each bucket as well if you'd like.