Skip to content

To support multi-tenancy with DB based identity management. Assumes t… #5110

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

Closed
wants to merge 6 commits into from

Conversation

kzwct
Copy link

@kzwct kzwct commented Jun 28, 2025

Assumes that all login names are "username@tenant_id". Modifies 3 methods of db_identitymanager - create_user, delete_user, and get_users to get multi-tenancy. SINGLE_TENANT_UUID provisioned at deployment is made a "super" tenant to get/create/delete users from any tenant when admin users from other tenants can do it for their own tenant only. NOTE: don't forget to set KEEP_DEFAULT_USERNAME=keep@keep

…hat all login names are username@tenant_id. Modifies 3 methods of db_identitymanager - create_user, delete_user, and get_users to get multi-tenancy. SINGLE_TENANT_UUID provisioned at deployment is made a super tenant to get/create/delete users from any tenant when admin users from other tenants can do it for their own tenant only. NOTE: don't forget to set KEEP_DEFAULT_USERNAME=keep@keep
Copy link

vercel bot commented Jun 28, 2025

@kzilberb is attempting to deploy a commit to the KeepHQ Team on Vercel.

A member of the Team first needs to authorize it.

@dosubot dosubot bot added the size:M This PR changes 30-99 lines, ignoring generated files. label Jun 28, 2025
@CLAassistant
Copy link

CLAassistant commented Jun 28, 2025

CLA assistant check
Thank you for your submission! We really appreciate it. Like many open source projects, we ask that you all sign our Contributor License Agreement before we can accept your contribution.
0 out of 2 committers have signed the CLA.

❌ kzilberb
❌ kzwct
You have signed the CLA already but the status is still pending? Let us recheck it.

Copy link
Contributor

No linked issues found. Please add the corresponding issues in the pull request description.
Use GitHub automation to close the issue when a PR is merged

Copy link
Contributor

github-actions bot commented Jun 28, 2025

Hey there and thank you for opening this pull request! 👋🏼

We require pull request titles to follow the Conventional Commits specification and it looks like your proposed title needs to be adjusted.

Details:

No release type found in pull request title "To support multi-tenancy with DB based identity management. Assumes t…". Add a prefix to indicate what kind of release this pull request corresponds to. For reference, see https://www.conventionalcommits.org/

Available types:
 - feat: A new feature
 - fix: A bug fix
 - docs: Documentation only changes
 - style: Changes that do not affect the meaning of the code (white-space, formatting, missing semi-colons, etc)
 - refactor: A code change that neither fixes a bug nor adds a feature
 - perf: A code change that improves performance
 - test: Adding missing tests or correcting existing tests
 - build: Changes that affect the build system or external dependencies (example scopes: gulp, broccoli, npm)
 - ci: Changes to our CI configuration files and scripts (example scopes: Travis, Circle, BrowserStack, SauceLabs)
 - chore: Other changes that don't modify src or test files
 - revert: Reverts a previous commit

@dosubot dosubot bot added the Enhancement New feature or request label Jun 28, 2025
cursor[bot]

This comment was marked as outdated.

Copy link
Member

@shahargl shahargl left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I would prefer to add a new env var (e.g. AUTH_TYPE=DB_MULTITENANT) so it will be clear separation between single and multi tenant.

I guess I would also create a new identity manager (e.g. dbmt_identitymanager.py)

Last, update docs to include the new authentication type and how to use it

@@ -52,7 +53,7 @@ def signin(body: dict):
token = jwt.encode(
{
"email": user.username,
"tenant_id": SINGLE_TENANT_UUID,
"tenant_id": user.username.split('@')[1],
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

add _get_tenant_id that checks if the user is user@tenant and if not will default to SINGLE_TENANT_UUID

Copy link
Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

In my follow-up commit I am adding dbmt_identitymanager that will fail if the user name has an incorrect format. I am restored dbmt_identitymanager to the original one and add defaulting to SINGLE_TENANT_UUID to db.py so it would support both identity managers.

@@ -87,8 +89,13 @@ def create_user(
) -> dict:
# Username is redundant, but we need it in other auth types
# Groups: for future use
tenant_id = user_email.split('@')[1]
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

see comment above

@dosubot dosubot bot added size:L This PR changes 100-499 lines, ignoring generated files. and removed size:M This PR changes 30-99 lines, ignoring generated files. labels Jun 29, 2025
cursor[bot]

This comment was marked as outdated.

cursor[bot]

This comment was marked as outdated.

cursor[bot]

This comment was marked as outdated.

cursor[bot]

This comment was marked as outdated.

Copy link

@cursor cursor bot left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Bug: JWT Payload Mismatch in Sign-In Response

The /signin endpoint's response incorrectly swaps the tenantId and email fields. tenantId is set to the full username (user.username) and email is set to the tenant ID (self._get_tenant_id(user.username)), which is inconsistent with the JWT payload and provides incorrect user/tenant information.

keep/identitymanager/identity_managers/dbmt/dbmt_identitymanager.py#L68-L74

# return the token
return {
"accessToken": token,
"tenantId": user.username,
"email": self._get_tenant_id(user.username),
"role": user.role,
}

Fix in CursorFix in Web


Was this report helpful? Give feedback by reacting with 👍 or 👎

@shahargl shahargl closed this Jul 16, 2025
@shahargl
Copy link
Member

@kzilberb closing. let me know if you wanna merge it and re-open.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
Enhancement New feature or request size:L This PR changes 100-499 lines, ignoring generated files.
Projects
None yet
Development

Successfully merging this pull request may close these issues.

4 participants
pFad - Phonifier reborn

Pfad - The Proxy pFad of © 2024 Garber Painting. All rights reserved.

Note: This service is not intended for secure transactions such as banking, social media, email, or purchasing. Use at your own risk. We assume no liability whatsoever for broken pages.


Alternative Proxies:

Alternative Proxy

pFad Proxy

pFad v3 Proxy

pFad v4 Proxy