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!
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.
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.
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.
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
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",
]
}
}
To deploy a new set of security rules with firebase cli
firebase deploy --only firestore:rules
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With