AWS IAM Security Best Practices & Checklist

0xffccdd
19 min readJun 21, 2022

--

If you are using Amazon Web Services (AWS), it is important to understand the concept of AWS Identity and Access Management (IAM). IAM is a powerful tool that allows you to control access to AWS resources.

One of the most important aspects of IAM is the use of access keys. Access keys are used to authenticate users and provide them with access to AWS resources.

However, access keys can also be a security risk. If access keys are compromised, they can be used to access AWS resources without your permission.

To help mitigate this risk, it is important to understand how to properly use and manage access keys. In this blog post, we will share some best practices for using access keys in AWS IAM.

We’ve built a platform for Cloud Detection & Response in AWS including IAM, Azure, and GCP — you can grab a demo here. You can also download free playbooks we’ve written on how to respond to security incidents in AWS, Azure, and GCP.

How to disable the AWS root account

AWS provides a root user for every AWS account. This root user has complete access to all AWS resources in your account. We recommend that you do not use the root user for your everyday tasks, even the administrative ones. Instead, create individual IAM users for people or applications that need access to AWS resources, and then grant each user only the permissions they need. To prevent accidental or unwanted actions, you can also disable the root user for your AWS account.

If you have never used the root user for your AWS account, it might be a good idea to delete the root user altogether. For more information, see Deleting the Root User.

To disable the root user for your AWS account-

Open the IAM console. In the navigation pane, choose Users. Select the check box next to the root user. Choose More Actions, and then choose Delete User. When prompted for confirmation, choose Yes, Delete.

After you have disabled the root user for your AWS account, you can no longer use it to sign in to the AWS Management Console or make API calls. If you need to access the root user for your AWS account, you can do so by creating an IAM user and giving that user the necessary permissions.

How to Grant least privilege in AWS IAM

Most organizations, when they think about least privilege, think about it in terms of the principle of least privilege for users. That is, users should only have the permissions they need to do their jobs, and no more. But least privilege is just as important for AWS resources. Just like you wouldn’t want a user to have more permissions than they need, you also don’t want an AWS resource to have more permissions than it needs.

The good news is that AWS IAM (Identity and Access Management) has a number of features that make it easy to implement least privilege for AWS resources. In this blog post, we’ll take a look at some of those features and how you can use them to grant least privilege to your AWS resources.

First, let’s take a look at IAM roles. IAM roles are a way to give permissions to AWS resources. They’re like user accounts, but for resources. IAM roles are an important part of least privilege because they allow you to give permissions to resources without giving those permissions to the users who are interacting with the resources.

For example, let’s say you have an Amazon S3 bucket that you want to allow users to upload files to. You could give the users permissions to upload files to the bucket, but then they would also have permissions to do other things, like delete files or change the permissions on the bucket. Instead, you can create an IAM role that has the permissions to upload files to the bucket, and then assign that role to the Amazon S3 bucket. Now, the users will be able to upload files to the bucket, but they won’t have any other permissions.

Another way to use IAM roles for least privilege is to use them to delegate permissions. For example, let’s say you have a team of developers who need to be able to deploy code to your Amazon EC2 instances. Instead of giving them permissions to do that, you can create an IAM role that has the permissions to deploy code, and then assign that role to the developers. Now, the developers will be able to deploy code, but they won’t have any other permissions on the EC2 instances.

Finally, IAM roles can be used to temporary permissions. For example, let’s say you have a script that needs to call the Amazon EC2 API to start an instance. You could give the script permissions to do that, but then the script would also have permissions to do other things, like terminate the instance. Instead, you can create an IAM role that has the permissions to start an instance, and then assign that role to the script. The role will only be valid for a limited time (you specify the duration), and then it will expire. This is a good way to make sure that a script or other program only has the permissions it needs for a short period of time, and then those permissions are revoked.

IAM roles are a powerful tool for least privilege, but they’re not the only tool. Another tool you can use is IAM policies. IAM policies are a way to give permissions to users, groups, and roles. They’re like IAM roles, but they’re for users, groups, and roles instead of resources.

