How to Configure Firestore User Roles
You set up firestore user roles by assigning cloud IAM permissions and writing database security rules. Cloud IAM controls backend admin tasks, while security rules check mobile and web app requests. Many engineering teams start by granting broad project roles to get their app running fast. Over time, these wide permissions let too many people read or change live production data. A single mistake by an engineer or script can wipe out key collections. How firestore user roles work in practice
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 user roles by assigning cloud IAM permissions and writing database security rules. Cloud IAM controls backend admin tasks, while security rules check mobile and web app requests. Many engineering teams start by granting broad project roles to get their app running fast. Over time, these wide permissions let too many people read or change live production data. A single mistake by an engineer or script can wipe out key collections.
How firestore user roles work in practice
Firestore splits role management into two distinct systems based on how a user connects. The first system is Google Cloud IAM, which handles team members and backend service accounts. You assign preset roles that grant read, write, or full owner rights across the database. You can also build custom roles that pick specific actions from the cloud permission list. When a developer or server runs a query, IAM checks their assigned role first.
The second system uses client security rules for people who log in through your app. These rules check the user token on every single document read or write request. You can store a role string on a user profile document or inside their token. When the app asks for a document, the rule engine reads that role value. It then allows or blocks the action based on the path and data fields. Still, backend servers and local developer tools with IAM roles bypass these client rules.
Why static role assignments fall short in production
Native roles do a great job of deciding who can connect to the database. They block unknown users and split basic read rights from full write rights. The problem starts once a trusted engineer or service account gets past that first check. Cloud IAM permissions apply to the whole database instance rather than single collections or fields.
If an engineer has a read role for debugging, they can query every single document. That means their query results will include raw emails, phone numbers, and card numbers. Native IAM cannot rewrite matched fields in results to hide sensitive user data during fixing. If an engineer needs to fix one broken record, they need a write role. That same write role lets them update or delete any other record by mistake.
User Provisioning (SCIM) + Lambda Execution Roles: architecture patterns and best practices
Continue reading? Get the full guide.
Free. No spam. Unsubscribe anytime.
Static roles also stay active all day and night unless an admin removes them by hand. Teams often share service account keys on laptops to run local scripts against production data. When multiple people use the same role or key, audit logs lose track of who ran what. You can see that a role changed a document, but not why or which script did it. Native roles decide who logs in, not what individual queries do in flight.
Steps to tighten database role access
Start by removing broad project editor and owner roles from daily developer accounts. Give each backend app its own service account with only the exact permissions it needs. Keep production data in a separate cloud project from your test and staging databases. Use short time limits when you grant write roles for human debugging tasks. Finally, review your role bindings each month to clean up old accounts and unused keys.
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
What is the difference between Cloud IAM and Firestore security rules?
Cloud IAM controls access for team members, servers, and admin scripts at the database level. Security rules control access for end users connecting from web or mobile client apps. Admin connections that use Cloud IAM bypass client security rules completely.
Can I restrict a Cloud IAM role to a single collection?
No, standard Cloud IAM roles apply across the entire database instance inside your project. You cannot use IAM alone to grant a developer read access to just one collection. Only client security rules inspect individual document paths during a request.
How do I stop engineers from seeing sensitive fields during debugging?
Native Firestore roles return the whole document whenever a user has read permissions. A read role exposes every field on that record, including emails and phone numbers. To hide specific fields, you must rewrite matched fields in results before they reach the user.
Related guides
In this post