Firebase-tools: Saving database rules creates a new database on the emulator and applies the rules to it

Created on 16 Jun 2020  路  6Comments  路  Source: firebase/firebase-tools

[REQUIRED] Environment info

firebase-tools: 8.4.2

Platform: Windows

[REQUIRED] Test case

https://github.com/filipesilva/firebase-rtdb-loglevel

[REQUIRED] Steps to reproduce

  • git clone https://github.com/filipesilva/firebase-rtdb-loglevel
  • cd firebase-rtdb-loglevel
  • npm i
  • npm run emulators
  • open http://localhost:4000/database, see the emulator-test-1 database
  • save database.rules.json once
  • in the emulator logs in the console, see the following lines:
i  database: Change detected, updating rules for undefined...
+  database: Rules updated.

[REQUIRED] Expected behavior

The rules should be applied to emulator-test-1 and no new database should be created.

[REQUIRED] Actual behavior

The rules are applied to a new database named undefined.

You can also change the code in public/index.html if you want to verify if the rules are applied to the correct database, but I was using the same reproduction for both this and https://github.com/firebase/firebase-js-sdk/issues/3211 and since this repro doesn't actually need to run any database code, I left it as is.

emulator-suite database bug

Most helpful comment

@karlmarxlopez no this will be included in the next release.

All 6 comments

@filipesilva thanks for the super-clear reproduction! I am working on this now.

In my instance, database.rules.json is completely ignored always.

Hi @samtstern, is the fixed deployed?

@karlmarxlopez no this will be included in the next release.

@samtstern I can confirm I don't see a new database created on rules changes. I don't see any logging at all on the console though, just a newline. I stopped the emulator, ran it again, and now I see the expected logs:

i  database: Change detected, updating rules for emulator-test-1...
+  database: Rules updated.

I also see logging related to updating the database rules in firebase-debug.log:

[debug] [2020-07-10T10:44:35.547Z] database rules config:  [{"rules":"database.rules.json","instance":"emulator-test-1"}]
[debug] [2020-07-10T10:44:35.551Z] Ignoring unsupported arg: projectId {"metadata":{"emulator":{"name":"database"},"message":"Ignoring unsupported arg: projectId"}}
[debug] [2020-07-10T10:44:35.551Z] Ignoring unsupported arg: auto_download {"metadata":{"emulator":{"name":"database"},"message":"Ignoring unsupported arg: auto_download"}}
[debug] [2020-07-10T10:44:35.551Z] Ignoring unsupported arg: rules {"metadata":{"emulator":{"name":"database"},"message":"Ignoring unsupported arg: rules"}}

...

[info] i  database: Change detected, updating rules for emulator-test-1... {"metadata":{"emulator":{"name":"database"},"message":"Change detected, updating rules for emulator-test-1..."}}
[debug] [2020-07-10T10:45:14.540Z] >>> HTTP REQUEST PUT http://localhost:9000/.settings/rules.json?ns=emulator-test-1  
 {
  "rules": {
    ".read": false,
    ".write": false,
    "path":{
      ".validate": false
    }
  }
}

[debug] [2020-07-10T10:45:14.582Z] <<< HTTP RESPONSE 200 {"content-length":"15","content-type":"application/json; charset=utf-8","access-control-allow-origin":"*","cache-control":"no-cache","x-firebase-project-id":"emulator-test-1","x-firebase-project-number":"123456789","x-firebase-uuid":"a140367c-0397-46e3-85eb-8346bceaacd9"}
[info] +  database: Rules updated. {"metadata":{"emulator":{"name":"database"},"message":"Rules updated."}}

The former seem a bit weird since they are ignoring things, but maybe it's expected. The latter seems ok as those are indeed the rules I was changing.

Thanks for your work in fixing this!

@filipesilva thanks for confirming this works. The logs you're seeing are the expected behavior. We only show more verbose logs if the rules are invalid in some way.

Was this page helpful?
0 / 5 - 0 ratings