कंसोल पर जाएं

Manage and deploy Firebase Security Rules

Use the Firebase CLI

Edit and deploy Rules using the Firebase CLI. Using the CLI allows you to keep your rules under version control with your application code and deploy rules as part of your existing deployment process.

Generate a configuration file

When you configure your Firebase project using the Firebase CLI, you create a .rules configuration file in your project directory. Use the following command to start configuring your Firebase project:

Cloud Firestore

// Set up Firestore in your project directory, creates a .rules file
firebase init firestore

Realtime Database

// Set up Realtime Database in your project directory, creates a .rules file
firebase init database

Storage

// Set up Storage in your project directory, creates a .rules file
firebase init storage

Edit and update your rules

Edit your rules directly in the .rules configuration file. Make sure that any edits you make in the Firebase CLI are reflected in the Firebase console, or that you consistently make updates using either the Firebase console or the Firebase CLI. Otherwise, you might overwrite any updates made in the Firebase console.

Test your updates

Use the Firebase emulator to test your updates locally and confirm that your app's Rules exhibit the behavior you want.

Deploy your updates

Once you've updated and tested your Rules, deploy them to production. Use the following commands to selectively deploy your Rules alone or deploy them as part of your normal deployment process.

Cloud Firestore

// Deploy your .rules file
firebase deploy --only firestore:rules

Realtime Database

// Deploy your .rules file
firebase deploy --only database

Storage

// Deploy your .rules file
firebase deploy --only storage

Use the Firebase console

You can also edit and deploy Rules from the Firebase console.

Edit and update your rules

  1. Open the Firebase console and select your project.
  2. Then, select Database or Storage from the product navigation.
    • Database: Select a database, then click Rules to navigate to the Rules editor.
    • Storage: Click Rules to navigate to the Rules editor.
  3. Edit your rules directly in the editor.

Test your updates

You can test your Rules behavior directly in the Firebase console, using the Rules simulator. Open the Simulator screen in the Rules editor, modify the settings and click Run. Look for the confirmation message at the top of the editor.

Deploy your updates

Once you're satisfied that your updates are what you expect, click Publish.