AWS IAM Basics

Learn the basic building blocks of AWS Identity and Access Management (IAM) and how permissions are granted.

What Is AWS IAM?

AWS Identity and Access Management (IAM) controls who can access AWS resources and what actions they can perform. IAM is a global AWS service.

IAM permissions apply to AWS API requests. Network controls such as security groups and network ACLs control traffic separately.

IAM Principals

An IAM principal is an identity that can make a request to AWS.

  • IAM users represent individual people or applications that need long-term credentials.
  • IAM groups collect users that need the same permissions. Groups cannot be used as a principal in a resource-based policy.
  • IAM roles provide temporary permissions to trusted users, applications, or AWS services.
  • Federated users obtain temporary AWS access through an external identity provider.
  • The AWS account root user owns the account and has unrestricted access. It should be used only for account-level tasks.

For applications running on AWS, an IAM role is usually preferred over storing access keys in application code.

IAM Policies

An IAM policy is a JSON document that describes permissions. A policy can allow or deny actions on AWS resources.

The basic parts of an identity-based policy are:

  • Effect: Allow or Deny
  • Action: the AWS operations that the policy allows or denies
  • Resource: the AWS resources to which the action applies
  • Condition: optional rules that restrict when the policy applies

Example:

1
2
3
4
5
6
7
8
9
10
11
12
13
{
"Version": "2012-10-17",
"Statement": [
{
"Effect": "Allow",
"Action": [
"s3:GetObject",
"s3:PutObject"
],
"Resource": "arn:aws:s3:::example-bucket/*"
}
]
}

This policy allows reading and writing objects only in example-bucket.

Managed and Inline Policies

AWS managed policies are maintained by AWS or created in an AWS account and can be attached to multiple identities. Customer managed policies are reusable policies that can be updated and versioned.

Inline policies are embedded directly in one user, group, or role. Use a managed policy when the permissions may be reused.

Users, Groups, and Roles

Attach permissions to a group rather than repeating the same policy on many users. A user can be a member of multiple groups.

Use a role when the identity does not need permanent credentials. Examples include an EC2 instance reading objects from S3, a Lambda function calling DynamoDB, or a developer assuming a role with higher privileges.

A role has a permissions policy and a trust policy. The permissions policy defines what the role can do. The trust policy defines who can assume the role.

1
2
3
4
5
6
7
8
9
10
11
12
{
"Version": "2012-10-17",
"Statement": [
{
"Effect": "Allow",
"Principal": {
"Service": "lambda.amazonaws.com"
},
"Action": "sts:AssumeRole"
}
]
}

This trust policy allows AWS Lambda to assume the role.

How IAM Decisions Work

By default, an IAM request is denied. Access is granted only when there is an applicable allow and no applicable explicit deny.

Key rules:

  • An explicit deny overrides an allow.
  • Identity-based and resource-based policies can both grant access.
  • Permissions boundaries and other policy types can further restrict permissions.

IAM permissions do not automatically grant access to every AWS resource. The principal needs permission, and the request must pass applicable conditions and resource policies.

Basic Security Best Practices

  • Do not use the root account for everyday work.
  • Enable multi-factor authentication (MFA), especially for privileged identities.
  • Follow least privilege: grant only the actions and resources required.
  • Use roles and temporary credentials for AWS workloads.
  • Prefer AWS managed or customer managed policies over duplicate inline policies.
  • Rotate access keys if they are used and remove keys that are no longer needed.
  • Review unused users, roles, permissions, and access keys.

IAM Access Analyzer

IAM Access Analyzer helps identify resources that can be accessed from outside an account or organizational boundary. It can review policies and report unintended public or cross-account access.

Access Analyzer is useful when auditing resource-based policies for S3 buckets, IAM roles, KMS keys, and other supported resources.

Summary

IAM controls AWS authorization. Start with least-privilege policies, use groups to manage user permissions, and use roles with temporary credentials for people and workloads. Protect the root account and enable MFA to reduce account risk.

Reference