visit
Today we’ll finally clarify IAM. Specifically when to use Users vs when to use Roles. This is a confusing topic for many people but with the visuals and examples I’ll share, you’ll realize it’s surprisingly simple.
Hi, I’m Dylan, a Cloud Engineer living in Oregon. So you’re using AWS for the first time, or 50th, and you want your friend to help you write and deploy a Lambda function.By default, all resources in AWS are locked. You have to specifically give permissions to the resource to get it to work. The reason for this is security. And follows the widely accepted principle of least privilege.
The Principle of Least Privilege states that “A subject should be given only those privileges needed for it to complete its task. If a subject does not need an access right, the subject should not have that right.”
IAM is the AWS service that tracks privilege every time an AWS resource gets used. For example, if you want to create an EC2 instance, AWS checks who you are and your privileges to see if you can.In order to make sure you can create that EC2 instance IAM needs to know at least two things, who you are, and what you’re allowed to do. Wait, Dylan, there are 4 parts to IAM, Users, Groups, Roles, and Policies. How can you only need two?
IAM’s four parts can be split up into those two categories. Users, Roles, and Groups tell IAM who or what you are, and Policies define what you can do.
Now to make sense of the confusing part; who has access, and specifically when to use users vs roles. There is one caveat I will say in a minute but to start, let me make it really easy.Users are for people, and roles are for AWS resources.Let’s go through some examples. A Lambda function needs to access Dynamo DB. The Lambda function needs a Role because it’s an AWS resource. And a policy attached to the role that allows access to Dynamo DB.A developer in your company needs to spin up an EC2. The developer just needs to have a user account because they are a person. Note, if you are logged into the AWS console, you are currently an IAM User. And a policy attached to allow creating EC2 instances. Side note, users are what you log in as using a name and password when you sign into the AWS console.
An administrator in your company needs access to all AWS resources. Do they need a user or a role? Because they’re a person, that’s right a user. What kind of policy needs to be attached? Yep, an all-access policy.
Those are the basics, and you can get far with them. As I mentioned there is one caveat. Users can assume a temporary role.
Let’s update how this applies to AWS resources and people.To clarify, roles can be assumed by both AWS resources and Users. While Users can only be assumed by people.AWS made this functionality because sometimes we need to give people temporary permission to certain resources.
A user assuming a role is like letting a plumber into your house to fix a pipe. They normally can’t just walk into your house, but you give them temporary permission to get a job done. Then when they fix your pipe, they are no longer allowed in your house.For example, you want to give a developer who only has access to S3 and Lambda temporary access to EC2 to help out on a project. You would give the user a role with a policy attached that allows access to EC2. The user needs to accept and assume the role. Then once the project is done you can then revoke access to the role and they can no longer use EC2.