角色与组

AWS 官方站点将角色读取为权限集合,将组读取为用户集合。但在我看来他们还是一样的。您将策略附加到组或角色,然后将组或角色分配给用户。角色和团队之间到底有什么不同?

36282 次浏览

AWS Groups are the standard groups which you can consider as collection of several users and a user can belong to multiple groups.

AWS IAM Roles are all together different species; they operate like individual users except that they work mostly towards the impersonation style and perform communication with AWS API calls without specifying the credentials.

Given that IAM Roles are little different, I am emphasizing only that. There are several types of IAM Roles like EC2 IAM Roles, Lambda etc. If you consider, you can launch an EC2 instance with an EC2 IAM Role; hence forth any AWS API related communication wouldn't require any AWS Access Key or Secret key for authentication rather can call the APIs directly (however the long answer is - it uses STS and continuously recycles the credentials behind the scenes); the privileges or permissions of what it can do is determined by the IAM Policies attached to the IAM Role.

Lambda IAM Role works exactly the same, except that only Lambda function can use the Lambda IAM Role etc.

Short answer for googlers: you can't assign role to user.

  • group is a bunch of users with the same policies
  • role is a preset of policies for service(s)

Users can asume roles according to AWS docs:

Assuming a Role

Users: End User (Think People).

Groups: A collection of users under one set of permissions (permission as policy). As per IAM standards we create groups with permissions and then assign user to that group.

Role: you create roles and assign them to AWS resource (AWS resource example can be a customer, supplier, contractor, employee, an EC2 instance, some external application outside AWS) but remember you can't assign role to user.

It’s not only users who will login, sometimes applications need access to AWS resources. For example, an EC2 instance might need to access one or more S3 buckets. Then, an IAM role needs to be created and attached to the EC2 instance. That role can be re-used by different EC2 instances.

Remember : Groups are for living. Roles are for non-living.

Only one IAM Role can be assumed at a time! And there are several situations which fits exactly this kind of permission.

Read the faq about: How many IAM roles can I assume?

The underlaying tool in use is "Permission" in both of the use cases namely: Group and IAM Role.

Group or IAM Role --> Has Policy --> Policy defines permisions --> Permissions are assigned to a Group or IAM Role.

I was confused all the time about the difference between these two functions.

In short,

Role is like a tag with all the preset policies that can attach on IAM users/groups or AWS services. IAM users share the same account with the account root user (Admin) but with assigned permissions by the root user to use AWS resources within that account.

Therefore, IAM users can directly interact with AWS services; whereas IAM roles cannot make direct requests to AWS services, they are meant to be assumed by authorised entities like an IAM user or an instance. https://aws.amazon.com/iam/faqs/

I think of an AWS Role as a kind of 'sudo', where each AWS Role can temporarily provide a very specific set of elevated privileges, but without needing the elevated credentials. I get the impression that like sudo, AWS Roles try to prevent privileged actions being used accidentally. I'd be interested to hear if others agree with this analogy.

Please note that Groups are specific to local IAM users, which are not federated, and local IAM user logs do not show who has done the actions (i.e.., multiple people or applications could use the same long-term secret/access keys, and there is no record of which entity used them). If you must use local IAM users, you can place them into IAM Groups. Where this can be especially useful is to serve as a boundary -- you could place a deny policy on the group, restricting access to specific services or actions, and that deny policy will be applied to all users in the Group.

Conversely, roles can be federated, whereas local IAM users are not. You might create an on-premises AD group that serves as a member container, for example, and then the members of that AD group (and only they) can use the role that the AD group correlates to, with whatever allow or deny policies and/or permissions boundaries you've applied to the role. (Here is a link explaining the AWS ADFS federation.)

Importantly, roles allow for temporary session credentials (which is a best security practice), as their session tokens expire after a maximum of 12 hours. Equally importantly, roles do show in the logs which of the AD members with access to use the role actually did the action. You'll find this tacked to the end of the role ARN in the logs (e.g., a user ID). CloudTrail would be one of several services that indicate user activity. This is important from a logging standpoint.

I had a hard time deciphering the spirit of the given answers..

Here's what I've found:


Groups:

  • Intended to represent human users created within IAM who need identical policies.

    • Ex. Dev 1 - Dev 8 are all developers, and all need access to create dev servers.
    • This is similar to traditional desktop users/groups, but for HUMAN users only.

Roles:

Roles rotate automatic credentials, meaning password input isn't needed for accessing policies.

This makes it good for two things:

  1. Giving permissions to non-humans, such as services / applications.

    • Ex. EC2 of type A needs access to S3 of type B.
  2. Giving permissions to federated / outside users & groups.

    • Ex. Contractor A @ Outside Company A needs access to your Server A.
      • Authentication of users & groups are handled by some service, like Azure AD.
      • Authorizations are then mapped to your IAM role(s), NOT users or groups.
        • Note: I've used Jumpcloud's Article & AWS's Documentation to gather this information. The terms "Group", "Role", and "User" become overloaded in context to SSO+IdP, and IAM.

        • Here's an image showing how they map roles. !Need 10 Reputation :(

Aside: There is a way of assigning Roles to normal IAM Users & Groups, but it appears to be bad practice.


Hopefully this provides clarity to the answers above.