Fix: namespace limitation (#138)

fix namespace validation with allowed characters

Signed-off-by: mabhi <abhijit.mukherjee@infracloud.io>
This commit is contained in:
Abhijit Mukherjee
2023-02-14 12:56:34 +05:30
committed by GitHub
parent f9a0792362
commit 99cb3765dd
2 changed files with 14 additions and 0 deletions
+3
View File
@@ -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
+11
View File
@@ -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(),