Skip to content

Commit

Permalink
fix robot account creation issue
Browse files Browse the repository at this point in the history
fixes #21251

Signed-off-by: wang yan <wangyan@vmware.com>
  • Loading branch information
wy65701436 committed Dec 13, 2024
1 parent 6eea45d commit 6fdc77e
Show file tree
Hide file tree
Showing 2 changed files with 96 additions and 3 deletions.
9 changes: 6 additions & 3 deletions src/server/v2.0/handler/robot.go
Original file line number Diff line number Diff line change
Expand Up @@ -481,11 +481,14 @@ func isValidPermissionScope(creating []*models.RobotPermission, creator []*robot

for _, pCreating := range creating {
key := fmt.Sprintf("%s:%s", pCreating.Kind, pCreating.Namespace)
creatingPerm, found := creatorMap[key]
creatorPerm, found := creatorMap[key]
if !found {
return false
allProjects := fmt.Sprintf("%s:*", pCreating.Kind)
if creatorPerm, found = creatorMap[allProjects]; !found {
return false
}
}
if !hasLessThanOrEqualAccess(pCreating.Access, creatingPerm.Access) {
if !hasLessThanOrEqualAccess(pCreating.Access, creatorPerm.Access) {
return false
}
}
Expand Down
90 changes: 90 additions & 0 deletions src/server/v2.0/handler/robot_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -382,6 +382,96 @@ func TestValidPermissionScope(t *testing.T) {
},
expected: false,
},
{
name: "System - subset project",
creatingPerms: []*models.RobotPermission{
{
Kind: "project",
Namespace: "test1",
Access: []*models.Access{
{Resource: "user", Action: "delete", Effect: "allow"},
},
},
},
creatorPerms: []*robot.Permission{
{
Kind: "system",
Namespace: "/",
Access: []*types.Policy{
{Resource: "robot", Action: "create", Effect: "allow"},
},
},
{
Kind: "project",
Namespace: "test1",
Access: []*types.Policy{
{Resource: "user", Action: "create", Effect: "allow"},
{Resource: "user", Action: "delete", Effect: "allow"},
},
},
},
expected: true,
},
{
name: "System - cover all",
creatingPerms: []*models.RobotPermission{
{
Kind: "project",
Namespace: "test1",
Access: []*models.Access{
{Resource: "user", Action: "delete", Effect: "allow"},
},
},
},
creatorPerms: []*robot.Permission{
{
Kind: "system",
Namespace: "/",
Access: []*types.Policy{
{Resource: "robot", Action: "create", Effect: "allow"},
},
},
{
Kind: "project",
Namespace: "*",
Access: []*types.Policy{
{Resource: "user", Action: "create", Effect: "allow"},
{Resource: "user", Action: "delete", Effect: "allow"},
},
},
},
expected: true,
},
{
name: "System - cover all 2",
creatingPerms: []*models.RobotPermission{
{
Kind: "project",
Namespace: "test1",
Access: []*models.Access{
{Resource: "user", Action: "update", Effect: "allow"},
},
},
},
creatorPerms: []*robot.Permission{
{
Kind: "system",
Namespace: "/",
Access: []*types.Policy{
{Resource: "robot", Action: "create", Effect: "allow"},
},
},
{
Kind: "project",
Namespace: "*",
Access: []*types.Policy{
{Resource: "user", Action: "create", Effect: "allow"},
{Resource: "user", Action: "delete", Effect: "allow"},
},
},
},
expected: false,
},
}
for _, tt := range tests {
t.Run(tt.name, func(t *testing.T) {
Expand Down

0 comments on commit 6fdc77e

Please sign in to comment.