IAM - Identity Access Management
Published: 2023-10-21 06:08:05


Hello, everyone! I hope you're all doing well. Welcome to the first week of the #12weeksawschallenge. This week, we will delve into AWS's IAM service, which enables you to regulate access to resources, determine how access is granted, and specify the actions that can be performed. These are just a few of the capabilities of IAM. Let's explore what it can do and how it accomplishes these tasks.

## Introduction


To all those who are new to my blog series, I extend a warm welcome. I am writing these blogs as part of the #12weeksawschallenge, which is designed to introduce AWS Cloud in a more practical manner. You can find additional information about #12weeksworkshops on their official website [here](https://12weeksworkshops.com/).

In this challenge, I am currently in week 1, where the primary focus is on AWS IAM, which stands for Identity and Access Management. IAM plays a crucial role in managing who has access to AWS resources and how they can utilize them. It effectively controls access in the AWS cloud environment.


In this post, we will delve into several key topics related to Identity and Access Management (IAM) in AWS. 

1. What is IAM?
2. Significance of IAM
3. What is Shared Responsibility Model?
4. How one can access AWS cloud services?
5. Various entities in IAM
6. Policy Evaluation

Let's explore these topics in detail to gain a better grasp of AWS Identity and Access Management.

## IAM - Identiy and Access Management

"IAM is a web service that helps you securely manage access to AWS resources. IAM enables you to configure who can access AWS resources, what specific resources a user can access, and the actions they are permitted to perform."

Now let's see in detail of some capabilities of IAM
1. **Share access to AWS account**
   &nbsp; &nbsp; &nbsp; &nbsp; IAM allows us to share resources with other users, without actually sharing our credentials

2. **Granular permissions**
   &nbsp; &nbsp; &nbsp; &nbsp; IAM enables you to grant permissions with a high level of granularity. You can grant a user the ability to administer resources alongside you, or you can restrict a user to only accessing resource names and nothing more.

3. **Secure Access to applications on EC2 instance**
   Sometimes, our applications may require data from an Aurora DB. In such cases, we need to provide credentials. However, it's not considered a standard practice to pass credentials directly. Instead, IAM offers a mechanism to achieve this using an entity called Role, which we will explore later in this post.

When looking at the multitude of tasks that IAM (Identity and Access Management) can perform, one may wonder how it efficiently accomplishes these functions. As users who utilize IAM, it's important to comprehend its inner workings and tailor its configurations to our specific needs. IAM achieves its capabilities through the use of key components such as users, user groups, policies, and roles. To gain a comprehensive understanding of IAM, let's delve into these elements in detail.

### [IAM Users](https://docs.aws.amazon.com/IAM/latest/UserGuide/id_users.html)



