IAM Roles
Hello Everyone
Welcome to CloudAffaire and this is Debjeet.
In the last blog post, we have discussed IAM Groups.
https://cloudaffaire.com/iam-groups/
In this blog post, we are going to discuss IAM Roles. We will also create our 1st IAM role.
IAM Roles:
An IAM role is similar to an IAM user, in that it is an AWS identity with permission policies that determine what the identity can and cannot do in AWS. However, instead of being uniquely associated with one person, a role is intended to be assumable by anyone who needs it. Also, a role does not have standard long-term credentials such as a password or access keys associated with it. Instead, when you assume a role, it provides you with temporary security credentials for your role session.
You can use roles to delegate access to users, applications, or services that don’t normally have access to your AWS resources. For example, you might want to grant users in your AWS account access to resources they don’t usually have, or grant users in one AWS account access to resources in another account. Or you might want to allow a mobile app to use AWS resources, but not want to embed AWS keys within the app (where they can be difficult to rotate and where users can potentially extract them). Sometimes you want to give AWS access to users who already have identities defined outside of AWS, such as in your corporate directory. Or, you might want to grant access to your account to third parties so that they can perform an audit on your resources.
Roles can be used by the following:
- An IAM user in the same AWS account as the role
- An IAM user in a different AWS account than the role
- A web service offered by AWS such as Amazon Elastic Compute Cloud (Amazon EC2)
- An external user authenticated by an external identity provider (IdP) service that is compatible with SAML 2.0 or OpenID Connect, or a custom-built identity broker.
Role types and usage:
- AWS service role: A role that a service assumes to perform actions in your account on your behalf. When you set up some AWS service environments, you must define a role for the service to assume. This service role must include all the permissions required for the service to access the AWS resources that it needs. Service roles vary from service to service, but many allow you to choose your permissions, as long as you meet the documented requirements for that service. Service roles provide access only within your account and cannot be used to grant access to services in other accounts. You can create, modify, and delete a service role from within IAM.
- AWS service role for an EC2 instance: A special type of service role that an application running on an Amazon EC2 instance can assume to perform actions in your account. This role is assigned to the EC2 instance when it is launched. Applications running on that instance can retrieve temporary security credentials and perform actions that the role allows.
- AWS service-linked role: A unique type of service role that is linked directly to an AWS service. Service-linked roles are predefined by the service and include all the permissions that the service requires to call other AWS services on your behalf. The linked service also defines how you create, modify, and delete a service-linked role. A service might automatically create or delete the role. It might allow you to create, modify, or delete the role as part of a wizard or process in the service. Or it might require that you use IAM to create or delete the role. Regardless of the method, service-linked roles make setting up a service easier because you don’t have to manually add the necessary permissions.
- A role for cross-account access: A role that grants access to resources in one account to a trusted principal in a different account. Roles are the primary way to grant cross-account access. However, some AWS services allow you to attach a policy directly to a resource (instead of using a role as a proxy). These are called resource-based policies, and you can use them to grant principals in another AWS account access to the resource. The following services support resource-based policies for the specified resources: Amazon Simple Storage Service (S3) buckets, Glacier vaults, Amazon Simple Notification Service (SNS) topics, and Amazon Simple Queue Service (SQS) queues.
Next, we are going to create a role for EC2 instance to use CloudWatch Agent which was one of the prerequisites for below blog post.
https://cloudaffaire.com/cloudwatch-agent/
Step 1: Login to AWS console and navigate to IAM.
Step 2: Navigate to ‘Roles’ and click ‘Create role’.
Step 3: Select ‘EC2’ service and click ‘Next: Permissions’.
Step 4: Select the policy and click ‘Next: Add tags’.
Step 5: Provide a tag (optional) and click ‘Next: Review’.
Step 6: Provide a name and click ‘Create role’.
Our IAM role successfully created.
You can add
Or add to an existing EC2 instance
Hope you have enjoyed this article. In the next blog post, we will discuss MAF or multi-factor authentication for IAM user.
To get more details on IAM, please refer below AWS documentation
https://docs.aws.amazon.com/iam/index.html