iam: require empty PolicyNames before group deletion
Reject DeleteGroup when group has attached policies, matching the
existing members check. Also fix GetGroup error handling in
DeletePolicy to only skip ErrGroupNotFound, not all errors.
returnresp,&IamError{Code:iam.ErrCodeDeleteConflictException,Error:fmt.Errorf("cannot delete group %s: group has %d member(s)",groupName,len(g.Members))}
returnresp,&IamError{Code:iam.ErrCodeDeleteConflictException,Error:fmt.Errorf("cannot delete group %s: group has %d member(s)",groupName,len(g.Members))}
}
}
iflen(g.PolicyNames)>0{
returnresp,&IamError{Code:iam.ErrCodeDeleteConflictException,Error:fmt.Errorf("cannot delete group %s: group has %d attached policy(ies)",groupName,len(g.PolicyNames))}
returnresp,&iamError{Code:iam.ErrCodeServiceFailureException,Error:fmt.Errorf("failed to get group %s: %w",gn,err)}
}
}
for_,pn:=rangeg.PolicyNames{
for_,pn:=rangeg.PolicyNames{
ifpn==policyName{
ifpn==policyName{
@ -1482,6 +1485,9 @@ func (e *EmbeddedIamApi) DeleteGroup(s3cfg *iam_pb.S3ApiConfiguration, values ur
iflen(g.Members)>0{
iflen(g.Members)>0{
returnresp,&iamError{Code:iam.ErrCodeDeleteConflictException,Error:fmt.Errorf("cannot delete group %s: group has %d member(s). Remove all members first",groupName,len(g.Members))}
returnresp,&iamError{Code:iam.ErrCodeDeleteConflictException,Error:fmt.Errorf("cannot delete group %s: group has %d member(s). Remove all members first",groupName,len(g.Members))}
}
}
iflen(g.PolicyNames)>0{
returnresp,&iamError{Code:iam.ErrCodeDeleteConflictException,Error:fmt.Errorf("cannot delete group %s: group has %d attached policy(ies). Detach all policies first",groupName,len(g.PolicyNames))}