Firetool

Home / Docs / Security rules

Docs

Edit Firestore and Storage security rules

See the security rules Firebase has for a Firestore database or a Storage bucket, check them for errors and deploy a change, with production confirmation and the old rules kept in the audit log.

Reading, checking, the history and the simulator work in the Free edition. Deploying needs Pro.

Open the rules

  1. In the sidebar, right-click a project (for its default database) or a database, and choose Security rules…. Or, with one of its collections open, choose Tools → Security rules….
  2. The rules open in their own tab: Firestore shows the rules of that database. Storage shows a bucket's rules; pick the bucket at the top when the project has more than one.
  3. The line above the rules says since when they're live. If nothing has been deployed yet, the box is empty and Firebase uses its defaults.
  4. Three views are at the top: Editor, History and Simulator. The editor colours keywords, methods, strings, comments, path variables and request / resource.

The emulators read rules from your project's firestore.rules and storage.rules files, so for an emulator you edit those files.

Check for errors

Edit the rules in the box (Tab indents), then choose Check. Firebase compiles them and lists any errors and warnings with their line and column; click one to go to that place. Checking saves nothing and changes nothing.

Deploy

  1. Choose Deploy (it turns on once you've changed something). The confirm reads the live rules again and shows them against the editor: only the changed lines, with a few around each. Check them and confirm.
  2. Firebase checks the rules again. If they have an error, nothing changes and the errors are listed.
  3. New rules apply to every app and user of the database or bucket, usually within a minute.

If someone changed the rules in the Firebase console or with the Firebase CLI after you opened them, Firetool doesn't deploy over their change: the confirm says so, shows their rules as the live ones and keeps Deploy off. Choose Reload, then make your edit again.

Production, read-only and Pro

Deploying rules is a change, so it follows the same rules as changing data: a project or database marked read-only refuses it, a Viewer role can only read the rules, a production project asks you to type its project ID, and a reason is asked for when your policy says so. Your Google account needs the Firebase Rules Admin role (or Owner or Editor) in the project.

History and compare

History lists the project's earlier versions of these rules, newest first, with the live one marked. Choose a version, then:

  • Compare with the editor shows the lines that differ from what's in the editor.
  • Put back in the editor loads that version into the editor. Nothing is deployed until you choose Check and Deploy as usual.

This list comes from Firebase, so it includes rules deployed from the Firebase console or the Firebase CLI.

Compare with another environment

New in 4.5.1. The Compare view shows another project's and database's live rules (or, for Storage, another bucket's) against the editor here, only the lines that differ and a few around them.

  • Put theirs in this editor copies the other side's rules into the editor here.
  • Open … with these rules opens the other side's rules in a new tab with this editor's text, to promote staging's rules to production.

Comparing reads only. Nothing goes live until you choose Deploy, with every check above. See Compare and migrate environments.

Try a request in the simulator

The Simulator asks Firebase whether a request would be allowed by the rules in the editor, deployed or not. Nothing is read or changed.

  1. Choose the request: get, list, create, update or delete, and the Document path (for Storage rules, the file path in the bucket).
  2. Choose Who: Not signed in, or Signed in with a user ID, an email and custom claims as JSON.
  3. Where it matters, give the document as stored (resource.data) and as written (request.resource.data) as JSON.
  4. Choose Test this request. Firebase answers Allowed or Denied, and lists the expressions it evaluated with their values (true or false), each linked to its line, plus any debug messages and errors.
The security rules simulator in Firetool: an update request on an orders document is Denied, with the evaluated lines shown as true or false

Put the old rules back

Every deploy is recorded in the audit log as rules.deploy, with the rules it replaced. To go back, open that entry in the audit log and choose Put back these rules…: the earlier rules open in the editor, in place of the live ones. Check them, then choose Deploy.

Questions

Does Firetool change my firestore.rules file?

No. Firetool works with the rules that are live in Firebase. If you keep your rules in a file and deploy them with the Firebase CLI, copy your change into that file too, or the next CLI deploy puts the file's version back.

Can I test a request against the rules?

Yes. The Simulator tries a get, list, create, update or delete against the rules in the editor, before you deploy them, and shows whether it's allowed and which lines decided it. It reads and changes nothing.