I've met with some unexpected behaviour when trying to write my Firebase Storage security rules for an Android app.
To test a simple case, I wrote the following rules:
service firebase.storage {
match /b/<my-firebase-storage-bucket>/o {
match /{allPaths=**} {
allow read: if request.auth.uid == "mystery";
allow write: if request.auth.uid == "6EP13cYABCciskhKwMTaXYZHS5g1";
}
}
}
The effect was that I could only upload a file if I logged into my app with the authorised write uid - "6EP13cYABCciskhKwMTaXYZHS5g1" - but I could still read a file regardless of which uid I was logged in with. So it appeared that only the write rule was actually operative; the read rule was being ignored.
To test further, I rewrote the rules as:
service firebase.storage {
match /b/<my-firebase-storage-bucket>/o {
match /{allPaths=**} {
allow read: if false;
allow write: if true;
}
}
}
This allowed me to both upload and read files when logged into my app: again it seemed that only the write rule was operative.
Can anyone think of a possible explanantion for this?
putBytes()/getBytes()
andTask
listeners to detect success and failure. For both sets of rules you posted, I am able to write but get permission failures for read. Can you provide more details about what methods you are using to read/write and how you are sensing read status? – Bob SnyderStorageReference.putFile(Uri)
. This returns anUploadTask
, to which I have added anonSuccessListener
. The listener callstaskSnapshot.getDownloadUrl()
when the upload completes. The Url is sent to a "firebaseUri" field in a Realtime Database which the downloader has access to. The change in the "firebaseUri" field triggers a call topopulateViewHolder()
in aFirebaseRecyclerAdapter
, which then loads the image using Glide. The image does actually load, hence the read must have been successful. – CKP78