SlideShare a Scribd company logo
1 of 12
Hey yo, can I see your
firebase stuff, AUTH
course you can
An emotionally fraught memoir of database authorization
Firebase - Apps not Ops
 Not just a database it’s an entire application framework and offers….
 Hosting
 Authentication (leveraging many providers or custom email/password)
 File Storage
 Analytics
 Cloud Functions – Server Side Execution.
 Cloud Messaging – By ID, Group or subscribed to a topic
 A strong feeling of belonging
Database Authorization
 This isn’t about who you are but what it is you can do
 Often it’s managed at a user/role level in terms of SQL and can be quite
heavyweight
 Other times with NoSQL DB it can be just lacking altogether
 Firebase is lighter in all regards. It’s essentially a JSON document with some
lovely wrapping tooling around it. You don’t need to install a heavy JDBC
client or management studio to use it. Restful API or through management
console
 So it should be no surprise that setting up the Authorization is pretty lovely as
well.
 The rules we are about to see for controlling access can also put input
validation on fields and indexes for querying
Database Authorization
Example DB Rules
{"rules": {
"foo": {
".read": true,
".write": false
} }}
Or this which allows write operations as long as the value of the /allow_writes/ node is true, there is a
sibling node called ‘Admins’, and there is a child named foo in the newly written data:
"rules": {
"ruleDemo" : {
".read": "auth != null",
".write": "root.child('allow_writes').val() === true &&
newData.child('foo').exists() && data.parent().child('Admins').exists()"
}
Database Authorization
Rules Simulator
 Sandbox for testing your rules out. Try different operations and different data
 Tired of being you? Be someone different
 Spoof authentication to show what happens if you are a certain user
Rules Simulator
Syntax – Helper Methods
 References ala DOM operations (root/child)
 Variables Auth Object including UserID. Below compares it to a variable.
"users": {
"$uid": {
".write": "$uid === auth.uid"
}
 Existing Data vs New Data
// we can write as long as old data or new data does not exist
// in other words, if this is a delete or a create, but not an update
".write": "!data.exists() || !newData.exists()"
Rules as Filters
 Let’s say our successful website selling erotic cakes and other less erotic baked goods is doing
well. We would like for users to be able to only view products which are suitable for work
 We could just write a rule that let’s us do that and then query Products right… NO! Cries and
runs away
 .read and .write rules work from top-down, with shallower rules overriding deeper rules. If
a rule grants read or write permissions at a particular path, then it also grants access to all
child nodes under it.
 Deny by Default so unless we have an explicit rule on /Products we can’t view it even if we
can view 100% of it’s children
Rules not as Filters then fine
 RULES ARE NOT FILTERS says google in a kind of passive aggressive way
https://firebase.google.com/docs/database/security/securing-
data#rules_are_not_filters
 You need to restructure your data and reprioritise your life
 All Public or All Private
Summary
 Firebase allows you to put fine grained control on your data in a nice
declarative way
 You can use helper methods and functions to do some neat things
 You can use the simulator to test your rules after you’ve set them
 Do not use Rules as Filters. It doesn’t work like that but there’s ways around
it
 Firebase got me like
Resources
 https://firebase.google.com/docs/database/security/
 https://www.youtube.com/watch?v=DBKB6r5BFqo
 https://www.youtube.com/watch?v=PUBnlbjZFAI&t=771s
 https://www.youtube.com/watch?v=rtoxRg-kbt0
 https://www.youtube.com/watch?v=6sIZvHOEw6Q

More Related Content

Similar to Firebase Authorization

Effective Test Driven Database Development
Effective Test Driven Database DevelopmentEffective Test Driven Database Development
Effective Test Driven Database Development
elliando dias
 
need help completing week 6 ilab.. i will upload what I currently ha.docx
need help completing week 6 ilab.. i will upload what I currently ha.docxneed help completing week 6 ilab.. i will upload what I currently ha.docx
need help completing week 6 ilab.. i will upload what I currently ha.docx
niraj57
 
Deferred Processing in Ruby - Philly rb - August 2011
Deferred Processing in Ruby - Philly rb - August 2011Deferred Processing in Ruby - Philly rb - August 2011
Deferred Processing in Ruby - Philly rb - August 2011
rob_dimarco
 
Data access best practices
Data access best practicesData access best practices
Data access best practices
Gieno Miao
 
Cis407 a ilab 6 web application development devry university
Cis407 a ilab 6 web application development devry universityCis407 a ilab 6 web application development devry university
Cis407 a ilab 6 web application development devry university
lhkslkdh89009
 

Similar to Firebase Authorization (20)

Effective Test Driven Database Development
Effective Test Driven Database DevelopmentEffective Test Driven Database Development
Effective Test Driven Database Development
 
BP-6 Repository Customization Best Practices
BP-6 Repository Customization Best PracticesBP-6 Repository Customization Best Practices
BP-6 Repository Customization Best Practices
 
Creating Truly RESTful APIs
Creating Truly RESTful APIsCreating Truly RESTful APIs
Creating Truly RESTful APIs
 
Spring Security 3
Spring Security 3Spring Security 3
Spring Security 3
 
Drupal Views development
Drupal Views developmentDrupal Views development
Drupal Views development
 
Firebasics
FirebasicsFirebasics
Firebasics
 
need help completing week 6 ilab.. i will upload what I currently ha.docx
need help completing week 6 ilab.. i will upload what I currently ha.docxneed help completing week 6 ilab.. i will upload what I currently ha.docx
need help completing week 6 ilab.. i will upload what I currently ha.docx
 
Sql
SqlSql
Sql
 
Sql
SqlSql
Sql
 
DP-900.pdf
DP-900.pdfDP-900.pdf
DP-900.pdf
 
Introduction to servlet
Introduction to servletIntroduction to servlet
Introduction to servlet
 
Behaviour Driven Development
Behaviour Driven DevelopmentBehaviour Driven Development
Behaviour Driven Development
 
Java Web Programming on Google Cloud Platform [2/3] : Datastore
Java Web Programming on Google Cloud Platform [2/3] : DatastoreJava Web Programming on Google Cloud Platform [2/3] : Datastore
Java Web Programming on Google Cloud Platform [2/3] : Datastore
 
Search
SearchSearch
Search
 
Deferred Processing in Ruby - Philly rb - August 2011
Deferred Processing in Ruby - Philly rb - August 2011Deferred Processing in Ruby - Philly rb - August 2011
Deferred Processing in Ruby - Philly rb - August 2011
 
Leveraging JavaScript Promises and the Bulk API
Leveraging JavaScript Promises and the Bulk APILeveraging JavaScript Promises and the Bulk API
Leveraging JavaScript Promises and the Bulk API
 
Data access best practices
Data access best practicesData access best practices
Data access best practices
 
Azure data factory security
Azure data factory securityAzure data factory security
Azure data factory security
 
Cis407 a ilab 6 web application development devry university
Cis407 a ilab 6 web application development devry universityCis407 a ilab 6 web application development devry university
Cis407 a ilab 6 web application development devry university
 
Slick Data Sharding: Slides from DrupalCon London
Slick Data Sharding: Slides from DrupalCon LondonSlick Data Sharding: Slides from DrupalCon London
Slick Data Sharding: Slides from DrupalCon London
 

Recently uploaded

Artificial Intelligence: Facts and Myths
Artificial Intelligence: Facts and MythsArtificial Intelligence: Facts and Myths
Artificial Intelligence: Facts and Myths
Joaquim Jorge
 

Recently uploaded (20)

Scaling API-first – The story of a global engineering organization
Scaling API-first – The story of a global engineering organizationScaling API-first – The story of a global engineering organization
Scaling API-first – The story of a global engineering organization
 
2024: Domino Containers - The Next Step. News from the Domino Container commu...
2024: Domino Containers - The Next Step. News from the Domino Container commu...2024: Domino Containers - The Next Step. News from the Domino Container commu...
2024: Domino Containers - The Next Step. News from the Domino Container commu...
 
Partners Life - Insurer Innovation Award 2024
Partners Life - Insurer Innovation Award 2024Partners Life - Insurer Innovation Award 2024
Partners Life - Insurer Innovation Award 2024
 
Repurposing LNG terminals for Hydrogen Ammonia: Feasibility and Cost Saving
Repurposing LNG terminals for Hydrogen Ammonia: Feasibility and Cost SavingRepurposing LNG terminals for Hydrogen Ammonia: Feasibility and Cost Saving
Repurposing LNG terminals for Hydrogen Ammonia: Feasibility and Cost Saving
 
Exploring the Future Potential of AI-Enabled Smartphone Processors
Exploring the Future Potential of AI-Enabled Smartphone ProcessorsExploring the Future Potential of AI-Enabled Smartphone Processors
Exploring the Future Potential of AI-Enabled Smartphone Processors
 
TrustArc Webinar - Unlock the Power of AI-Driven Data Discovery
TrustArc Webinar - Unlock the Power of AI-Driven Data DiscoveryTrustArc Webinar - Unlock the Power of AI-Driven Data Discovery
TrustArc Webinar - Unlock the Power of AI-Driven Data Discovery
 
Bajaj Allianz Life Insurance Company - Insurer Innovation Award 2024
Bajaj Allianz Life Insurance Company - Insurer Innovation Award 2024Bajaj Allianz Life Insurance Company - Insurer Innovation Award 2024
Bajaj Allianz Life Insurance Company - Insurer Innovation Award 2024
 
Automating Google Workspace (GWS) & more with Apps Script
Automating Google Workspace (GWS) & more with Apps ScriptAutomating Google Workspace (GWS) & more with Apps Script
Automating Google Workspace (GWS) & more with Apps Script
 
🐬 The future of MySQL is Postgres 🐘
🐬  The future of MySQL is Postgres   🐘🐬  The future of MySQL is Postgres   🐘
🐬 The future of MySQL is Postgres 🐘
 
Strategies for Unlocking Knowledge Management in Microsoft 365 in the Copilot...
Strategies for Unlocking Knowledge Management in Microsoft 365 in the Copilot...Strategies for Unlocking Knowledge Management in Microsoft 365 in the Copilot...
Strategies for Unlocking Knowledge Management in Microsoft 365 in the Copilot...
 
Data Cloud, More than a CDP by Matt Robison
Data Cloud, More than a CDP by Matt RobisonData Cloud, More than a CDP by Matt Robison
Data Cloud, More than a CDP by Matt Robison
 
ProductAnonymous-April2024-WinProductDiscovery-MelissaKlemke
ProductAnonymous-April2024-WinProductDiscovery-MelissaKlemkeProductAnonymous-April2024-WinProductDiscovery-MelissaKlemke
ProductAnonymous-April2024-WinProductDiscovery-MelissaKlemke
 
HTML Injection Attacks: Impact and Mitigation Strategies
HTML Injection Attacks: Impact and Mitigation StrategiesHTML Injection Attacks: Impact and Mitigation Strategies
HTML Injection Attacks: Impact and Mitigation Strategies
 
Artificial Intelligence: Facts and Myths
Artificial Intelligence: Facts and MythsArtificial Intelligence: Facts and Myths
Artificial Intelligence: Facts and Myths
 
Boost PC performance: How more available memory can improve productivity
Boost PC performance: How more available memory can improve productivityBoost PC performance: How more available memory can improve productivity
Boost PC performance: How more available memory can improve productivity
 
Strategize a Smooth Tenant-to-tenant Migration and Copilot Takeoff
Strategize a Smooth Tenant-to-tenant Migration and Copilot TakeoffStrategize a Smooth Tenant-to-tenant Migration and Copilot Takeoff
Strategize a Smooth Tenant-to-tenant Migration and Copilot Takeoff
 
A Domino Admins Adventures (Engage 2024)
A Domino Admins Adventures (Engage 2024)A Domino Admins Adventures (Engage 2024)
A Domino Admins Adventures (Engage 2024)
 
Real Time Object Detection Using Open CV
Real Time Object Detection Using Open CVReal Time Object Detection Using Open CV
Real Time Object Detection Using Open CV
 
presentation ICT roal in 21st century education
presentation ICT roal in 21st century educationpresentation ICT roal in 21st century education
presentation ICT roal in 21st century education
 
Workshop - Best of Both Worlds_ Combine KG and Vector search for enhanced R...
Workshop - Best of Both Worlds_ Combine  KG and Vector search for  enhanced R...Workshop - Best of Both Worlds_ Combine  KG and Vector search for  enhanced R...
Workshop - Best of Both Worlds_ Combine KG and Vector search for enhanced R...
 

Firebase Authorization

  • 1. Hey yo, can I see your firebase stuff, AUTH course you can An emotionally fraught memoir of database authorization
  • 2. Firebase - Apps not Ops  Not just a database it’s an entire application framework and offers….  Hosting  Authentication (leveraging many providers or custom email/password)  File Storage  Analytics  Cloud Functions – Server Side Execution.  Cloud Messaging – By ID, Group or subscribed to a topic  A strong feeling of belonging
  • 3. Database Authorization  This isn’t about who you are but what it is you can do  Often it’s managed at a user/role level in terms of SQL and can be quite heavyweight  Other times with NoSQL DB it can be just lacking altogether  Firebase is lighter in all regards. It’s essentially a JSON document with some lovely wrapping tooling around it. You don’t need to install a heavy JDBC client or management studio to use it. Restful API or through management console  So it should be no surprise that setting up the Authorization is pretty lovely as well.  The rules we are about to see for controlling access can also put input validation on fields and indexes for querying
  • 4. Database Authorization Example DB Rules {"rules": { "foo": { ".read": true, ".write": false } }} Or this which allows write operations as long as the value of the /allow_writes/ node is true, there is a sibling node called ‘Admins’, and there is a child named foo in the newly written data: "rules": { "ruleDemo" : { ".read": "auth != null", ".write": "root.child('allow_writes').val() === true && newData.child('foo').exists() && data.parent().child('Admins').exists()" }
  • 6. Rules Simulator  Sandbox for testing your rules out. Try different operations and different data  Tired of being you? Be someone different  Spoof authentication to show what happens if you are a certain user
  • 8. Syntax – Helper Methods  References ala DOM operations (root/child)  Variables Auth Object including UserID. Below compares it to a variable. "users": { "$uid": { ".write": "$uid === auth.uid" }  Existing Data vs New Data // we can write as long as old data or new data does not exist // in other words, if this is a delete or a create, but not an update ".write": "!data.exists() || !newData.exists()"
  • 9. Rules as Filters  Let’s say our successful website selling erotic cakes and other less erotic baked goods is doing well. We would like for users to be able to only view products which are suitable for work  We could just write a rule that let’s us do that and then query Products right… NO! Cries and runs away  .read and .write rules work from top-down, with shallower rules overriding deeper rules. If a rule grants read or write permissions at a particular path, then it also grants access to all child nodes under it.  Deny by Default so unless we have an explicit rule on /Products we can’t view it even if we can view 100% of it’s children
  • 10. Rules not as Filters then fine  RULES ARE NOT FILTERS says google in a kind of passive aggressive way https://firebase.google.com/docs/database/security/securing- data#rules_are_not_filters  You need to restructure your data and reprioritise your life  All Public or All Private
  • 11. Summary  Firebase allows you to put fine grained control on your data in a nice declarative way  You can use helper methods and functions to do some neat things  You can use the simulator to test your rules after you’ve set them  Do not use Rules as Filters. It doesn’t work like that but there’s ways around it  Firebase got me like
  • 12. Resources  https://firebase.google.com/docs/database/security/  https://www.youtube.com/watch?v=DBKB6r5BFqo  https://www.youtube.com/watch?v=PUBnlbjZFAI&t=771s  https://www.youtube.com/watch?v=rtoxRg-kbt0  https://www.youtube.com/watch?v=6sIZvHOEw6Q

Editor's Notes

  1. Rules are applied in an atomic manner. That means that a read or write operation is failed immediately if there isn't a rule at that location or at a parent location that grants access. Even if every affected child path is accessible, reading at the parent location will fail completely. Consider this structure: