Sub topic 7
Organizing Users with Groups
This chapter assumes you know what an IAM user is and how identity-based policies are written (Effect, Action, Resource). It covers what a group is, what it cannot do, and how to manage groups from the CLI.
What a group is
An IAM group is a collection of IAM users. You attach permissions policies to the group, and every member gets those permissions. Groups exist only to make permission management easier. A group has no password, no access keys, and no sign-in of its own, so it can never make a request. Only its member users do.
A group is not a principal. You cannot put a group in the Principal element of a resource-based policy such as a bucket policy. To grant access to a set of people through a resource-based policy, name the users, or use a role.
A group does appear as a resource. Its ARN looks like arn:aws:iam::111122223333:group/Developers. You use that ARN in the Resource element when you control who may administer the group, for example with iam:AddUserToGroup.
Rules and limits
- A group contains only users. It cannot contain other groups, roles, or federated identities.
- A user can belong to several groups, and to none.
- AWS has no built-in group that contains all users. If you want one, create it.
- Default quotas: 300 groups per account, 10 groups per user, and 10 managed policies attached to each group. These can be adjusted through Service Quotas. Check the current values before you design around them.
- Groups cannot be tagged. Users and roles can, so tag-based access control (
aws:PrincipalTag) works on users and roles but not on groups. - A group can have AWS managed policies, customer managed policies, and inline policies attached.
How group permissions combine
A user's effective identity-based permissions are the union of the policies attached to the user directly and the policies attached to every group the user belongs to. Group membership never takes permissions away. Only an explicit Deny does that, and an explicit Deny in any one of those policies wins over every Allow. Evaluation is covered in a later chapter.
In this diagram, bob gets only the Developers permissions. Alice gets Developers, Auditors, and her inline policy combined.
Creating and using a group
The following commands create a group, attach an AWS managed policy, create a user, and add the user to the group.
aws iam create-group --group-name Developers
aws iam attach-group-policy \
--group-name Developers \
--policy-arn arn:aws:iam::aws:policy/PowerUserAccess
aws iam create-user --user-name alice
aws iam add-user-to-group \
--group-name Developers \
--user-name alice
aws iam list-groups-for-user --user-name alice
aws iam get-group --group-name Developers
aws iam list-attached-group-policies --group-name Developerslist-groups-for-user answers "what can this person get from groups?". get-group lists the members of a group. list-attached-group-policies shows managed policies, and list-group-policies shows inline ones. Check both when you audit a group, because inline policies do not appear in the managed list.
To remove access, use remove-user-from-group for one person, or detach-group-policy to change what everyone in the group can do.
aws iam remove-user-from-group --group-name Developers --user-name alice
aws iam detach-group-policy \
--group-name Developers \
--policy-arn arn:aws:iam::aws:policy/PowerUserAccess
aws iam delete-group --group-name DevelopersGroups and roles together
A group cannot be assumed, and a role cannot be a member of a group. To let a group's members use a role, attach a policy to the group that allows sts:AssumeRole on that role's ARN.
{
"Version": "2012-10-17",
"Statement": [
{
"Sid": "AllowAssumeAuditorRole",
"Effect": "Allow",
"Action": "sts:AssumeRole",
"Resource": "arn:aws:iam::444455556666:role/ReadOnlyAuditor"
}
]
}This grants only one half of the access. The role's trust policy must also allow the caller. When the role is in the same account, either the group policy or the trust policy can supply the permission, depending on how the trust policy names its principal. For a role in another account, both sides must allow it. Roles and trust policies get their own chapters.
You can save the policy above as assume-auditor.json and attach it as an inline group policy.
aws iam put-group-policy \
--group-name Auditors \
--policy-name AssumeAuditorRole \
--policy-document file://assume-auditor.jsonDesign guidance
Groups work best when they match job functions, such as Developers, Auditors, or BillingAdmins, and not individual people. Some practical rules:
- Attach managed policies to groups, not inline policies. A managed policy is reusable and shows up in listings of attachments. An inline policy lives and dies with its group.
- Avoid attaching policies directly to users. Direct attachments are hard to find during audits. Put people in groups and review membership.
- Keep a group's purpose narrow. Combining several narrow groups per user is easier to reason about than one large group with exceptions.
- Limit who can change membership.
iam:AddUserToGroupon an administrator group is a privilege escalation path. Anyone who can add themselves to a group inherits its permissions. Restrict that action with the group's ARN in theResourceelement. - Remember that workloads should not be users in groups. Applications running on AWS should use roles with temporary credentials. Groups are for people who still need long-lived IAM users.
Common mistakes
| Mistake | What happens | Fix |
|---|---|---|
| Putting a group ARN in `Principal` of a bucket policy | The policy is rejected as invalid | Name users or a role as the principal |
| Expecting groups to nest | Adding a group to a group is not possible | Add the user to each group they need |
| Expecting a group to restrict a user | Groups only add permissions, apart from explicit `Deny` | Use an explicit `Deny`, a permissions boundary, or an SCP |
| Hitting the 10-managed-policy limit on a group | `attach-group-policy` fails with a quota error | Consolidate policies, or request a quota increase |
| Deleting a group with members | `delete-group` fails | Remove members and detach policies first |
Exercise
Alice belongs to the Developers group, which allows s3:* on all resources. She also belongs to the Contractors group, which has a policy with an explicit Deny on s3:DeleteBucket. Can Alice delete a bucket, and why? Separately, can you list the Developers group as the Principal in a bucket policy?
Show answer
Alice cannot delete a bucket. Her effective permissions are the union of all her groups' policies, but an explicit Deny in any of them overrides every Allow, so the Contractors Deny wins over the s3:* Allow from Developers. No, you cannot name a group as a Principal. Groups are not principals and cannot make requests. Name the individual users or a role instead.