FEAT: Multi tenant feature#80
Open
bharathkeyvalue wants to merge 23 commits intoKeyValueSoftwareSystems:developmentfrom
Open
FEAT: Multi tenant feature#80bharathkeyvalue wants to merge 23 commits intoKeyValueSoftwareSystems:developmentfrom
bharathkeyvalue wants to merge 23 commits intoKeyValueSoftwareSystems:developmentfrom
Conversation
|
Postgres super users can bypass rls. A new user should be created that cannot bypass rls. |
abba2c9 to
9d10fea
Compare
966c820 to
d0f032c
Compare
Collaborator
doylefermi-kv
left a comment
There was a problem hiding this comment.
Looks good and in the right direction 👍
src/util/database.connection.ts
Outdated
| * @returns connection | ||
| */ | ||
|
|
||
| export async function getConnection(): Promise<DataSource> { |
Collaborator
There was a problem hiding this comment.
Can we try to use NestJS dependency injection in the request scope to obtain a connection from the connection pool? The connection can be injected to the necessary service as and when it needs it.
| # Superuser for migrations | ||
| POSTGRES_ADMIN_USER=postgres | ||
| POSTGRES_ADMIN_PASSWORD=postgres | ||
| # Minimal user with restricted access |
Collaborator
There was a problem hiding this comment.
Can we add a snippet in the readme how multi-tenancy is handled? And also the ways to create a tenant Postgres user.
Let's add a DB Init script in the docker-compose.yml file as well
Collaborator
|
@bharathkeyvalue Note: Once PR is submitted and ready for review, do not force push. |
…ain a connection from the connection pool
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.
Multi-Tenancy Implementation
Description
Key Features
Multi-Tenancy Support
tenanttable and atenant_idcolumn to all relevant tables (excluding permissions).ExecutionManagerto handle tenant context in asynchronous operations.Row-Level Security (RLS)
app.tenant_idset to the specific tenant.New Tenant Creation API
Environment Variable Changes
New Environment Variables
AUTH_KEY: Used for authentication key validation in the tenant creation API.POSTGRES_ADMIN_USER: Admin username for migration runner.POSTGRES_ADMIN_PASSWORD: Admin password for migration runner.POSTGRES_TENANT_USER: Restricted tenant user for database connections.POSTGRES_TENANT_PASSWORD: Password for the restricted tenant user.POSTGRES_TENANT_MAX_CONNECTION_LIMIT: Maximum concurrent database connections for tenants (uses the default setting if unspecified).POSTGRES_ADMIN_MAX_CONNECTION_LIMIT: Maximum concurrent database connections for the admin user (uses the default setting if unspecified).MULTI_TENANCY_ENABLED: A boolean that indicates if multi-tenancy is enabled, used for handling user login.DEFAULT_TENANT_ID: Default tenant id to be used when multi-tenancy is disabled.