IAM policies are a good way to give least privilege to users because they allow you to fine-tune the permissions that a user has. For example, let’s say you have a user who needs to be able to read files from an Amazon S3 bucket, but not write files to the bucket. You could create an IAM policy that allows the user to read files from the bucket, but not write files to the bucket. This would give the user the least amount of permissions possible to do their job.

IAM policies can also be used to give least privilege to groups and roles. For example, let’s say you have a group of users who need to be able to read and write files to an Amazon S3 bucket. You could create an IAM policy that allows the group to read and write files to the bucket. This would give the group the least amount of permissions possible to do their job.

IAM policies are a powerful tool for least privilege, but they have one downside: they can be hard to manage. If you have a lot of users, groups, and roles, and you want to give each one a different set of permissions, it can be hard to keep track of all the policies.

AWS IAM has a feature that can help with this: IAM resource-based policies. Resource-based policies are a way to give permissions to AWS resources. They’re like IAM roles, but they’re for resources instead of users, groups, and roles.

Resource-based policies are a good way to give least privilege to resources because they allow you to fine-tune the permissions that a resource has. For example, let’s say you have an Amazon S3 bucket that you want to allow users to read files from, but not write files to. You could create a resource-based policy that allows the users to read files from the bucket, but not write files to the bucket. This would give the users the least amount of permissions possible to do their job.

Resource-based policies can also be used to give least privilege to groups and roles. For example, let’s say you have a group of users who need to be able to read and write files to an Amazon S3 bucket. You could create a resource-based policy that allows the group to read and write files to the bucket. This would give the group the least amount of permissions possible to do their job.

Resource-based policies are a powerful tool for least privilege, but they have one downside: they can be hard to manage. If you have a lot of resources, and you want to give each one a different set of permissions, it can be hard to keep track of all the policies.

AWS IAM has a feature that can help with this: IAM resource tags. Resource tags are a way to add metadata to AWS resources. They’re like labels, but they’re for AWS resources instead of users, groups, and roles.

Resource tags are a good way to manage least privilege because they allow you to group resources together. For example, let’s say you have a set of resources that all need the same permissions. You can tag those resources with the same tag, and then create an IAM policy that gives the permissions to that tag. Now, all of the resources that are tagged with that tag will have the permissions that you specified in the policy.

Resource tags are a powerful tool for managing least privilege, but they have one downside: they can be hard to remember. If you have a lot of resources, and you want to give each one a different set of permissions, it can be hard to keep track of all the tags.

AWS IAM has a feature that can help with this (you may be seeing a pattern here!): IAM resource groups. Resource groups are a way to group AWS resources together. They’re like folders, but they’re for AWS resources instead of users, groups, and roles.

Resource groups are a good way to manage least privilege because they allow you to group resources together. For example, let’s say you have a set of resources that all need the same permissions. You can put those resources in the same resource group, and then create an IAM policy that gives the permissions to that resource group. Now, all of the resources in the resource group will have the permissions that you specified in the policy.

Resource groups are a powerful tool for managing least privilege, but they have one downside: they can be hard to remember. If you have a lot of resources, and you want to give each one a different set of permissions, it can be hard to keep track of all the resource groups.

How to use roles to delegate permissions in AWS IAM

Using roles to delegate permissions in AWS IAM is a great way to help manage your AWS environment. By creating roles and then assigning those roles to users or groups, you can give them just the right amount of access to the AWS resources that they need. In this blog post, we’ll show you how to create and assign roles in AWS IAM.

Creating a role in AWS IAM is simple. Just login to the AWS console and go to the IAM section. From there, click on “Roles” and then “Create New Role”. Give your role a name and description, and then select the “Role for Cross-Account Access” template. This template will allow you to give your role permissions to access resources in another AWS account.

Next, you’ll need to specify the trust relationship for your role. This is the account or accounts that you want to be able to assume this role. For our example, we’ll specify the account ID of our production account.

Now it’s time to add some permissions to our role. We can do this by attaching IAM policies. For our example, we’ll add the AmazonS3FullAccess policy. This will give our role full access to Amazon S3.

Finally, we’ll need to specify a role session name. This is the name that will be used when a user or group assumes this role.

