Skip to content

Commit

Permalink
truncating username in vela_project_user to match vela_user username
Browse files Browse the repository at this point in the history
  • Loading branch information
oanasc committed Jul 4, 2024
1 parent 127f532 commit a5670cd
Showing 1 changed file with 11 additions and 9 deletions.
20 changes: 11 additions & 9 deletions pkg/server/domain/service/authentication.go
Original file line number Diff line number Diff line change
Expand Up @@ -449,6 +449,14 @@ func (a *authenticationServiceImpl) GetLoginType(ctx context.Context) (*apisv1.G
}, nil
}

func getSub(claims *model.Claims) string {

Check failure on line 452 in pkg/server/domain/service/authentication.go

View workflow job for this annotation

GitHub Actions / check

undefined: model.Claims

Check failure on line 452 in pkg/server/domain/service/authentication.go

View workflow job for this annotation

GitHub Actions / server-unit-tests

undefined: model.Claims
sub := strings.ToLower(claims.Sub)
if len(sub) > datastore.PrimaryKeyMaxLength {
return sub[:datastore.PrimaryKeyMaxLength]
}
return sub
}

func (d *dexHandlerImpl) login(ctx context.Context) (*apisv1.UserBase, error) {
var claims struct {
Email string `json:"email"`
Expand Down Expand Up @@ -492,14 +500,8 @@ func (d *dexHandlerImpl) login(ctx context.Context) (*apisv1.UserBase, error) {
klog.Errorf("failed to get the system info %s", err.Error())
}
user := &model.User{
Email: claims.Email,
Name: func() string {
sub := strings.ToLower(claims.Sub)
if len(sub) > datastore.PrimaryKeyMaxLength {
return sub[:datastore.PrimaryKeyMaxLength]
}
return sub
}(),
Email: claims.Email,
Name: getSub(claims),
DexSub: claims.Sub,
Alias: claims.Name,
LastLoginTime: time.Now(),
Expand All @@ -514,7 +516,7 @@ func (d *dexHandlerImpl) login(ctx context.Context) (*apisv1.UserBase, error) {
if systemInfo != nil {
for _, project := range systemInfo.DexUserDefaultProjects {
_, err := d.projectService.AddProjectUser(ctx, project.Name, apisv1.AddProjectUserRequest{
UserName: strings.ToLower(claims.Sub),
UserName: getSub(claims),
UserRoles: project.Roles,
})
if err != nil {
Expand Down

0 comments on commit a5670cd

Please sign in to comment.