-
Notifications
You must be signed in to change notification settings - Fork 752
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
feat: create user if not exists on JWT authenticate #4924
Conversation
The latest updates on your projects. Learn more about Vercel for Git ↗︎ 1 Ignored Deployment
|
Thanks for the contribution! Please review the labels and make any necessary changes. |
None => return Err(ErrorCode::AuthenticateFailure("jwt auth not configured.")), | ||
}; | ||
self.users | ||
let user_name = jwt.subject.unwrap(); | ||
if let Some(create_user) = jwt.custom.create_user { |
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.
-
add_user
return error if user exists. does the cloud platform when it should carry the create_user field? -
for an existed user, what if the existed user info diff with info in create_user?
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.
add_user return error if user exists. does the cloud platform when it should carry the create_user field?
User will be created only if user does not exist. is_not_exists
is true for add_user
.
for an existed user, what if the existed user info diff with info in create_user?
create_user
just used to create users, not update.
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.
User will be created only if user does not exist
do you mean cloud platform do this check to determine whether or not to addcreate_user
in jwt? cc @flaneur2020
add_user
may ErrorCode::UserAlreadyExists
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.
do you mean cloud platform do this check to determine whether or not to addcreate_user in jwt?
i guess the cloud platform could ensure user exists by an jwt with create_user enabled when the user successfully logged in, and then pass normal jwt for the normal operations to interact with databend-query.
a jwt is used to authenticate an user, if the jwt verified successfully and the user already existed, it can pass the authentication happily, it might a bit weird to get a userAlreadyExists in this case. 🤔
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.
btw, how about making the create_user
claim into a bool?
the infomation about tenant and role may already existed some another claims 🤔
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.
btw, how about making the create_user claim into a bool?
like this?
{
"create_user": true,
"tenant_id": "",
"roles": []
}
I'm not sure if the same fields would be in custom claims, it's better together.
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.
@junnplus sorry, what I saw is UserApi::add_user.
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.
i guess the cloud platform could ensure user exists by an jwt with create_user enabled when the user successfully logged in, and then pass normal jwt for the normal operations to interact with databend-query.
maybe we can call it ensure_user
? I saw it a lot in puppet. or "create_user_if_not_exist".
btw, how about making the create_user claim into a bool?
seems currently this create_user
provides only a basic
template for a newly-seen user, so the value in it take effective only when user dose not exist. and it will not override behavior specified by an existing userInfo.
So, I prefer to separate it from other fields,which while be regard,naturally, being able to override the behavior of the session
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.
ensure_user
SGTM. cc @flaneur2020
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.
cool, ensure_user
is much better than create_user_if_not_exist
.
I guess jwt in some manner favors shorter names, as it'd like to avoids getting too big in the transport, likewise "aud" over "audience", "sub" over "subject" etc.
} | ||
self.user_mgr.add_user(&tenant, user_info, true).await?; | ||
} | ||
self.user_mgr |
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.
if add_user does return ok, no need to get_user here?
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.
if add_user does return ok, no need to get_user here?
If the user already exists, we still need to get the user.
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.
why not return the UserInfo just created?
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.
why not return the UserInfo just created?
User will not be created if user already exists, so we need to get_user
.
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.
so, put it together, Jwt only create a user if not exist.
the user may be altered later as normal.
lgtm
Signed-off-by: Ye Sijun <junnplus@gmail.com>
I hereby agree to the terms of the CLA available at: https://databend.rs/dev/policies/cla/
Summary
Create user if not exists on JWT authenticate.
Specify the
create_user
struct in custom claims to create a user.Changelog
Related Issues
Fixes #4875