Skip to content
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

Fix: The sub length of the dex user more than 31 #785

Merged
merged 1 commit into from
Apr 24, 2023
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
10 changes: 8 additions & 2 deletions pkg/server/domain/service/authentication.go
Original file line number Diff line number Diff line change
Expand Up @@ -492,8 +492,14 @@ 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: strings.ToLower(claims.Sub),
Email: claims.Email,
Name: func() string {
sub := strings.ToLower(claims.Sub)
if len(sub) > datastore.PrimaryKeyMaxLength {
return sub[:datastore.PrimaryKeyMaxLength]
}
return sub
}(),
DexSub: claims.Sub,
Alias: claims.Name,
LastLoginTime: time.Now(),
Expand Down
3 changes: 3 additions & 0 deletions pkg/server/infrastructure/datastore/datastore.go
Original file line number Diff line number Diff line change
Expand Up @@ -46,6 +46,9 @@ var (
ErrEntityInvalid = NewDBError(fmt.Errorf("entity is invalid"))
)

// PrimaryKeyMaxLength The primary key length should be limited when the datastore is kube-api
var PrimaryKeyMaxLength = 31

// DBError datastore error
type DBError struct {
err error
Expand Down
3 changes: 2 additions & 1 deletion pkg/server/interfaces/api/validate.go
Original file line number Diff line number Diff line change
Expand Up @@ -23,6 +23,7 @@ import (
"github.com/go-playground/validator/v10"

"github.com/kubevela/velaux/pkg/server/domain/service"
"github.com/kubevela/velaux/pkg/server/infrastructure/datastore"
)

var validate = validator.New()
Expand Down Expand Up @@ -72,7 +73,7 @@ func ValidatePayloadType(fl validator.FieldLevel) bool {
// ValidateName custom check name field
func ValidateName(fl validator.FieldLevel) bool {
value := fl.Field().String()
if len(value) > 31 || len(value) < 2 {
if len(value) > datastore.PrimaryKeyMaxLength || len(value) < 2 {
return false
}
return nameRegexp.MatchString(value)
Expand Down