Conversation
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
Add this suggestion to a batch that can be applied as a single commit.This suggestion is invalid because no changes were made to the code.Suggestions cannot be applied while the pull request is closed.Suggestions cannot be applied while viewing a subset of changes.Only one suggestion per line can be applied in a batch.Add this suggestion to a batch that can be applied as a single commit.Applying suggestions on deleted lines is not supported.You must change the existing code in this line in order to create a valid suggestion.Outdated suggestions cannot be applied.This suggestion has been applied or marked resolved.Suggestions cannot be applied from pending reviews.Suggestions cannot be applied on multi-line comments.Suggestions cannot be applied while the pull request is queued to merge.Suggestion cannot be applied right now. Please check back later.
Purpose
This pull request adds two new power-up features to StarbaseDB currently isolated in their own worker deployments. Typically each of these features would be contributed to the project independently but much of the testing performed was to co-test how these features performed together in tandem.
Core features for enabling the possibility to run SQL from the frontend include both having a list of allowed queries that should be executable against the database, and row level security. The allowlist serves as a way to quickly deny any incoming database query at the edge (e.g. Worker) and not burdening our database instance itself with making that determination and potentially adding latency to subsequent queries. In addition as another layer of security RLS (row level security) allows us to expressively write policy rules on a per table basis to make sure only specific actions can be performed and potentially only valid with expected values (e.g. ensure a user can only select rows that match the userId available to the system).
Since the recommended usage of these power-ups is to be placed in the
beforeQueryhook (read more) that means every aspect of our StarbaseDB instance including executing REST API queries, web sockets, transactions and more all funnel through this function before executing against the database.Tasks
Verify
context.id()as the value column that the JWTsubvalue is used to replace it in the SQL query before execution.value_typeis defined as anumberto make sure quotes do not exist around the value in the produced SQL statement.Reference the
migration.sqlfiles in the PR for the corresponding SQL table definitions. You can follow a similar row INSERT command as shown below for each table to establish enough rules to run a statement to get all results from your table (in this case, assuming the table name istodos).Before
After