How to Configure Firestore Row Level Security
You set up firestore row level security by writing rules that check user tokens against document fields. Since the database uses documents instead of rows, rules control read and write calls per document. Most teams start with broad test rules that let any logged-in user read all collections. Broad rules expose private user records when someone queries a collection directly from a web app. How firestore row level security works with document rules In a standard relational database, you attach
Your coding agents run with your access.
Claude Code reaches prod with a developer's credentials, and approval prompts get clicked through. hoop.dev checks every query, masks sensitive data, and holds risky changes for a human.
You set up firestore row level security by writing rules that check user tokens against document fields. Since the database uses documents instead of rows, rules control read and write calls per document. Most teams start with broad test rules that let any logged-in user read all collections. Broad rules expose private user records when someone queries a collection directly from a web app.
How firestore row level security works with document rules
In a standard relational database, you attach policies to rows in a table. In this document database, each document acts like a single row of data. You define access logic inside a central rules file that sits in front of your collections. When a client app sends a request, the engine checks the path and the user token.
Every logged-in user receives a signed token from the login service. This token holds a unique user ID and any custom role claims you add. Your rule compares that token ID with an owner field stored inside the target document. If the two values match, the database allows the read or write request to finish.
You can also check data inside other documents before you allow an action. For example, a rule can look up a team membership document to verify a user role. This lookup lets you build group permissions across nested subcollections. Still, rules do not filter data on their own during a broad query. If a query asks for ten documents and one fails the rule, the whole request fails. The client app must include matching filter clauses in every query it sends.
Why document rules do not stop broad backend keys
Native security rules work well when mobile or web apps talk directly to the database. They force client requests to follow strict ownership checks on every single document path. They also check incoming data shapes before a user saves a new record. This stops bad actors from changing their own role fields from a browser.
Still, a large security gap opens when engineers and backend servers log in. Server SDKs and admin tools use cloud service accounts instead of standard user tokens. By design, these admin roles bypass all document security rules completely. Once a service key or engineer logs in through Cloud IAM, every collection is wide open.
Row-Level Security + End-to-End Encryption: architecture patterns and best practices
Continue reading? Get the full guide.
Free. No spam. Unsubscribe anytime.
IAM roles decide who can connect to the project, not which documents they can read. An engineer who needs to fix one broken record gets full read permissions across the database. Native rules cannot mask sensitive fields like emails, phone numbers, card numbers, or national IDs. If an admin runs a script to inspect user profiles, raw personal data returns in full. Standard cloud logs also miss the exact document paths that an admin script reads in flight. Teams need a way to inspect individual queries and rewrite sensitive fields before results return.
Best practices for document permission design
Start every rules file by denying all reads and writes across the entire database. Then open specific collection paths one by one as you build out your app features. Keep your role data in a separate collection that regular users can read but never edit. Store the owner ID directly on every document to avoid slow cross-document lookups.
Test your rules in a local emulator before you push changes to your live project. Write unit tests that try to read documents using fake tokens from other users. Split your read rules into single document fetches and collection list queries. This stops a user from listing an entire collection when they only need one record. Review your cloud IAM roles often and remove direct database permissions from human accounts.
Govern statements and responses across databases and APIs
Good config and scoped roles are needed setup. They do not check single queries in flight or mask sensitive fields in returned rows. Across Postgres, MySQL, SQL Server, MongoDB, ClickHouse, Kubernetes APIs, SSH, and internal HTTP endpoints, hoop.dev sits inline in the protocol beside each supported service as an open-source proxy, a sidecar for your database or API. For every query or command an AI agent or engineer runs against production, hoop.dev decides to pass, mask, block, or hold it for human approval.
First, hoop.dev guardrails block banned queries before they run or hold risky ones for review, and hoop.dev data masking rewrites matched sensitive values in responses in memory. Furthermore, hoop.dev holds SOC 2 Type II and is open source on GitHub.
Frequently asked questions
Does Firestore have native row level security like SQL databases?
No, it uses document-level security rules instead of SQL table policies. You write path rules that match a user token against fields inside each requested document.
Why do my queries fail when I turn on document rules?
Rules are not filters, so they reject any query that might return a forbidden document. Your app query must include a filter clause that matches the exact conditions in your rule.
Do backend admin SDKs follow document security rules?
No, backend SDKs that use cloud service accounts bypass all document rules by default. You must limit their reach through IAM roles or control their queries at runtime.
Related guides
In this post