-
Notifications
You must be signed in to change notification settings - Fork 3
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
DPLT-1049 Provision separate DB per user #132
Merged
Merged
Conversation
This file contains 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
morgsmccauley
force-pushed
the
DPLT-1049-db-per-user
branch
3 times, most recently
from
July 17, 2023 23:19
d5403f0
to
62ff02b
Compare
morgsmccauley
force-pushed
the
DPLT-1049-db-per-user
branch
from
July 17, 2023 23:20
62ff02b
to
2116c94
Compare
morgsmccauley
force-pushed
the
DPLT-1049-db-per-user
branch
from
July 18, 2023 02:55
b7d5e1a
to
07e61b5
Compare
morgsmccauley
force-pushed
the
DPLT-1049-db-per-user
branch
from
July 18, 2023 03:24
146fa74
to
ab8856c
Compare
This comment was marked as resolved.
This comment was marked as resolved.
gabehamilton
approved these changes
Jul 20, 2023
morgsmccauley
added a commit
that referenced
this pull request
Jul 21, 2023
This reverts commit 8e18566.
This was referenced Jul 21, 2023
Merged
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.
This PR updates the Lambda Runner provisioning step to create a separate Postgres database per user. This provides greater security, preventing users from manipulating other users data within the provided SQL.
I've added the high level steps, as well as some notes on the changes to them, below:
1. Create database/user in Postgres
It's possible to run SQL against Postgres via Hasura, but the provided statements are run within a transaction block. As
CREATE DATABASE
can not be run within a transaction, we need a direct connection to Postgres to create new databases.Crypto random passwords are generated for each PG user, these will be stored by Hasura in plain text within its metadata table. Exposing the password/connection string via an environment variable isn't really feasible as this would require: creating a secret, updating the Cloud Run revision, and restarting the instance. We can look at more secure options for this in future.
2. Add database to Hasura
Database connections are added as 'data sources' to Hasura, this makes up the majority of changes to Hasura Client - making
source
configurable. As mentioned above, these connections are stored in the Hasura metadata tables and are therefore persisted across restarts.A database will be created per account, we must therefore check if the datasource exists before provisioning to avoid attempting to recreate it when the account creates their second indexer.
3. Run user provided SQL
There are two potential conflicts when provisioning an endpoint:
namespace
, which scopes all top-level fields to that namespace.The end result is a query like to the following:
Instead of namespaces, we could create a DB schema named after both account ID/function, which would result in the top-level fields we have currently, i.e.
account_name_function_name_table_name
. But I believe the namespace reduces the noise and makes GraphQL operations more readable.4. Track tables, foreign key relationships, and add permissions
These steps are mostly unchanged, but have been slightly refactored to take in to account execution against different databases/sources.
Other Considerations
By default, all users are able to connect to the
template
databases, which are used as 'templates' for new databases. To prevent users from modifying these templates we should removePUBLIC
access from them: