Viggo,
I think I see what the issue is.
In the console, when you simulate a "read", it's checking when a document lookup would be allowed. In this case, your rules definitely allow the user to look up that document, so it is all green.
However, you're trying to issue a
query, and that query is not allowed by your rules. Writing security rules for Firestore queries can be tricky; our
documentation here will be useful to you. The key insight is that
rules are not filters. In this case you're issuing a query for all documents with a given organizationNumber, but your rules are checking for whether the user is in the document. What if one of the documents with that organizationNumber didn't have the user?
You'll need to modify your query so that the rules engine can guarantee that it's allowed. In this case, you will probably need to add an additional where clause to ensure the user is in the document:
db.collection("tenants").where("organizationNumber", "==", 10).where("users", "array-contains", "viggo").get()
This query is definitely safe, because we're explicitly asking for documents that contain your user id.
One additional note: there is no way to use the console to simulate a query. If you want to test your queries, I would recommend looking into the
local Firestore emulator, which is a tool you can download and run on your local machine. It does support queries, and will also give you very direct information about how your rules are being evaluated.
~Ryan
P.S.: