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.
Open the Firebase console and select your project. Then, select Realtime Database, Cloud Firestore or Storage from the product navigation, then click Rules to navigate to the Rules editor. Edit your rules directly in the editor.
To set up and deploy your first set of rules, open the Rules tab in the Cloud Firestore section of the Firebase console. Write your rules in the online editor, then click Publish.
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.
You can also use deploy targets. More info can be found here.
Example
firebase target:apply storage main myproject.appspot.com myproject-eu myproject-ja
firebase.json
{
"storage": [ {
"target": "main", // "main" is the applied target name for the group of Storage buckets
"rules": "storage.main.rules" // the file that contains the shared security rules
}
]
}
firebase deploy --only storage:main
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With