diff --git a/CHANGELOG.md b/CHANGELOG.md index 43f2101..8e37c87 100644 --- a/CHANGELOG.md +++ b/CHANGELOG.md @@ -4,6 +4,9 @@ All notable changes to this project will be documented in this file. ## Unreleased +### Fixed +- namespace limitation [mabhi](https://github.com/mabhi) + ## [0.2.0] - 2023-01-27 ## Fixed diff --git a/pkg/service/group.go b/pkg/service/group.go index 087dcfe..a92a119 100644 --- a/pkg/service/group.go +++ b/pkg/service/group.go @@ -4,6 +4,7 @@ import ( "context" "database/sql" "fmt" + "regexp" "strings" "time" @@ -102,6 +103,8 @@ func (s *groupService) createGroupRoleRelations(ctx context.Context, db bun.IDB, var grs []models.GroupRole var ps []*authzv1.Policy var rids []uuid.UUID + regexc := regexp.MustCompile(`^[a-z0-9]([-a-z0-9]*[a-z0-9])?$`) + for _, pnr := range projectNamespaceRoles { role := pnr.GetRole() entity, err := dao.GetByName(ctx, db, role, &models.Role{}) @@ -204,6 +207,14 @@ func (s *groupService) createGroupRoleRelations(ctx context.Context, db bun.IDB, } namespace := pnr.GetNamespace() + match := regexc.MatchString(namespace) + if !match { + return &userv3.Group{}, nil, fmt.Errorf("namespace %q is invalid", namespace) + } + if len(namespace) < 1 || len(namespace) > 63 { + return &userv3.Group{}, nil, fmt.Errorf("namespace %q is invalid. must be no more than 63 characters", namespace) + } + pgnrObj := models.ProjectGroupNamespaceRole{ CreatedAt: time.Now(), ModifiedAt: time.Now(),