Once you’ve created your role, you can now assign it to a user or group. To do this, go to the “Users” or “Groups” section in IAM and select the user or group that you want to assign the role to. Then, click on the “Add inline policy” button and select the “Attach existing policies directly” option. From there, you can search for and select the role that you just created.

Now, when a user or group assumes this role, they will have the permissions that you’ve specified. This is a great way to delegate permissions in AWS IAM and help manage your AWS environment.

How to use AWS managed policies

AWS managed policies are a great way to control access to your AWS resources. By creating and attaching policies to IAM users, you can fine-tune their permissions to exactly what you want them to be able to do. In this blog post, we’ll walk you through the process of creating and attaching policies, and show you how to use them to control access to your resources.

First, let’s take a look at the different types of AWS managed policies. There are two main types:

1. Customer Managed Policies

2. AWS Managed Policies

Customer managed policies are policies that you create and manage yourself. They can be attached to multiple users, groups, or roles, and you have full control over them. AWS managed policies are created and managed by AWS, and can only be attached to users, groups, or roles.

Now that we’ve covered the basics, let’s walk through the process of creating and attaching a policy.

1. Go to the IAM console and select “Policies” from the sidebar.

2. Click “Create Policy”.

3. Give your policy a name and description.

4. Select the “policy document” option.

5. Paste in your policy document. This is the JSON document that defines the permissions for your policy.

6. Click “Create Policy”.

Your policy is now created! The next step is to attach it to a user, group, or role.

1. Select the “Attach Policy” button.

2. Select the users, groups, or roles you want to attach the policy to.

3. Click “Attach Policy”.

Your policy is now attached and will start enforcing the permissions you defined.

One of the great things about AWS managed policies is that they can be used to control access to any AWS resource, not just the resources in your account. For example, you can use a policy to allow a user to read from an S3 bucket, but not write to it. Or you can use a policy to allow a user to start and stop EC2 instances, but not terminate them.

The possibilities are endless, and policies give you a great way to fine-tune the permissions for your users. So if you’re not using policies yet, we encourage you to give them a try.

How to use Use customer managed policies instead of inline policies

If you’re using AWS Identity and Access Management (IAM) to control access to your AWS resources, you can use customer managed policies to centrally manage your permissions. Customer managed policies are JSON documents that you create and manage in your own AWS account. This gives you full control over your policy management, including the ability to attach, detach, and update policies as needed. In contrast, inline policies are embedded in individual IAM users, groups, or roles.

There are a few things to keep in mind when using customer managed policies:

• You can’t use customer managed policies to control access to IAM resources (such as users, groups, and roles). For this, you need to use inline policies.

• You can’t use customer managed policies to control access to AWS resources that are not managed by IAM (such as Amazon S3 buckets or Amazon DynamoDB tables). For this, you need to use resource-based policies.

• Customer managed policies can’t be used to grant permissions that are allowed by the AWS managed policies. For example, you can’t use a customer managed policy to grant the ability to create IAM users, because this is already allowed by the AmazonIdentityManagementFullAccess managed policy.

When should you use customer managed policies?

There are a few situations where customer managed policies can be helpful:

• When you want to centrally manage permissions for multiple IAM users, groups, or roles. For example, if you have a group of developers who need access to your Amazon S3 buckets, you can create a customer managed policy and attach it to the group. This way, you don’t need to individually manage the permissions for each IAM user in the group.

• When you want to use the same permissions in multiple IAM users, groups, or roles. For example, if you have a group of administrators who need access to your Amazon S3 buckets, you can create a customer managed policy and attach it to the group. Then, if you need to give the same permissions to another group of users, you can just attach the policy to the new group. You don’t need to recreate the policy.

• When you want to grant permissions to an IAM user that you created in another AWS account. For example, if you have a user in your development account who needs access to your production Amazon S3 buckets, you can create a customer managed policy in your production account and attach it to the user.

How do you create a customer managed policy?

There are two ways to create a customer managed policy:

• Use the AWS Management Console.

• Use the AWS Command Line Interface (CLI).

To create a customer managed policy using the AWS Management Console:

1. Open the IAM console.

2. In the navigation pane, choose Policies.

3. Choose Create Policy.

4. Choose the JSON tab.

