21

Today when I tried to update my firebase storage rules I got a message about upgrading them. How do I do that?

i  deploying storage
i  firebase.storage: checking storage.rules for compilation errors...
⚠  [W] undefined:undefined - Ruleset uses old version (version [1]). Please update to the latest version (version [2]).
✔  firebase.storage: rules file storage.rules compiled successfully
i  storage: uploading rules storage.rules...
✔  storage: released rules storage.rules to firebase.storage

My rules looks like this:

service firebase.storage {
    match /b/{bucket}/o {
        match /user-files/{uid}/{allPaths=**} {
            allow read: if resource.metadata[request.auth.uid] == "1";  // the uploading user can get a downloadURL
            allow create, update: if request.auth.uid == uid // User can only upload to the users own folder
                && request.auth.token.storageLeft >= request.resource.size
                && request.auth.token.path == request.resource.name
            allow delete: if false; // files are only deleted by cloud functions
        }
    }
}
Jørgen Rasmussen
  • 1,143
  • 14
  • 31

1 Answers1

35

To switch your rules to version 2, add this line at the top:

rules_version = "2";

To learn more about the new version of the rules language, see the documentation on getting started.

Frank van Puffelen
  • 565,676
  • 79
  • 828
  • 807
  • to the top of what? – Pablo Johnson Jul 03 '20 at 19:12
  • You need to add that line to the top of your rules definition (either in the file or in the console). If you're having trouble making that work, I'd suggest opening a new question showing what you've done. – Frank van Puffelen Jul 03 '20 at 20:42
  • 3
    The documentation is here: https://firebase.google.com/docs/firestore/security/get-started – zelig74 Jul 05 '20 at 19:03
  • 1
    Good one @zelig74, I added that link to the answer too. – Frank van Puffelen Jul 05 '20 at 21:31
  • 1
    The links in the answer as well as in comments- all point to *firestore* documentation, but the warning and question is for *storage*. I don't see anything in storage documentation about rules version 2. Any reference of what change to expect in storage rules v2? – AsifM Aug 26 '20 at 23:00
  • 1
    Ah, that is indeed the wrong link. Thanks for catching. The steps are correct for Storage though, as the language syntax and parser are shared between Storage and Firestore. So: add the line from my answer to your Storage rules and it'll use the new v2 syntax (and allow list operations). – Frank van Puffelen Aug 26 '20 at 23:08