I have a firebase storage bucket with this hierarchy e.g.
-Bucket
--UserData
--Folder A
--Folder B
--Folder C
--Folder D
I want to apply these rules for [Folder A, Folder B, Folder C, Folder D]
match /{allPaths=**} {
allow read;
allow write;
}
but for UserData folder I want to apply these rules
match /UserData/{user_id} {
allow read;
allow write: if request.auth != null && request.auth.uid == user_id;
}
in real life, I have far more folders [A,B,C,D ........] and only one folder [UserData] so it is not possible to write storage rule for each specific folders
CodePudding user response:
What you're trying to do is not supported by security rules. You would have to list out each top-level folder separately - there are no wildcards for this.
The easiest way to apply the same rules to unstructured folder content is to organize all that content under a single prefix (folder), and write the rules for that prefix. If you moved everything under EverythingElse, then you could apply a single rule to all of it recursively:
match /UserData/{user_id} {
allow read;
allow write: if request.auth != null && request.auth.uid == user_id;
}
match /EverythingElse/{allPaths=**} {
// your rules here
}