Skip to content

Commit

Permalink
Fix: Username length in projects users to match users (#904)
Browse files Browse the repository at this point in the history
* truncating username in vela_project_user to match vela_user username

Signed-off-by: Oana Schipor <[email protected]>

* update fn

Signed-off-by: Oana Schipor <[email protected]>

* Remove old k8s version

Signed-off-by: Oana Schipor <[email protected]>

---------

Signed-off-by: Oana Schipor <[email protected]>
  • Loading branch information
oanasc authored Jul 4, 2024
1 parent 127f532 commit 73334e7
Show file tree
Hide file tree
Showing 2 changed files with 12 additions and 10 deletions.
2 changes: 1 addition & 1 deletion .github/workflows/server-test.yml
Original file line number Diff line number Diff line change
Expand Up @@ -110,7 +110,7 @@ jobs:
if: needs.detect-noop.outputs.noop != 'true'
strategy:
matrix:
k8s-version: ["v1.21", "v1.26"]
k8s-version: ["v1.26"]
concurrency:
group: ${{ github.workflow }}-${{ github.ref }}-${{ matrix.k8s-version }}
cancel-in-progress: true
Expand Down
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 getUserName(sub string) string {
username := strings.ToLower(sub)
if len(sub) > datastore.PrimaryKeyMaxLength {
return sub[:datastore.PrimaryKeyMaxLength]
}
return username
}

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: getUserName(claims.Sub),
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: getUserName(claims.Sub),
UserRoles: project.Roles,
})
if err != nil {
Expand Down

0 comments on commit 73334e7

Please sign in to comment.