AWS Identity and Access Management (IAM): Users, Groups, Roles, and Policies
·CloudAWSCertificationsSecurityProfessional

AWS Identity and Access Management (IAM): Users, Groups, Roles, and Policies

Master the fundamental concepts of AWS Identity and Access Management (IAM). Learn about IAM users, groups, roles, and policies, and how they work together to securely control access to your AWS resources with the principle of least privilege.

Gatekeepers of the Cloud: Understanding AWS IAM Fundamentals

Welcome to Module 7: Identity and Access Management (IAM)! Having explored the Shared Responsibility Model, you now understand that "Security IN the Cloud" is a critical customer responsibility. At the heart of managing this security in AWS is AWS Identity and Access Management (IAM). This service is fundamental to securing your AWS account and resources, controlling who can do what, when, and where. It's not just a concept for technical professionals; understanding IAM is crucial for anyone engaging with AWS, making it a high-priority topic for the AWS Certified Cloud Practitioner exam.

This lesson will extensively cover the core components of IAM: users, groups, roles, and policies. We'll explain how these pieces fit together to provide granular access control, emphasizing the vital principle of least privilege. By the end of this lesson, you'll have a solid grasp of how to manage identities and access securely within your AWS environment.

1. What is AWS Identity and Access Management (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 who is authenticated (signed in) and authorized (has permissions) to use resources.

IAM is a global service. This means that IAM configurations (users, groups, roles) are applied across all AWS Regions, though they manage permissions for resources that might be specific to a Region.

Key Purpose of IAM:

  • Authentication: Verifying who an entity is (e.g., an IAM user providing a username and password).
  • Authorization: Determining what an authenticated entity is allowed to do (e.g., an IAM user can read data from an S3 bucket but not delete it).

2. Core IAM Components

IAM is built upon several key components that work in conjunction to define a complete access control strategy.

a. IAM Users

  • Definition: An IAM user represents a person or an application that interacts with AWS. It consists of a name and credentials (password for console, access keys for programmatic access).
  • Best Practice: Do NOT use the AWS account root user for daily tasks. Create individual IAM users for everyone who needs access to your AWS account.
  • Access Types: Users can be configured for AWS Management Console access (username and password) and/or programmatic access (access key ID and secret access key).

b. IAM Groups

  • Definition: An IAM group is a collection of IAM users. You can attach policies to a group, and all users in that group automatically inherit the permissions defined by those policies.
  • Purpose: Simplifies access management. Instead of attaching policies to individual users, you attach them to groups. For example, you could have an "Developers" group with permissions to interact with EC2 instances and an "Auditors" group with read-only access to logs.
  • Best Practice: Assign permissions to groups, not directly to users. A user can belong to multiple groups.

c. IAM Policies

  • Definition: IAM policies are JSON documents that define permissions. They specify what actions are allowed or denied on which AWS resources, and under what conditions.
  • Structure: A policy consists of statements, where each statement includes:
    • Effect: Allow or Deny (Deny always overrides Allow).
    • Action: The specific API actions that can be performed (e.g., s3:GetObject, ec2:RunInstances).
    • Resource: The AWS resources on which the action can be performed (e.g., arn:aws:s3:::my-bucket/*).
    • Principal: The user, role, or service that the policy applies to (this is implicitly the user/group/role the policy is attached to).
    • Condition: Optional conditions under which the policy is in effect (e.g., aws:SourceIp must be from a specific IP address range).
  • Types of Policies:
    • Managed Policies: Created and managed by AWS (e.g., AmazonS3ReadOnlyAccess).
    • Customer Managed Policies: Created and managed by you.
    • Inline Policies: Embedded directly into a user, group, or role.

d. IAM Roles

  • Definition: 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, a role is intended to be assumable by anyone who needs it, not uniquely associated with one person.
  • Purpose:
    • Granting temporary access: To AWS services (e.g., an EC2 instance needing to access S3).
    • Cross-account access: To allow a user in one AWS account to access resources in another.
    • Federated users: For users authenticated through an external identity provider (e.g., Okta, Active Directory).
  • Key Difference from Users: Roles do not have standard long-term credentials (password or access keys). Instead, temporary security credentials are created dynamically when a role is assumed.

Visualizing IAM Components and Their Relationships

graph TD
    RootAccount[AWS Root Account] --> A[IAM Users]
    RootAccount --> B[IAM Groups]
    RootAccount --> C[IAM Roles]

    A --> D1[User 1]
    A --> D2[User 2]

    B --> E1[Developers Group]
    B --> E2[Admins Group]

    C --> F1[EC2 Role]
    C --> F2[Lambda Role]

    D1 --> E1
    D2 --> E2

    E1 -- Attaches --> P1[Policy: EC2 Full Access]
    E2 -- Attaches --> P2[Policy: S3 Read Only]

    F1 -- Attaches --> P3[Policy: S3 Write Access]
    F2 -- Attaches --> P4[Policy: DynamoDB Access]
    
    P1 & P2 & P3 & P4 --> G[AWS Resources]

    style RootAccount fill:#FFD700,stroke:#333,stroke-width:2px,color:#000
    style A fill:#ADD8E6,stroke:#333,stroke-width:2px,color:#000
    style B fill:#ADD8E6,stroke:#333,stroke-width:2px,color:#000
    style C fill:#ADD8E6,stroke:#333,stroke-width:2px,color:#000
    style D1 fill:#90EE90,stroke:#333,stroke-width:2px,color:#000
    style D2 fill:#90EE90,stroke:#333,stroke-width:2px,color:#000
    style E1 fill:#FFB6C1,stroke:#333,stroke-width:2px,color:#000
    style E2 fill:#FFB6C1,stroke:#333,stroke-width:2px,color:#000
    style F1 fill:#FFB6C1,stroke:#333,stroke-width:2px,color:#000
    style F2 fill:#FFB6C1,stroke:#333,stroke-width:2px,color:#000
    style P1 fill:#ADD8E6,stroke:#333,stroke-width:2px,color:#000
    style P2 fill:#ADD8E6,stroke:#333,stroke-width:2px,color:#000
    style P3 fill:#ADD8E6,stroke:#333,stroke-width:2px,color:#000
    style P4 fill:#ADD8E6,stroke:#333,stroke-width:2px,color:#000
    style G fill:#DAF7A6,stroke:#333,stroke-width:2px,color:#000

This diagram illustrates how users belong to groups, and policies are attached to groups or directly to roles, defining permissions to AWS resources.

3. The Principle of Least Privilege

This is a core security best practice that you will encounter frequently: Grant only the minimum necessary permissions required for a user or service to perform its task.

  • Why it's important: Reduces the attack surface. If a user or service is compromised, the damage they can do is limited by their restricted permissions.
  • How to apply it: Start with no permissions and add only what is explicitly needed. Avoid using * (all actions) or * (all resources) in your policies unless absolutely necessary and well-justified.

4. Understanding the Root User Account

When you first create an AWS account, you create an AWS account root user. This user has complete access to all AWS services and resources in the account.

  • Best Practice: Do NOT use the root user for everyday tasks. Lock away the root user credentials and only use it for a very limited set of account and service management tasks (e.g., changing your AWS Support plan, closing your account). For all other tasks, create and use IAM users or roles.
  • Security Recommendation: Enable Multi-Factor Authentication (MFA) for your root user account.

5. Practical Example: Creating an IAM User with Read-Only S3 Access

Let's illustrate the creation of an IAM user, group, and policy with the principle of least privilege in mind. This example demonstrates how to set up a user who can only read from S3 buckets.

Step 1: Create an IAM Policy (JSON Document)

This JSON document specifies that the entity this policy is attached to can only perform s3:GetObject and s3:ListBucket actions on any S3 resource.

{
    "Version": "2012-10-17",
    "Statement": [
        {
            "Effect": "Allow",
            "Action": [
                "s3:GetObject",
                "s3:ListBucket"
            ],
            "Resource": "*"
        }
    ]
}

You would save this as a JSON file (e.g., s3-read-only-policy.json) and then create a managed policy in AWS.

Step 2: Create a Managed Policy using AWS CLI

aws iam create-policy \
    --policy-name S3ReadOnlyAccessCustom \
    --policy-document file://s3-read-only-policy.json \
    --description "Grants read-only access to S3 buckets"

This command creates a reusable policy named S3ReadOnlyAccessCustom.

Step 3: Create an IAM Group

aws iam create-group --group-name S3ReadersGroup

Step 4: Attach the Policy to the Group

aws iam attach-group-policy \
    --group-name S3ReadersGroup \
    --policy-arn arn:aws:iam::123456789012:policy/S3ReadOnlyAccessCustom
# Replace 123456789012 with your AWS Account ID

Now, any user added to S3ReadersGroup will automatically inherit read-only S3 permissions.

Step 5: Create an IAM User and Add to the Group

# Create user
aws iam create-user --user-name Alice

# Add user to group
aws iam add-user-to-group --group-name S3ReadersGroup --user-name Alice

Now, Alice is an IAM user who has read-only access to S3 resources because she is a member of S3ReadersGroup, which has the S3ReadOnlyAccessCustom policy attached. This adheres to the principle of least privilege.

Conclusion: IAM - Your First Line of Defense

AWS Identity and Access Management is an indispensable service for securing your AWS resources. By understanding and effectively utilizing IAM users, groups, roles, and policies, you can implement robust access control mechanisms, enforce the principle of least privilege, and protect your AWS environment from unauthorized access. This foundational knowledge is not just critical for the AWS Certified Cloud Practitioner exam, but also for any cloud professional looking to build and maintain secure applications on AWS.


Knowledge Check

?Knowledge Check

A developer needs to be able to read data from all Amazon S3 buckets in an AWS account but should NOT be able to modify or delete any data. Which IAM component is the most appropriate way to grant these permissions according to the principle of least privilege?

Subscribe to our newsletter

Get the latest posts delivered right to your inbox.

Subscribe on LinkedIn