Python Firebase规则允许在不应写入时写入';不可能

Python Firebase规则允许在不应写入时写入';不可能,python,firebase,firebase-realtime-database,firebase-security,firebase-admin,Python,Firebase,Firebase Realtime Database,Firebase Security,Firebase Admin,我有以下数据库条目:“公司:8”: 我有以下数据库规则,它们不允许向数据库模拟写入“companys:8” { "rules": { ".read": "auth != null", ".write": "auth != null", "companies": { ".validate": "(data.exists() && (newData.val() === data.val() + 1)) ||

我有以下数据库条目:“公司:8”:

我有以下数据库规则,它们不允许向数据库模拟写入“companys:8”

{
  "rules": {
      ".read": "auth != null",
      ".write": "auth != null",
        "companies": {  
              ".validate": "(data.exists() && (newData.val() === data.val() + 1)) || (!data.exists() && newData.val() == 0)" 
        }
  }
}

但是,当我尝试使用Firebase Python SDK将“companys:20”写入数据库时(这在这些规则下也是不允许的),它可以工作:

In [1]: import firebase_admin

In [2]: from firebase_admin import credentials, db

In [3]: cred = credentials.Certificate('serviceAccountCredentials_dev_async.json
   ...: ')

In [4]: firebase_admin.initialize_app(cred, {'databaseURL': 'https://async-testi
   ...: ng.firebaseio.com/'})
Out[4]: <firebase_admin.App at 0x7fc50c00c080>

In [5]: ref = db.reference()

In [6]: ref.update({'companies': 20})
[1]中的
:导入firebase\u管理
[2]中:来自firebase_管理员导入凭据,db
[3]中:cred=credentials.Certificate('serviceAccountCredentials\u dev\u async.json
...: ')
在[4]:firebase_admin.initialize_app(cred,{'databaseURL':'https://async-testi
…:ng.firebaseio.com/'})
出[4]:
[5]中:ref=db.reference()
在[6]中:ref.update({'companys':20})

我做错了什么?

您正在使用Firebase Admin SDK,看起来像是这样。在这种情况下,没有应用安全规则,我认为甚至没有验证规则

如果出于某种原因,您必须访问Admin SDK并希望执行验证规则,则:

作为最佳实践,服务应该只能访问资源 它需要。要获得对资源的更细粒度控制,请 Firebase应用程序实例可以访问,请在应用程序中使用唯一标识符 表示您的服务的安全规则。然后设置适当的 授予服务访问所需资源的权限的规则


抓到鲍勃了!