Implementing Least Privilege: Best Practices for AWS IAM Policies

Emre ÖZDEM
5 min readJul 9, 2024

--

AWS IAM (Identity and Access Management) Policies are crucial for securely and efficiently managing access to resources in your AWS environment. In this article, we will explore how IAM Policies work and examine best practices, including the principle of least privilege.

How AWS IAM Policies Work

AWS IAM Policies are JSON documents that define who (principal) can perform what actions (actions) on which resources and under what conditions (conditions). Policies are classified into two main categories:

  1. Identity-Based Policies: These policies are attached to IAM identities such as users, groups, and roles. They define the permissions and restrictions for these identities when accessing AWS resources.
  2. Resource-Based Policies: These policies are attached to specific AWS resources. They define who can use these resources and how. For example, S3 bucket policies fall into this category.

Best Practices

1. Principle of Least Privilege

Always grant your users and applications only the permissions they need. This minimizes security risks. For instance, if a developer only needs read access, do not grant write access.

Consider a scenario where you have an S3 bucket called example-bucket, and you want to grant a user permissions to upload and list objects in this bucket but not delete them. You can create the following policy and assign it to the desired user or user groups.

{
"Version": "2012-10-17",
"Statement": [
{
"Effect": "Allow",
"Action": [
"s3:PutObject",
"s3:ListBucket"
],
"Resource": [
"arn:aws:s3:::example-bucket",
"arn:aws:s3:::example-bucket/*"
]
}
]
}

In this policy:

  • The Effect field is set to Allow, granting the specified permissions.
  • The Action field includes s3:PutObject and s3:ListBucket, allowing the user to upload and list objects.
  • The Resource field specifies the example-bucket and all objects within it (example-bucket/*).

By limiting permissions to only PutObject and ListBucket, you prevent the user from performing unwanted actions such as deleting objects (s3:DeleteObject). This adheres to the principle of least privilege by granting only the necessary permissions for the user’s role.

There are also hundreds of Amazon managed policies available for similar authorizations.

2. Role-Based Access Control (RBAC)

Assign users with similar permissions to groups and roles. This makes permission management easier and more secure.

IAM groups allow you to group users with similar permissions. This way, you can assign permissions at the group level instead of managing individual permissions, simplifying the management process.

Example Scenario: Developer and Data Analyst Groups

Suppose you have two types of user groups in your AWS environment: developers and data analysts. Developers need read/write access to S3 buckets, while data analysts only need read access.

1. Developer Group:

  • Users in this group should have extended permissions required for development processes. For example, they can upload and list objects in S3 buckets.
{
"Version": "2012-10-17",
"Statement": [
{
"Effect": "Allow",
"Action": [
"s3:PutObject",
"s3:ListBucket",
"s3:GetObject"
],
"Resource": [
"arn:aws:s3:::example-bucket",
"arn:aws:s3:::example-bucket/*"
]
}
]
}
  • Attach this policy to an IAM group named Developers. Thus, every user added to this group will have permissions to upload, list, and read objects in the S3 bucket.

2. Data Analyst Group:

  • Users in this group only need read access for data analysis. Therefore, you can apply a more restricted policy.
{
"Version": "2012-10-17",
"Statement": [
{
"Effect": "Allow",
"Action": "s3:GetObject",
"Resource": [
"arn:aws:s3:::example-bucket",
"arn:aws:s3:::example-bucket/*"
]
}
]
}
  • Attach this policy to an IAM group named DataAnalysts. Thus, every user added to this group will have permissions to read objects in the S3 bucket, but not upload or delete them.

Advantages of IAM Groups

  • Easy Management: Managing permissions at the group level is simpler than managing individual user permissions. New users can be added to the group to automatically receive the necessary permissions.
  • Consistency: Groups ensure that users with the same role have consistent permissions, aiding in the consistent application of security policies.
  • Flexibility: You can quickly change permissions by adding or removing users from different groups.

3. Avoid Using Wildcards in Policies

Using wildcards (*) in IAM policies can grant more permissions than intended, leading to potential security risks. Wildcards may unintentionally allow access to more resources or actions than necessary, undermining the principle of least privilege.

Instead of using wildcards, specify the exact resources and actions needed. For example, rather than "Resource": "arn:aws:s3:::example-bucket/*", list each required resource individually:

{
"Resource": [
"arn:aws:s3:::example-bucket/object1",
"arn:aws:s3:::example-bucket/object2"
]
}

This approach ensures that users have only the necessary permissions for their roles, minimizing security vulnerabilities.

4. Regular Permission Audits

Regularly review your IAM policies and roles to remove unnecessary permissions. Tools like AWS IAM Access Analyzer can help audit your permissions.

5. Multi-Factor Authentication (MFA)

Enable MFA for users, especially those with access to critical resources. MFA adds an additional layer of security against unauthorized access.

6. Limit Root Account Access

Use the AWS root account only for critical tasks. For daily operations, use IAM users and roles. Don’t forget to enable MFA for root account access.

7. Use Temporary Credentials

Encourage IAM users to use temporary credentials instead of long-term access keys. AWS STS (Security Token Service) can help with this.

8. Monitoring and Auditing

Use tools like CloudTrail to monitor AWS account activities. Regularly review IAM policy changes and access attempts.

Conclusion

AWS IAM Policies are a powerful tool for securing your AWS environment. By following best practices and regularly auditing permissions, you can enhance security and prevent unauthorized access. By using the principles and tools discussed in this article, you can manage your AWS resources securely and effectively.

--

--