![User](https://dev-to-uploads.s3.amazonaws.com/uploads/articles/hod9w8g7fp6j4yzntrmn.png)


An IAM user is an entity created in the AWS cloud, representing a human user who utilizes IAM to interact with AWS. The user possesses a name and credentials for authentication.

##### Types of Users

There are two types of users

1. **Root User**
   - Root user is also the Account owner, this account was created while the account was created.
   - This account has un-restricted access hence it was recommended not to use this account for everyday activities


2. **AWS IAM User**
  - These IAM users are created by administrator as per the business needs. 
  - These users will be having restricted access to the resources


##### Identifying The User

1. **Friendly Name**
<small>
  - The name of the user that which was given during user creation.
  - This was visible in the Management Console
</small>


2. **Amazon Resource Name(ARN)**
<small>
 - A user can be uniquely identified using it's ARN, which helps us  in during policy creations.
 - ARN looks similar to <center>`arn:aws:iam::accountId>:user/<userName>`</center>
 - Can be accessed from Management Console
</small>



3. **Unique Identifier**
<small>
 - This was an ID returned only when API tools were used to create the user
 - This can't be seen in the Management Console
</small>

#### Root User Best Practices

   Best Practices are some standard set of procedures users can adopt in order to keep their accounts safe. Some of them are

- This root user was not recommended for everyday activities
- To have an Administrative access over all the resource create an IAM Admin user
- Enable a Virtual MFA Device for your AWS Account Root User
- Configure Account Security Challenge Questions

and there were more which you find it [here](https://catalog.us-east-1.prod.workshops.aws/workshops/18b3622c-5d4c-45c9-9834-6a7091109072/en-US/basic-modules/20-identities-and-access-management/1-users/2-1-1)



### [IAM User Groups](https://docs.aws.amazon.com/IAM/latest/UserGuide/id_groups.html)

A User Group is a collection of users that _<u>allows us to specify permissions for multiple users, simplifying the management of permissions</u>_. These groups pertain to permissions rather than authentication.

![Imuser group](https://dev-to-uploads.s3.amazonaws.com/uploads/articles/en852gs1xwhresx4532s.png)
<center><small>An example of user groups based on roles</small>
<br></center>

>Some characteristics of User groups are 

>1. A user group can encompass multiple users but cannot include another user group within it.

>2. A user can be a member of multiple groups, not limited to just one group.

### [IAM Roles](https://docs.aws.amazon.com/IAM/latest/UserGuide/id_roles.html)

Roles is an similar entity to User, which has permission policies that can decide what identity can do or can't do.But this roles are not uniquely associated with one person._<u>Roles when ever they are assumed they provide temporary security credentials for your session</u>_

<br>
![Role access](https://dev-to-uploads.s3.amazonaws.com/uploads/articles/g25jskr7g9nbohc4r7yi.png)
<center><small>In a scenario, a developer was initially denied access to production logs. However, they proceeded to assume a production role and were subsequently able to access the logs.</small>
<br></center>

<br>
>Roles are used to delegate access when users/applications/services that don't normally have access to a resource

###  [IAM Policy](https://docs.aws.amazon.com/IAM/latest/UserGuide/access_policies.html)

Permissions in AWS are represented using policies, and these policies are attached to IAM identities or AWS resources.AWS evaluates these policies when an principal(user or role) makes a request

Most Policies are stored as JSON documents and there are 6 different types of policies they are,

#### Types of IAM Policies
 1. <strong>Identity Based Policies</strong>
  - These are JSON policy documents  attached to identities
  - These permissions include what type of effect(allow/deny) should be taken on what actions under what circumstances(conditions)

 2. <strong>Resource Based Policies</strong>
   - These are JSON policy documents attached to resources
   - These Specifies grant to the principals who can use them

 3. <strong>Permission Based Policies</strong>
    - Advanced feature that allows you to set maximum permissions that an identity can grant to an entity

 4. <strong>Organization SCP's</strong>
 5. <strong>Access Control Lists</strong>
   -  ACL is a service that which allows you to control which principals from another account can access a resource
   - Similar to resource based policy but this was not and JSON policy document

 6. <strong>Session policies</strong>
    - Advanced Policies that allows you to pass a param when you pragmatically create temporary sessions
 
 
![Policy](https://dev-to-uploads.s3.amazonaws.com/uploads/articles/14fp55sg421e6v961ti8.PNG)
 <center><small>Structure of a simple policy</center>

### Time to build

Now we got to know about how permissions work. So let's work put our learning into practice by building a simple use case (scenario mentioned in immersion day)

You can also find this lab from aws workshops [here](https://catalog.workshops.aws/general-immersionday/en-US/basic-modules/30-iam/iam)

![Use Case architecture](https://dev-to-uploads.s3.amazonaws.com/uploads/articles/r6i9j5b1ybsnrdbyxanw.png)

<center><small>A simple usecase given by Amazon which helps us in getting practical touch of what we have seen till now</small>
<br></center>

<hr>

Thank you all for following along, I sincerely hope this was not boring, but I feel this was bit lengthy and this was the perfect time that you take a break and continue further. Have a cup of water or move way for some from your desk and after a short break let's continue building the use case

<hr>

Now let's resume back, If we see the architecture we require multiple instances of EC2, A user, User Group and Policy. So Now let's create all of them one by one and once all of them were ready let's align them according to the architecture


#### 1. Creating EC2 instances

-  Go to AWS management console and navigate through EC2 Dashboard

![Step-0](https://dev-to-uploads.s3.amazonaws.com/uploads/articles/ms8p3ir2fv9zrrdwvzjc.PNG)
<center><small>Step-1 Login to the management Console and navigate to EC2 Dashboard</small></center>

- In the EC2 Dashboard select on **Launch Instance**

![Step-2 Launch Instances](https://dev-to-uploads.s3.amazonaws.com/uploads/articles/xtrjz0loq0bbofgxhyus.PNG)
<center><small>Step-2 Click on launch Instance</small></center>

- Now create an EC2-instance with name `dev-instance` and add it a new tag as follows `Env-dev`

![Dev inst](https://dev-to-uploads.s3.amazonaws.com/uploads/articles/ezqi1cb48j9kxzzjlsvw.PNG)
<center><small>Step-3.1 Creating an instance within development environment</small></center>

- Now create an EC2-instance with name `prod-instance` and add it a new tag as follows `Env-prod`

![prod](https://dev-to-uploads.s3.amazonaws.com/uploads/articles/hz4mh2p6tu2dogq84v6m.PNG)

<center><small>Step-3.2 Creating an instance within production environment</small></center>

- you can also refer to the configurations of both instances here

> <center><table><thead><tr><th>Attribute</th><th>Value</th></tr></thead><tbody><tr><td>Name</td><td>prod-instance</td></tr><tr><td>Env</td><td>prod</td></tr><tr><td>Application and OS Images</td>
<td>Amazon Linux</td></tr><tr><td>Instance type</td><td>t2.micro</td>
</tr><tr><td>Key pair</td><td>proceed without a key pair</td></tr><tr><td>Security Group</td><td>default</td></tr></tbody></table></center>

> <center><table><thead><tr><th>Attribute</th><th>Value</th></tr></thead><tbody><tr><td>Name</td><td>dev-instance</td></tr><tr><td>Env</td><td>dev</td></tr><tr><td>Application and OS Images</td>
<td>Amazon Linux</td></tr><tr><td>Instance type</td><td>t2.micro</td>
</tr><tr><td>Key pair</td><td>proceed without a key pair</td></tr><tr><td>Security Group</td><td>default</td></tr></tbody></table></center>

- Now, click on launch after entering appropriate details

<br>

> <strong>Note. </strong>: I've used default security group and no key pair in an intention not to create new resources but you can create new resources and apply them here

- once done you should have two instances running 

![S-4](https://dev-to-uploads.s3.amazonaws.com/uploads/articles/2s6k63j5qcjnl43hh5u9.PNG)

<center><small>Step-4 Verify your instances</small></center>

#### 2.Creating a Policy
- Go to IAM Dashboard and click on policies

![Step-1 ](https://dev-to-uploads.s3.amazonaws.com/uploads/articles/5lmy9wkjenbgx81zkuxc.PNG)

<center><small>Step-1 Go to IAM Dashboard</small></center>

- Click on Create policy


![Step-2](https://dev-to-uploads.s3.amazonaws.com/uploads/articles/wgtzbow1we4qyv064m8l.PNG)

<center><small>Step-2 Click on create Policies</small></center>

- Now we are in policy create Policy page let's use both Visual and JSON methods to add permissions
 - First, in the visual editor select the following configuration
   ![Step-3.1](https://dev-to-uploads.s3.amazonaws.com/uploads/articles/zi3peo752vegp630mhcd.PNG)
 <center><small>Step-3.1 Creating a permission to perform any action on EC2 instance of dev-env</small></center>

 - Now, switch to the JSON editor and append this in the statement Object (Ive edited my json such that it allows all Describe actions instead of writing whole JSON code)
   ![Step-3.2](https://dev-to-uploads.s3.amazonaws.com/uploads/articles/k69zgoyvb1xjvromlq74.PNG)
 <center><small>Step-3.2 Creating a permission to perform any kind of Describe actions on any EC2 instance</small></center>

 - Now, Switch back to visual editor and add this rule   
   ![Step-3.3](https://dev-to-uploads.s3.amazonaws.com/uploads/articles/gnueht7amv9rm8upppol.PNG)
 <center><small>Step-3.3 Creating a permission which denes user </small></center>

 - Now we have all the permissions required now click on next and enter the details
  ![Step 3.4](https://dev-to-uploads.s3.amazonaws.com/uploads/articles/4owo0c1oksubr682xpis.PNG)
  <center><small>Step-3.4 Creating policy </small></center>
 
- Now click on **Create Policy** and your policy was created
![Step 4](https://dev-to-uploads.s3.amazonaws.com/uploads/articles/mw88p8e2menor3uvldxj.PNG)
     <center><small>Step-4 Now Click on Create Policy </small></center>

#### 3.Creating a User Group

- Now quickly go to IAM Dashboard and select User Groups and click on **Create Group**
  ![Step-01](https://dev-to-uploads.s3.amazonaws.com/uploads/articles/r410ppqjcdxeb2qgrtdx.PNG)
  <center><small>Step-1 IAM Dashboard>User Groups > Create Group </small></center>


- Now name your user group and leave the other configurations like Add Users and Attach Policies, as we'll deal with them later
  ![Step -02](https://dev-to-uploads.s3.amazonaws.com/uploads/articles/le8nf56vhj9zjr3j5dhh.PNG)
  <center><small>Step-2 Name your User Group </small></center>

- Now click on Create Group button and your user group is ready to use


#### 4.Create A User

- Now go to IAM Dashboard navigate to users and click on Create User
  ![Step -1 ](https://dev-to-uploads.s3.amazonaws.com/uploads/articles/pxvzblyjyjn04fhe048m.PNG)
 <center><small>Step-1 IAM Dashboard > Users > Create User </small></center>

- Now enter the user name as desired and select the following options and click on Next
  ![Step -2](https://dev-to-uploads.s3.amazonaws.com/uploads/articles/onn6qfkskl8di4emcurb.PNG)
  <center><small>Step-2 Configuring Username and Password </small></center>

- Now skip all other steps as we'll add the user in fore coming steps and also the policies
- Now create the user, when it's better to download the csv file and store in a safe place
- Now copy the user signin link which will be helpful for us in further steps


With this we had all the required components.So, let us start connecting the components 

#### 5. Aligning the components according to architecture Diagram

1. Go to the User Group you had created and add user to the group
User Group > Users > Add Users
  ![adding use to grp](https://dev-to-uploads.s3.amazonaws.com/uploads/articles/0n388h02khuikpoi1mqc.PNG)
  <center><small>Step-1 Adding user to the user group</small></center>

2. Now attach the policy you've created to the user group
User Group > Permissions > Add Permissions
  ![s2](https://dev-to-uploads.s3.amazonaws.com/uploads/articles/hqpl4guq3z321ggo6zkb.PNG)
  <center><small>Step-2 Attaching permission to the user group</small></center>

3. Now verify whether you were able to see the instances in the EC2 Dashboard
 ![s3](https://dev-to-uploads.s3.amazonaws.com/uploads/articles/4lrl1nqrbaqrrc98h53w.PNG)
 <center><small> We were able to see all the instance which means Rule-2 was in action</small></center>

4. Now try to terminate any instance , you will encounter an error which means the 3rd rule was also in action
  ![s4](https://dev-to-uploads.s3.amazonaws.com/uploads/articles/2fotwhd1mq16e5ava3hh.PNG)
    <center><small>Picture shows the error message when tried to terminate the instance</small></center>


Now this shows us how permissions in AWS are attached to the users, we saw from What is IAM what does it provides, and saw how we can actually implement those features using Policies and IAM entities. 

## Programmatic Access

It was important to how we can access our resources via command line tools or SDK provided by AWS. So, Now let's see how we can enable the user to access resources from Command line.

Consider a scenario Your mentor has requested you to verify if you have access to a specific bucket. To accomplish this, you need to list all the buckets and confirm whether the particular bucket is present in the list. Assume that you have the necessary permissions to create a user.

1. Go to Users Page from IAM dashboard and Click on Create User      
    ![Programatic Access Step-1](https://dev-to-uploads.s3.amazonaws.com/uploads/articles/vq3o24m7qoh71yg1wq8s.PNG)
2. On the current page, enter the username and click 'Next.' Since we only require command-line permissions, we are not granting access to the Management Console.
3. On the Permissions page, retain all default values and proceed to the next step to create the user. 
4. You now have an IAM user with no attached policies. Next, we'll create access keys for the user.Which allows him to access CLI
5. From the user dashboard, select the user you have created and navigate to the 'Security Credentials' tab.
       ![Step-2 Programatic Access](https://dev-to-uploads.s3.amazonaws.com/uploads/articles/w61lin24k5bp9wlnykua.PNG)

6. Select the "Command Line Interface" use case, check the checkbox, and proceed to the next step.
       ![Step-3 PA](https://dev-to-uploads.s3.amazonaws.com/uploads/articles/13ri43kzxxwrjevbn4fm.PNG)
7. Now leave the tag value as empty and click on **Create access Key**
8. It's important to download the access key, which was created by AWS itself. To do so, click on the button to download the key in CSV format.

Now we had a user who has Command Line access. So, let's see what to do next

1. Download and Install Amazon CLI from [here](https://docs.aws.amazon.com/cli/latest/userguide/getting-started-install.html)
2. Now check if your installation was successful or not
   ![Shell](https://dev-to-uploads.s3.amazonaws.com/uploads/articles/682ysurrhn3z8hmbdgb5.PNG)
3. Now that we have the AWS CLI installed, we need to configure it by using the `aws configure` command and entering the access key details from the CSV file you downloaded earlier.
   ![shell](https://dev-to-uploads.s3.amazonaws.com/uploads/articles/keu79dwgffhv6zezr7qv.PNG)
4.Now let's try to get the list of all buckets which we had using `aws s3 ls`
5. Oops! We encountered an error: Access denied
    ![shell](https://dev-to-uploads.s3.amazonaws.com/uploads/articles/4ch2w4ynmg64kbsq4ehq.PNG)
6. No problem, we know what to do now. Let's take it as a challenge and try to get it working.

<hr>

Once again thank you so much for following upto here, I hope this article was useful to you. Meet you all soon in the next blog, Have a great time ahead.

I would really like to hear your valuable suggestions and in case of any queries , You can reach out to me at
LinkedIn : Vignesh bandla
Email : vignesh.bandla01@gmail.com