How to Use AWS Identity and Access Management
Introduction
Welcome to our AWS journey! Today we'll dive into AWS Identity and Access Management (IAM) a critical service for managing access and permissions securely in AWS. Understanding IAM is essential for protecting your AWS resources and ensuring that the right individuals have appropriate access. This blog will cover the basics of IAM including setting up users and groups, creating roles and managing policies for secure access control. We'll also provide examples to illustrate these concepts in practice.
What is AWS IAM?
AWS Identity and Access Management (IAM) is a web service that helps you securely control access to AWS resources. With IAM you can manage users and their permissions to ensure that only authorized users can access specific resources. IAM allows you to create and manage AWS users and groups, use permissions to allow and deny their access to AWS resources and securely manage credentials such as access keys and passwords.
Key Components of IAM
Users :- Individuals or services that interact with AWS resources.
Groups :- Collections of users that share common permissions.
Roles :- Permissions assigned to AWS resources or services to perform actions on your behalf.
Policies :- Documents that define permissions and access controls.
Setting Up Users and Groups
Creating IAM Users
IAM users are entities that you create in AWS to represent individuals or services. Each user has unique credentials and permissions.
Step-by-Step Guide to Create an IAM User :-
Sign in to the AWS Management Console.
Navigate to the IAM Dashboard.
Click on "Users" in the left navigation pane.
Click the "Add user" button.
Enter the username for the new user.
Select the type of access :-
Programmatic access :- Allows the user to interact with AWS services using the AWS CLI, SDKs or APIs.
AWS Management Console access :- Allows the user to sign in to the AWS Management Console.
Click "Next : Permissions" to set permissions.
Assigning Permissions to IAM Users
Permissions determine what actions users can perform and what resources they can access. Permissions are granted using policies.
Step-by-Step Guide to Assign Permissions :-
Attach existing policies directly :- Choose from AWS managed policies or custom policies you have created.
- Example :- Attach the AmazonS3ReadOnlyAccess policy to allow read-only access to Amazon S3.
Add user to group :- Place the user in a group that has the necessary permissions.
- Example :- Create a group called S3ReadOnlyGroup and attach the AmazonS3ReadOnlyAccess policy to it. Add the user to this group.
Click "Next : Tags" to add optional metadata to the user.
Click "Next : Review" to review the user's details and permissions.
Click "Create user" to finalize the creation.
Example :- Creating a User with S3 Read-Only Access
Suppose you need to create a user JohnDoe
who should have read-only access to Amazon S3.
Create the user :-
Username :- Nikunj
Access type :- Programmatic access and AWS Management Console access.
Attach the policy :-
- Use the AmazonS3ReadOnlyAccess AWS managed policy.
Review and create the user.
Creating IAM Groups
IAM groups are collections of users that share common permissions. Instead of managing permissions for each user individually you can assign permissions to a group and add users to that group.
Step-by-Step Guide to Create an IAM Group :-
Navigate to the IAM Dashboard.
Click on "Groups" in the left navigation pane.
Click the "Create New Group" button.
Enter a name for the group (e.g. Developers ).
Attach policies to the group :-
- Example :- Attach the AmazonEC2FullAccess policy to allow full access to Amazon EC2.
Click "Create group" to finalize.
Example :- Creating a Group with EC2 Full Access
Suppose you need to create a group Developers with full access to Amazon EC2.
Create the group :-
- Group name :- Developers
Attach the policy :-
- Use the AmazonEC2FullAccess AWS managed policy.
Add users to the group :-
- Add existing users such as Nikunj to the Developers group to grant them EC2 full access.
Creating IAM Roles
IAM roles are similar to users in that they have permissions but they are intended to be assumed by anyone who needs them including AWS services. Roles are essential for granting AWS services permissions to interact with other AWS services.
Creating a Role for AWS Services
Step-by-Step Guide to Create an IAM Role :-
Navigate to the IAM Dashboard.
Click on "Roles" in the left navigation pane.
Click the "Create role" button.
Select the type of trusted entity :-
- AWS service :- Allows AWS services (e.g. EC2, Lambda) to assume this role.
Choose the service that will use this role :-
- Example :- Select EC2 to create a role that EC2 instances can assume.
Attach policies to the role :-
- Example :- Attach the AmazonS3FullAccess policy to allow full access to Amazon S3.
Add tags (optional) to add metadata to the role.
Review and create the role.
Example :- Creating a Role for EC2 to Access S3
Suppose you need to create a role that allows EC2 instances to access S3 with full permissions.
Create the role :-
Trusted entity :- AWS service
Service :- EC2
Attach the policy :-
- Use the AmazonS3FullAccess AWS managed policy.
Review and create the role.
Assigning the Role to an EC2 Instance
Launch or select an existing EC2 instance.
In the instance settings choose "Actions" > "Instance Settings" > "Attach/Replace IAM Role".
Select the role you created (e.g. EC2S3AccessRole ).
Attach the role.
Managing IAM Policies
IAM policies are JSON documents that define permissions. They specify who can do what to which resources under what conditions.
Types of IAM Policies
AWS Managed Policies :- Predefined policies managed by AWS.
Customer Managed Policies :- Policies created and managed by you.
Inline Policies :- Policies embedded directly in a user, group or role.
Writing a Customer Managed Policy
Example :- Creating a Policy for Read-Only S3 Access
{
"Version": "2012-07-30",
"Statement": [
{
"Effect": "Allow",
"Action": [
"s3:GetObject",
"s3:ListBucket"
],
"Resource": [
"arn:aws:s3:::nikks-bucket",
"arn:aws:s3:::nikks-bucket/*"
]
}
]
}
Step-by-Step Guide to Create a Customer Managed Policy :-
Navigate to the IAM Dashboard.
Click on "Policies" in the left navigation pane.
Click the "Create policy" button.
Select the JSON tab and enter the policy JSON :-
- Example policy for read-only S3 access (as shown above).
Click "Review policy".
Name and describe the policy :-
Name :- S3ReadOnlyPolicy
Description :- Read-only access to a specific S3 bucket.
Click "Create policy".
Attaching Policies to Users, Groups and Roles
Step-by-Step Guide to Attach a Policy :-
Navigate to the IAM Dashboard.
Select the user, group or role to which you want to attach the policy.
Click on "Add permissions".
Choose "Attach policies directly".
Select the policy you created (e.g. S3ReadOnlyPolicy ).
Click "Next : Review" and then "Add permissions".
Best Practices for IAM
Follow the Principle of Least Privilege :- Grant only the permissions needed to perform a task.
Use Groups to Assign Permissions :- Manage permissions for multiple users easily by assigning them to groups.
Enable Multi-Factor Authentication (MFA) :- Add an extra layer of security for users.
Rotate Credentials Regularly :- Regularly rotate access keys and passwords to reduce the risk of compromised credentials.
Monitor IAM Activity :- Use AWS CloudTrail to monitor and log IAM activities.
Use Roles for Applications and Services :- Instead of using long-term credentials, use IAM roles to grant permissions to applications and services.
Real-World Examples and Case Studies
Example 1 :- Secure Access Control for a Development Team
A development team at a company uses AWS for hosting and development. The team needs different levels of access based on roles.
Setup :-
Create Groups :-
Admins with full access to all AWS services.
Developers with full access to EC2 and limited access to S3.
Testers with read-only access to S3.
Create Users :- Create individual users for each team member and add them to the appropriate group.
Create Policies :- Define and attach policies to groups to control access.
Outcome :- The team can securely access AWS resources based on their roles minimizing the risk of unauthorized access.
Example 2 :- Using Roles for Cross-Account Access
A company has multiple AWS accounts for different departments. They need to allow the billing team in one account to access S3 buckets in another account.
Setup :-
Create a Role in the Target Account :-
- Define a role with S3 access and specify the source account as a trusted entity.
Create a Policy in the Source Account :-
- Define a policy that allows assuming the role in the target account.
Attach the Policy :-
- Attach the policy to the users or groups in the source account that need access.
Outcome :- The billing team can securely access S3 buckets in the target account using cross-account roles.
Conclusion
AWS Identity and Access Management (IAM) is a powerful tool for managing access to AWS resources securely. By understanding and implementing IAM's features you can ensure that only authorized individuals have the necessary access to perform their tasks. In this blog post we've covered the basics of IAM, including setting up users and groups, creating roles and managing policies. We've also provided real-world examples to illustrate these concepts.
Stay tuned for more insights and best practices in our upcoming blog posts.
Connect and Follow:
Like👍 | Share📲 | Comment💭
Subscribe to my newsletter
Read articles from Nikunj Vaishnav directly inside your inbox. Subscribe to the newsletter, and don't miss out.
Written by
Nikunj Vaishnav
Nikunj Vaishnav
👋 Hi there! I'm Nikunj Vaishnav, a passionate QA engineer Cloud, and DevOps. I thrive on exploring new technologies and sharing my journey through code. From designing cloud infrastructures to ensuring software quality, I'm deeply involved in CI/CD pipelines, automated testing, and containerization with Docker. I'm always eager to grow in the ever-evolving fields of Software Testing, Cloud and DevOps. My goal is to simplify complex concepts, offer practical tips on automation and testing, and inspire others in the tech community. Let's connect, learn, and build high-quality software together! 📝 Check out my blog for tutorials and insights on cloud infrastructure, QA best practices, and DevOps. Feel free to reach out – I’m always open to discussions, collaborations, and feedback!