Skip to content

Allow Multiple Spaceclaims #11291

New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Merged
merged 1 commit into from
May 8, 2025
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
1 change: 1 addition & 0 deletions changelog/unreleased/claim-managed-spaces.md
Original file line number Diff line number Diff line change
Expand Up @@ -3,3 +3,4 @@ Enhancement: Claim managed spaces
Allow managing spaces from oidc claims

https://github.com/owncloud/ocis/pull/11280
https://github.com/owncloud/ocis/pull/11291
27 changes: 24 additions & 3 deletions services/proxy/pkg/middleware/space_manager.go
Original file line number Diff line number Diff line change
Expand Up @@ -158,27 +158,48 @@ func (csm claimSpaceManager) getSpaceAssignments(ctx context.Context) map[string
claims := oidc.FromContext(ctx)
values, ok := claims[csm.claimName].([]any)
if !ok {
csm.logger.Error().Interface("entitlements", claims["entitlements"]).Msg("entitlements claims are not a []string")
csm.logger.Error().Interface("claims", claims).Str("claimname", csm.claimName).Msg("configured claims are not an array")
}

assignments := make(map[string]string)
for _, ent := range values {
e, ok := ent.(string)
if !ok {
csm.logger.Error().Interface("entitlement", ent).Msg("entitlement is not a sting")
csm.logger.Error().Interface("assignment", ent).Msg("assignment is not a string")
continue
}

match, spaceid, role := csm.mapper.Exec(e)
if !match {
continue
}
assignments[spaceid] = role
assignments[spaceid] = chooseRole(role, assignments[spaceid])
}

return assignments
}

// will return the role with the highest permissions.
func chooseRole(roleA, roleB string) string {
if roleA == "" {
return roleB
}

if roleB == "" {
return roleA
}

permsA := conversions.RoleFromName(roleA).CS3ResourcePermissions()
permsB := conversions.RoleFromName(roleB).CS3ResourcePermissions()

if conversions.SufficientCS3Permissions(permsA, permsB) {
return roleA
}
// Note: This could be an issue if roleB does not contain roleA
return roleB

}

func getSpaceMemberStatus(space *storageprovider.StorageSpace, userid string) (bool, *storageprovider.ResourcePermissions, error) {
var permissionsMap map[string]*storageprovider.ResourcePermissions
if err := utils.ReadJSONFromOpaque(space.GetOpaque(), "grants", &permissionsMap); err != nil {
Expand Down