Reputation: 23
I'm using Python on my PC to update the Realtime Database, and that Python script should be the only thing that has access to the Realtime Database, for writing at the very least.
Is there a unique 'token' for the database that I can add to the script that can give it access, and then have the rules only allow access to users with that 'token'.
My thought was to add it here, in the Firebase configuration in Python.
firebaseConfig={
"apiKey": "XXX",
"authDomain": "XXX",
"databaseURL": "XXX",
"projectId": "XXX",
"storageBucket": "XXX",
"messagingSenderId": "XXX",
"appId": "XXX",
"measurementId": "XXX"
*"Unique Token Identifier": "123.."
}
firebase = pyrebase.initialize_app(firebaseConfig)
Upvotes: 2
Views: 212
Reputation: 599491
If you only run the Python script in a trusted environment, such as your own machine, I recommend adding service account credentials to the setup.
With a service account your script runs as an administrative process that bypasses the security rules, so you can use these rules to ensure that only your script can access the database:
{
"rules": {
".read": false,
".write": false
}
}
Upvotes: 1
Reputation: 50890
You can add a database rule which allows your user account only (i.e. your UID to write data).
{
"rules": {
".read": true,
".write": "auth.uid === 'your_uid'"
}
}
These rules will allow anyone to read the data but only you to write. Make sure you change the rules as per your needs so users can only read the data that they are supposed to.
If you are not using Firebase Authentication then an alternative would be to change ".write"
to false
so no one can write to database and use Firebase Admin SDK which bypasses any security rules to write to database. Admin SDK uses service accounts instead of the public Firebase Config so write a separate script to write to database using Admin SDK and use it on your computer.
Upvotes: 2