-
Notifications
You must be signed in to change notification settings - Fork 4
FEAT: Multi tenant feature #80
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
base: development
Are you sure you want to change the base?
FEAT: Multi tenant feature #80
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
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Looks good and in the right direction 👍
src/util/database.connection.ts
Outdated
* @returns connection | ||
*/ | ||
|
||
export async function getConnection(): Promise<DataSource> { |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
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.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Updated in commit here
# Superuser for migrations | ||
POSTGRES_ADMIN_USER=postgres | ||
POSTGRES_ADMIN_PASSWORD=postgres | ||
# Minimal user with restricted access |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
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
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
updated in commit here
@bharathkeyvalue Note: Once PR is submitted and ready for review, do not force push. |
…ain a connection from the connection pool
Multi-Tenancy Implementation
Description
Key Features
Multi-Tenancy Support
tenant
table and atenant_id
column to all relevant tables (excluding permissions).ExecutionManager
to handle tenant context in asynchronous operations.Row-Level Security (RLS)
app.tenant_id
set 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.