简体   繁体   中英

Firebase Storage rule different for a specific folder

I have a firebase storage bucket with this hierarchy eg

-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

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
}

The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM