Skip to content

Database governance built for humans and agents — controlling changes and access across every major database.

fix: create user (#13779)

ecmadao0dda24a5504e
diff --git a/backend/api/v1/auth_service.go b/backend/api/v1/auth_service.go
index 2924ab181a..7d60694b24 100644
--- a/backend/api/v1/auth_service.go
+++ b/backend/api/v1/auth_service.go
@@ -157,9 +157,6 @@ func (s *AuthService) CreateUser(ctx context.Context, request *v1pb.CreateUserRe
if request.User.UserType != v1pb.UserType_SERVICE_ACCOUNT && request.User.UserType != v1pb.UserType_USER {
return nil, status.Errorf(codes.InvalidArgument, "support user and service account only")
}
- if request.User.UserType != v1pb.UserType_SERVICE_ACCOUNT && request.User.Password == "" {
- return nil, status.Errorf(codes.InvalidArgument, "password must be set")
- }
count, err := s.store.CountUsers(ctx, api.EndUser)
if err != nil {
@@ -189,16 +186,24 @@ func (s *AuthService) CreateUser(ctx context.Context, request *v1pb.CreateUserRe
}
password := request.User.Password
- if err := s.validatePassword(ctx, password); err != nil {
- return nil, err
- }
-
if request.User.UserType == v1pb.UserType_SERVICE_ACCOUNT {
pwd, err := common.RandomString(20)
if err != nil {
return nil, status.Errorf(codes.Internal, "failed to generate access key for service account.")
}
password = fmt.Sprintf("%s%s", api.ServiceAccountAccessKeyPrefix, pwd)
+ } else {
+ if password != "" {
+ if err := s.validatePassword(ctx, password); err != nil {
+ return nil, err
+ }
+ } else {
+ pwd, err := common.RandomString(20)
+ if err != nil {
+ return nil, status.Errorf(codes.Internal, "failed to generate random password for service account.")
+ }
+ password = pwd
+ }
}
passwordHash, err := bcrypt.GenerateFromPassword([]byte(password), bcrypt.DefaultCost)
if err != nil {
diff --git a/backend/store/principal.go b/backend/store/principal.go
index 111dd7c7a3..9df7cbd725 100644
--- a/backend/store/principal.go
+++ b/backend/store/principal.go
@@ -251,8 +251,16 @@ func (s *Store) CreateUser(ctx context.Context, create *UserMessage, creatorID i
}
defer tx.Rollback()
- set := []string{"creator_id", "updater_id", "email", "name", "type", "password_hash", "phone"}
- args := []any{creatorID, creatorID, create.Email, create.Name, create.Type, create.PasswordHash, create.Phone}
+ if create.Profile == nil {
+ create.Profile = &storepb.UserProfile{}
+ }
+ profileBytes, err := protojson.Marshal(create.Profile)
+ if err != nil {
+ return nil, err
+ }
+
+ set := []string{"creator_id", "updater_id", "email", "name", "type", "password_hash", "phone", "profile"}
+ args := []any{creatorID, creatorID, create.Email, create.Name, create.Type, create.PasswordHash, create.Phone, profileBytes}
placeholder := []string{}
for index := range set {
placeholder = append(placeholder, fmt.Sprintf("$%d", index+1))
@@ -284,7 +292,7 @@ func (s *Store) CreateUser(ctx context.Context, create *UserMessage, creatorID i
PasswordHash: create.PasswordHash,
Phone: create.Phone,
CreatedTime: time.Unix(createdTs, 0),
- Profile: &storepb.UserProfile{},
+ Profile: create.Profile,
MFAConfig: &storepb.MFAConfig{},
}
s.userIDCache.Add(user.ID, user)
diff --git a/frontend/src/components/User/Settings/CreateUserDrawer.vue b/frontend/src/components/User/Settings/CreateUserDrawer.vue
index 09ca91e261..a425ca0e70 100644
--- a/frontend/src/components/User/Settings/CreateUserDrawer.vue
+++ b/frontend/src/components/User/Settings/CreateUserDrawer.vue
@@ -172,7 +172,6 @@ import {
User,
} from "@/types/proto/v1/auth_service";
import { State } from "@/types/proto/v1/common";
-import { randomString } from "@/utils";
import UserPassword from "./UserPassword.vue";
interface LocalState {
@@ -313,9 +312,7 @@ const tryCreateOrUpdateUser = async () => {
const createdUser = await userStore.createUser({
...state.user,
title: state.user.title || extractUserTitle(state.user.email),
- password:
- state.user.password ||
- randomString(10) + randomString(10, "0123456789"),
+ password: state.user.password,
});
if (state.roles.length > 0) {
await workspaceStore.patchIamPolicy([