Skip to content

Commit

Permalink
fix user scope (#360)
Browse files Browse the repository at this point in the history
  • Loading branch information
tiancandevloper committed Dec 12, 2023
1 parent 91a6a21 commit 070093e
Show file tree
Hide file tree
Showing 3 changed files with 14 additions and 2 deletions.
11 changes: 11 additions & 0 deletions pkg/apis/user/v1/user_types.go
Original file line number Diff line number Diff line change
Expand Up @@ -130,3 +130,14 @@ type UserList struct {
func init() {
SchemeBuilder.Register(&User{}, &UserList{})
}

func (u *User) IsUserPlatformScope() bool {
platformScope := false
for _, scope := range u.Spec.ScopeBindings {
if scope.ScopeType == PlatformScope {
platformScope = true
break
}
}
return platformScope
}
3 changes: 2 additions & 1 deletion pkg/apiserver/cubeapi/authorization/handler.go
Original file line number Diff line number Diff line change
Expand Up @@ -597,6 +597,7 @@ func getUserProjects(user *user.User, projectList *tenantv1.ProjectList, tenantA
projectSet.Insert(p.Project)
}
tenantSet := sets.NewString(user.Status.BelongTenants...)
isUserPlatform := user.IsUserPlatformScope()

for _, p := range projectList.Items {
t, ok := p.Labels[constants.TenantLabel]
Expand All @@ -607,7 +608,7 @@ func getUserProjects(user *user.User, projectList *tenantv1.ProjectList, tenantA
// 1. user is platform admin
// 2. user's belong projects had this queried project
// 3. user's belong tenants had this queried tenant
if !user.Status.PlatformAdmin && !projectSet.Has(p.Name) && !tenantSet.Has(t) {
if !isUserPlatform && !user.Status.PlatformAdmin && !projectSet.Has(p.Name) && !tenantSet.Has(t) {
continue
}

Expand Down
2 changes: 1 addition & 1 deletion pkg/apiserver/cubeapi/authorization/helper.go
Original file line number Diff line number Diff line change
Expand Up @@ -272,7 +272,7 @@ func GetVisibleTenants(ctx context.Context, cli mgrclient.Client, username strin
return nil, err
}

if user.Status.PlatformAdmin {
if user.Status.PlatformAdmin || user.IsUserPlatformScope() {
return tenants.Items, nil
}

Expand Down

0 comments on commit 070093e

Please sign in to comment.