5. Paste your policy document into the policy editor.

6. Choose Review Policy.

7. Enter a name and description for the policy.

8. Choose Create Policy.

To create a customer managed policy using the AWS CLI:

1. Use the create-policy command to create the policy.

2. Use the put-policy command to attach the policy to an IAM user, group, or role.

How do you attach a customer managed policy to an IAM user, group, or role?

There are two ways to attach a customer managed policy to an IAM user, group, or role:

• Use the AWS Management Console.

• Use the AWS Command Line Interface (CLI).

To attach a customer managed policy using the AWS Management Console:

1. Open the IAM console.

2. In the navigation pane, choose Policies.

3. Choose the policy that you want to attach.

4. Choose the Users, Groups, or Roles tab.

5. Choose the IAM user, group, or role that you want to attach the policy to.

6. Choose Attach Policy.

How to use Use access levels to review IAM permissions

In order to use AWS access levels to review IAM permissions, you first need to understand what IAM is and how it works. IAM is the Identity and Access Management service from Amazon Web Services. It is a secure way to control access to AWS resources. IAM provides a way to create and manage users and groups. It also provides a way to grant permissions to users and groups to access AWS resources.

IAM permissions are fine-grained. That means that you can grant a user permission to access only a specific AWS resource, or you can grant a user permission to access all AWS resources. You can also grant a user permission to access only certain actions on an AWS resource. For example, you could grant a user permission to read objects from an Amazon S3 bucket, but not write objects to the bucket.

When you create an IAM user, you specify the permissions that the user has. You do this by creating IAM policies. An IAM policy is a document that specifies who has what permissions. IAM policies are written in JSON.

You can attach IAM policies to users, groups, or roles. When you attach an IAM policy to a user, the user inherits the permissions in the policy. When you attach an IAM policy to a group, all users in the group inherit the permissions in the policy. When you attach an IAM policy to a role, any entity that assumes the role inherits the permissions in the policy.

In order to use AWS access levels to review IAM permissions, you need to have an IAM policy that allows you to perform the necessary actions. The AWS Policy Generator is a tool that can help you create IAM policies.

Once you have an IAM policy that allows you to perform the necessary actions, you can use the AWS Management Console to review the permissions that are assigned to IAM users and groups. To do this, open the IAM console and select the Users tab. Then, select the user or group that you want to review.

On the Permissions tab, you will see a list of the IAM policies that are attached to the user or group. You can click on each policy to view the details. The details will include the resources that the policy grants access to, and the actions that are allowed.

You can use the information on the Permissions tab to determine whether a user or group has too much or too little access. If you think that a user or group has too much access, you can remove one or more of the IAM policies that are attached to the user or group. If you think that a user or group does not have enough access, you can add one or more IAM policies.

It is important to note that IAM policies can be very complex. If you are not familiar with JSON, you may want to ask someone for help in creating or editing IAM policies.

In conclusion, you can use AWS access levels to review IAM permissions. To do this, you need to have an IAM policy that allows you to perform the necessary actions. You can use the AWS Management Console to review the permissions that are assigned to IAM users and groups. If you think that a user or group has too much or too little access, you can add or remove IAM policies as necessary.

How to Configure a strong password policy for your users in AWS IAM

It is estimated that over 80% of data breaches are due to weak or stolen passwords. In order to protect your AWS account and resources, it is important to configure a strong password policy for your users.

There are a few key factors to consider when creating a password policy:

1. Password length — The longer the password, the more difficult it is to crack. A minimum password length of 8 characters is recommended.

2. Password complexity — Use a mix of uppercase and lowercase letters, numbers, and special characters to make your password more difficult to guess.

3. Password rotation — Require your users to change their passwords every 60–90 days to help prevent password reuse and guessing.

4. Two-factor authentication — In addition to a password, require your users to enter a code from their mobile phone or other device to login. This adds an extra layer of security in case their password is compromised.

To configure a strong password policy for your users in AWS IAM:

1. Login to the AWS Management Console and navigate to the IAM section.

2. Click on the Policies tab and then click on the Create Policy button.

3. Select the Password Policy template and click on the Select button.

