Fix duplicate groups in ListGroups API (#20396)

This commit is contained in:
Taran Pelkey
2024-09-06 20:28:47 -04:00
committed by GitHub
parent 261111e728
commit 84e122c5c3
2 changed files with 11 additions and 8 deletions

View File

@@ -980,6 +980,7 @@ func (store *IAMStoreSys) GetGroupDescription(group string) (gd madmin.GroupDesc
// updateGroups updates the group from the persistent store, and also related policy mapping if any.
func (store *IAMStoreSys) updateGroups(ctx context.Context, cache *iamCache) (res []string, err error) {
groupSet := set.NewStringSet()
if iamOS, ok := store.IAMStorageAPI.(*IAMObjectStore); ok {
listedConfigItems, err := iamOS.listAllIAMConfigItems(ctx)
if err != nil {
@@ -992,7 +993,7 @@ func (store *IAMStoreSys) updateGroups(ctx context.Context, cache *iamCache) (re
if err = iamOS.loadGroup(ctx, group, cache.iamGroupsMap); err != nil && !errors.Is(err, errNoSuchGroup) {
return nil, fmt.Errorf("unable to load the group: %w", err)
}
res = append(res, group)
groupSet.Add(group)
}
}
@@ -1002,23 +1003,23 @@ func (store *IAMStoreSys) updateGroups(ctx context.Context, cache *iamCache) (re
if err = iamOS.loadMappedPolicy(ctx, group, regUser, true, cache.iamGroupPolicyMap); err != nil && !errors.Is(err, errNoSuchPolicy) {
return nil, fmt.Errorf("unable to load the policy mapping for the group: %w", err)
}
res = append(res, group)
groupSet.Add(group)
}
return res, nil
return groupSet.ToSlice(), nil
}
// For etcd just return from cache.
for k := range cache.iamGroupsMap {
res = append(res, k)
groupSet.Add(k)
}
cache.iamGroupPolicyMap.Range(func(k string, v MappedPolicy) bool {
res = append(res, k)
groupSet.Add(k)
return true
})
return res, nil
return groupSet.ToSlice(), nil
}
// ListGroups - lists groups. Since this is not going to be a frequent