Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

How do I deploy Firebase Database Security rules using the command line?

In older versions of Firebase, we could add a rules section to our firebase.json file, and upload new security rules on every deploy.

How do we use the firebase-tools v3 command-line tools to deploy database security rules?

This page says that it's possible: "Rules for Firebase Storage"

This page hints that the command line tools can do it, but firebase --help and firebase deploy --help don't seem to hint at how to do it? (Apologies if I missed it...)

(related: where is the canonical doc for everything that can go into firebase.json? I found it on the old Firebase site, but can't find it via search on the new docs.)

Thanks!

like image 474
Seth Ladd Avatar asked Jul 08 '16 23:07

Seth Ladd


People also ask

Which command is used for deploying a Firebase hosted application?

Many common tasks, such as deploying a Firebase project, require a project directory. We set up the project directory using the Firebase init command. The project directory is usually the same directory as our source control root. After running Firebase Init, the directory contains the Firebase.

How do I create a rule for Firebase Realtime Database?

These rules are hosted on Firebase servers and are applied automatically at all times and you can change the rules of your database in Firebase console. You just have to select your project, click on the Database section on the left and select the Rules tab.

What is Firebase command line?

The Firebase CLI is a utility used to administer Firebase projects and perform tasks such as Realtime Database management tasks from the command-line of a terminal or command-prompt window. The Firebase CLI is also the method by which Firebase Cloud Functions are deployed and managed.


3 Answers

You can use firebase deploy --only database if you only want to update database rules. It will overwrite your existing rules.

You can check out Firebase CLI Reference for more info

like image 166
jpdelatorre Avatar answered Oct 01 '22 15:10

jpdelatorre


You can use firebase deploy or firebase deploy --only database from the command line, BUT most important:

Please note hereunder firebase.json format: The "rules" entry is under "database" entry.

It was taken from Firebase Sample code.

{
  "database": {
    "rules": "database-rules.json"
  },
  "hosting": {
    "public": "./",
    "ignore": [
      "firebase.json",
      "database-rules.json",
    ]
  }
}
like image 44
LiorK Avatar answered Oct 01 '22 16:10

LiorK


To deploy a new set of security rules with firebase cli

firebase deploy --only firestore:rules
like image 20
Chadly M. Avatar answered Oct 01 '22 15:10

Chadly M.