4. Enter the details of your password policy, such as minimum password length and complexity requirements.

5.Click on the Create Policy button to save your password policy.

6. Now that you have created your password policy, you need to attach it to one or more IAM users or groups. To do this, navigate to the Users or Groups tab and select the users or groups you want to attach the policy to.

7. Click on the Attach Policy button and select the policy you created from the list.

8. Click on the Attach Policy button to save your changes.

Your users will now be required to follow the strong password policy you have configured when they login to their AWS account.

How to Enable MFA in AWS

MFA, or Multi-Factor Authentication, adds an extra layer of security to your AWS account. When you enable MFA, you’ll need to enter a code from your MFA device in addition to your password when you sign in to your AWS account.

Enabling MFA can help protect your account from unauthorized access, even if your password is compromised. In this blog post, we’ll show you how to enable MFA for your AWS account.

First, you’ll need to sign in to the AWS Management Console. Once you’re signed in, click on your account name in the upper-right corner, and then click “My Security Credentials”.

Next, expand the “Multi-Factor Authentication (MFA)” section, and then click “Manage MFA”.

On the next page, you’ll need to select the IAM user that you want to enable MFA for. If you want to enable MFA for your root account, you’ll need to select the “root user” option.

Once you’ve selected the IAM user, click the “Enable MFA” button.

On the next page, you’ll need to select the type of MFA device that you want to use. AWS supports two types of MFA devices: hardware devices and virtual devices.

Hardware devices, such as the Amazon MFA device, generate a new code every 30 seconds. You’ll need to enter the code from the device when you sign in to your AWS account.

Virtual devices, such as the Google Authenticator app, generate a new code every 30 seconds. You’ll need to enter the code from the app when you sign in to your AWS account.

We recommend using a hardware device if possible, as it’s more secure than a virtual device. However, if you don’t have a hardware device, you can use a virtual device.

Once you’ve selected the type of MFA device, you’ll need to configure it. For a hardware device, you’ll need to enter the serial number and activation code from the device. For a virtual device, you’ll need to scan the QR code with the app.

After you’ve configured the MFA device, you’ll need to enter the code from the device to complete the process.

Once you’ve enabled MFA, you’ll need to use the code from your MFA device when you sign in to your AWS account. You’ll also need to use the code when you use the AWS CLI or API.

If you’re using the AWS Management Console, you’ll see the MFA prompt after you enter your password.

If you’re using the AWS CLI or API, you’ll need to specify the — serial-number and — token options when you authenticate.

If you have any questions about enabling MFA for your AWS account, please leave a comment below.

How to Use roles for applications that run on Amazon EC2 instances

If you are running applications on Amazon EC2 instances, you can use roles to give your applications access to AWS resources. Roles are a secure way to grant permissions to applications that need access to your resources. They can also be used to give applications access to resources in other AWS accounts.

To use roles for applications that run on Amazon EC2 instances, you first need to create a role. You can do this using the AWS Management Console, the AWS Command Line Interface (CLI), or the AWS SDKs.

Once you have created a role, you need to assign it to an Amazon EC2 instance. You can do this when you launch the instance, or you can attach the role to an existing instance.

When you assign a role to an Amazon EC2 instance, the instance is given an IAM role. The IAM role grants the instance permissions to make AWS API calls. The instance can then use these permissions to access AWS resources, such as Amazon S3 buckets or DynamoDB tables.

You can use roles to give your Amazon EC2 instances access to resources in other AWS accounts. To do this, you first need to create a cross-account IAM role. You can do this using the AWS Management Console or the AWS CLI.

Once you have created a cross-account IAM role, you need to assign it to an Amazon EC2 instance. You can do this when you launch the instance, or you can attach the role to an existing instance.

When you assign a cross-account IAM role to an Amazon EC2 instance, the instance is given permissions to assume the role. The instance can then use the role’s permissions to access resources in the other AWS account.

You can use roles to give your applications access to AWS resources. Roles are a secure way to grant permissions to applications that need access to your resources. They can also be used to give applications access to resources in other AWS accounts.

You can get a playbook on how to respond to incidents in AWS here.

For more, see this (somewhat dated!) video from AWS:

--

--