Swiftorial Logo
Home
Swift Lessons
Matchups
CodeSnaps
Tutorials
Career
Resources

AWS Security: Service Roles & Trusted Entities

1. Introduction

AWS IAM (Identity and Access Management) provides a framework for managing access to AWS resources securely. Understanding service roles and trusted entities is crucial for implementing effective security measures.

2. Key Concepts

  • Service Role: An IAM role that allows AWS services to perform actions on behalf of a user.
  • Trusted Entity: An AWS account or service that is allowed to assume a role.
  • AssumeRole: A call made to assume a role, gaining temporary security credentials.

3. Service Roles

Service roles are used by AWS services to perform actions on your behalf. For example, when you launch an Amazon EC2 instance, you can assign a service role that allows it to access other AWS resources.

Note: Always grant the least privilege necessary when defining a service role.

4. Trusted Entities

A trusted entity can assume a role to perform actions. Trusted entities can be AWS services, IAM users, or other AWS accounts. Understanding who can assume a role is critical for controlling access.

5. Code Example

The following AWS CLI command creates a service role that allows an EC2 instance to access S3:

aws iam create-role --role-name MyEC2Role --assume-role-policy-document file://trust-policy.json

Example trust policy (trust-policy.json):

{
    "Version": "2012-10-17",
    "Statement": [
        {
            "Effect": "Allow",
            "Principal": {
                "Service": "ec2.amazonaws.com"
            },
            "Action": "sts:AssumeRole"
        }
    ]
}

6. Best Practices

  1. Define roles with the minimum permissions required.
  2. Regularly audit roles and their permissions.
  3. Use IAM policies in conjunction with service roles for granular control.
  4. Implement logging and monitoring for role usage.

7. FAQ

What is the difference between a user and a role in IAM?

A user is an entity that represents a person or an application, while a role is an AWS identity that has specific permissions and can be assumed by trusted entities.

Can a service role be assumed by multiple services?

Yes, a service role can be assumed by multiple services provided that the trust policy allows it.

How do I know which roles are being used?

You can use AWS CloudTrail to monitor and log all the actions taken by roles in your AWS account.