Skip to content

Commit

Permalink
all actions must be part of the role
Browse files Browse the repository at this point in the history
Signed-off-by: Jörn Friedrich Dreyer <[email protected]>
  • Loading branch information
butonic committed Aug 26, 2024
1 parent 6c13e5f commit db6d2ef
Show file tree
Hide file tree
Showing 2 changed files with 11 additions and 12 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -178,7 +178,7 @@ var _ = Describe("DriveItemPermissionsService", func() {
Expect(permission.GetRoles()[0]).To(Equal(unifiedrole.NewViewerUnifiedRole().GetId()))
})

It("succeeds with folder roles (happy path)", func() {
FIt("succeeds with folder roles (happy path)", func() {
statResponse.Info.Type = provider.ResourceType_RESOURCE_TYPE_CONTAINER
gatewayClient.On("GetUser", mock.Anything, mock.Anything).Return(getUserResponse, nil)
gatewayClient.On("CreateShare", mock.Anything, mock.Anything).Return(createShareResponse, nil)
Expand Down
21 changes: 10 additions & 11 deletions services/graph/pkg/unifiedrole/unifiedrole.go
Original file line number Diff line number Diff line change
Expand Up @@ -528,17 +528,20 @@ func GetLegacyName(role libregraph.UnifiedRoleDefinition) string {
// CS3ResourcePermissionsToUnifiedRole tries to find the UnifiedRoleDefinition that matches the supplied
// CS3 ResourcePermissions and constraints.
func CS3ResourcePermissionsToUnifiedRole(p *provider.ResourcePermissions, constraints string, listFederatedRoles bool) *libregraph.UnifiedRoleDefinition {
actions := CS3ResourcePermissionsToLibregraphActions(p)
actionSet := map[string]struct{}{}
for _, action := range CS3ResourcePermissionsToLibregraphActions(p) {
actionSet[action] = struct{}{}
}

var res *libregraph.UnifiedRoleDefinition
for _, uRole := range GetBuiltinRoleDefinitionList() {
definitionMatch := false
for _, uPerm := range uRole.GetRolePermissions() {

for _, permission := range uRole.GetRolePermissions() {
// this is a dirty comparison because we are not really parsing the SDDL, but as long as we && the conditions we are good
isFederatedRole := strings.Contains(uPerm.GetCondition(), UnifiedRoleConditionFederatedUser)
isFederatedRole := strings.Contains(permission.GetCondition(), UnifiedRoleConditionFederatedUser)
switch {
case !strings.Contains(uPerm.GetCondition(), constraints):
case !strings.Contains(permission.GetCondition(), constraints):
continue
case listFederatedRoles && !isFederatedRole:
continue
Expand All @@ -547,13 +550,9 @@ func CS3ResourcePermissionsToUnifiedRole(p *provider.ResourcePermissions, constr
}

// if the actions converted from the ResourcePermissions equal the action the defined for the role, we have match
for i, action := range uPerm.GetAllowedResourceActions() {
if !slices.Contains(actions, action) {
break
}
if i == len(uPerm.GetAllowedResourceActions())-1 {
definitionMatch = true
}
if resourceActionsEqual(actionSet, permission.GetAllowedResourceActions()) {
definitionMatch = true
break
}
}
if definitionMatch {
Expand Down

0 comments on commit db6d2ef

Please sign in to comment.