mirror of
https://github.com/paralus/paralus.git
synced 2026-08-24 15:47:19 +00:00
Fix: namespace limitation (#138)
fix namespace validation with allowed characters Signed-off-by: mabhi <abhijit.mukherjee@infracloud.io>
This commit is contained in:
@@ -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
|
||||
|
||||
@@ -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(),
|
||||
|
||||
Reference in New Issue
Block a user