How to Configure Firestore PII

Published
Length
3 min read

Luis Felipe Dias

All posts

You set up firestore pii protection by splitting private fields into separate subcollections. Then you apply strict security rules and cloud roles to those document paths. Many teams start by placing all user fields into one single document. That layout causes problems when support staff or scripts need read roles. Broad roles let every query return full documents with emails and phone numbers. How native firestore pii rules work In this document database, reads always return the whole docume

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 pii protection by splitting private fields into separate subcollections. Then you apply strict security rules and cloud roles to those document paths. Many teams start by placing all user fields into one single document. That layout causes problems when support staff or scripts need read roles. Broad roles let every query return full documents with emails and phone numbers.

How native firestore pii rules work

In this document database, reads always return the whole document at once. Security rules cannot hide just one or two fields inside a single document. If a user can read a document, they receive every field inside it. Because of this design, you must change how you store your data.

Teams solve this by splitting each user record into two separate parts. You put safe fields into a main collection for normal app use. Then you put emails, phone numbers, and card numbers into a private subcollection. You write security rules that block normal users from reading that private path.

Mobile and web apps use these security rules to check every client request. Still, backend servers and admin scripts do not use those client rules. Instead, backend tools use cloud identity roles to log in and run queries. A cloud role grants read or write power across the whole database project.

What native setup solves and what it misses

Splitting documents works well for client apps that follow your security rules. It stops regular app users from pulling private subcollections to their phones. Cloud roles also help you control which backend services can log in. You can block unknown servers from connecting to your cloud project at all.

Still, cloud identity roles only decide who can log in to the database. They do not filter what individual queries or scripts do during a session. Once an engineer or script logs in with a read role, rules stop. That admin role bypasses document security rules and reads every collection in full.

This leaves a big gap during live debugging and support tasks. A developer who checks a bug in production can read private subcollections. If a query pulls a private document, raw card numbers show up on screen. Native roles cannot rewrite matched fields in results while a query runs.

End-to-End Encryption + PII in Logs Prevention: architecture patterns and best practices

Continue reading? Get the full guide.

Free. No spam. Unsubscribe anytime.

Why document splitting adds extra work for teams

Keeping private fields in separate subcollections also makes app code harder to maintain. Every time your app needs both safe and private data, it runs two reads. Extra document reads add delay to your app and raise your monthly cloud bill. Developers must also write extra code to keep both documents in sync.

Schema changes create another risk when teams build new features fast. A developer might add a phone number field to the main public document. Because the main document has broad read rules, that field is now exposed. Native roles do not check document contents to catch misplaced national IDs or emails.

Audit logs also have limits when you rely only on cloud identity roles. Cloud logs can show that a service account ran a read request. When five engineers share one support role, logs miss who ran the query. You also need a way to mask sensitive fields in results during live sessions.

Check database and API queries on the wire

Identity tools, roles, and network rules decide who opens a session. Setup alone cannot check what each query does or mask sensitive values in a response once a session starts. When workflows touch Postgres, MySQL, SQL Server, MongoDB, ClickHouse, Kubernetes APIs, SSH, or internal HTTP APIs, hoop.dev sits inline in the wire protocol beside those services as an open-source proxy, a sidecar for your Postgres or API. On every query an AI agent or engineer runs against production, hoop.dev decides to pass, mask, block, or hold it for human review.

Your login details and client tools stay as they are while hoop.dev guardrails refuse bad deletes or drops before they run, and hoop.dev data masking rewrites matched sensitive values in responses in memory. Furthermore, hoop.dev holds SOC 2 Type II, is MIT licensed, and writes every query and decision to an audit trail that generates evidence for HIPAA, GDPR, and PCI DSS. See the source on GitHub.

Frequently asked questions

Can security rules hide one field inside a document?

No, document reads always return the entire document or nothing at all. To protect a field with native rules, you must move it to a separate collection.

Do backend admin SDKs follow document security rules?

No, backend SDKs that use cloud service roles bypass client security rules. They rely on cloud identity roles, which usually grant broad access across collections.

What fields should go into a private subcollection?

You should move high-risk data like emails, phone numbers, card numbers, and national IDs. Keep only basic profile data in the main collection that general users read.

The query runs. The emails stay hidden.