AWS Security: The Basics of IAM Policies

Mohasina Clt
8 min readFeb 10, 2024

--

Table of Contents:

  1. Introduction
  2. Understanding IAM Policies
  3. Policy Stimulation
  4. IAM Policy Structure and Components
  5. Types of IAM Policies
  6. Crafting IAM Policies: Practical Examples
  7. Conclusion

Introduction:

As businesses increasingly migrate their operations to the cloud, ensuring robust security measures within cloud environments has become paramount. Among cloud service providers, Amazon Web Services (AWS) stands out as a leading platform, offering a vast array of services to support diverse business needs. However, with this flexibility comes the responsibility to safeguard sensitive data and resources from unauthorized access and cyber threats.

Enter IAM (Identity and Access Management) policies — the linchpin of AWS security. IAM policies serve as the bedrock of access control within AWS, dictating who can access what resources and under what conditions. They are the guardians of your digital kingdom, providing granular control over user permissions and enforcing the principle of least privilege.

In this blog post, we’ll delve deep into the realm of IAM policies, unraveling their significance, structure, and practical applications. From understanding the fundamental components of IAM policies to crafting tailored policies for specific use cases, readers can expect to gain a comprehensive understanding of IAM policies and their role in fortifying AWS security. So, join us on this journey as we navigate the intricate landscape of AWS security and master IAM policies to safeguard your cloud infrastructure.

⇒ Understanding IAM Policies:

IAM (Identity and Access Management) policies are like rulebooks for controlling who can do what in your AWS (Amazon Web Services) environment. They’re essential for keeping your cloud secure.

IAM policies have three main parts: the Policy Name (like a title), the Description (optional but helpful for explaining what the policy does), and the Statements (the actual rules that determine permissions).

It’s crucial to think about specific situations, or use cases, when creating IAM policies. By understanding what different users or groups need to do in AWS, you can make sure they have the right permissions without giving them too much access.

⇒ Policy Stimulation:

Policy stimulation is essential for security training, especially in complex environments like cloud computing. It allows learners to immerse themselves in realistic scenarios, experiment with various policy configurations, and troubleshoot potential issues in a risk-free setting. This hands-on approach fosters a deeper understanding of access control principles and promotes collaboration among team members. Ultimately, policy stimulation empowers individuals to design effective security strategies and safeguard sensitive data within their organizations.

IAM Policy Structure and Components:

IAM (Identity and Access Management) policies serve as the backbone of access control in AWS (Amazon Web Services), providing a structured framework for defining permissions. Let’s break down the components of an IAM policy and understand how they work together.

  1. Policy Name: A Policy Name serves as a unique identifier for the policy, allowing easy identification and management within your AWS environment.
  2. Description (Optional): The Description provides a brief explanation of the policy’s purpose or function, aiding in understanding and management. While optional, it can enhance clarity and documentation.
  3. Statements: Statements form the core elements of an IAM policy, defining permissions for specific actions on AWS resources. Each statement includes:
  • Effect: Specifies whether permissions are granted (“Allow”) or denied (“Deny”).
  • Action: Describes the specific AWS service actions (tasks) permitted or denied by the policy.
  • Resource: Identifies the AWS resources (e.g., S3 buckets, EC2 instances) on which the actions are allowed or denied.
  • Condition (Optional): Specifies additional criteria under which the policy statement is enforced, providing flexibility in access control.

Policy Example: Below is a simplified IAM policy example granting read-only access to a specific S3 bucket:

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

In this example:

  • The policy allows the s3:GetObject action, granting permission to read objects within the specified S3 bucket.
  • The Resource field specifies the ARN (Amazon Resource Name) of the S3 bucket, indicating that the permission applies to all objects within that bucket.

This policy allows users or roles to read objects from the specified S3 bucket. Further customization is possible to meet specific security needs and use cases.

⇒ Types of IAM Policies:

Identity-based and resource-based policies serve distinct roles in controlling access within AWS.

Identity-based policies are attached to IAM users, groups, or roles, specifying what actions each identity can perform. For example, a policy might grant a user permission to launch EC2 instances or read from an S3 bucket.

Resource-based policies, on the other hand, are attached directly to AWS resources such as S3 buckets or SNS topics. These policies determine which identities can access the resource and what actions they can take. For instance, a policy attached to an S3 bucket might specify which IAM users or roles are allowed to access the bucket and what actions they can perform.

Both types of policies work together to form a comprehensive access control framework. Identity-based policies control what actions an identity can perform, while resource-based policies control who can access a specific AWS resource and what actions they are allowed to take on it. By combining these policies, organizations can enforce granular access control across their AWS environment.

⇒ Crafting IAM Policies: Practical Examples

  1. Access the AWS Management Console:

2. Navigate to IAM:

  • In the AWS Management Console, go to the “Services” menu and select “IAM” under the “Security, Identity, & Compliance” section.

3. Access the Policy Generator:

  • In the IAM console, select “Policies” from the left-hand navigation pane.
  • Click on the “Create policy” button.
  • Choose between “Visual” or “JSON” tab from the policy editor.

Use Case 1: EC2 Snapshot Management

⇨ Define Permissions:

  • Select the service (e.g., EC2) and actions needed for EC2 snapshot management.

⇨ Add actions:

  • Specify actions like Modify Snapshot Attribute, Reset Snapshot Attribute, etc.
  • Here’s an example of an allowing All-permissions management actions in EC2:

⇨ Select Resources:

  • Choose whether the policy applies to all resources or specific resources.
  • If selecting specific resources, specify the ARN (Amazon Resource Name) of the snapshots.
  • You can select any resources from this, now Iam choosing all actions in snapshot.
  • To specify snapshot resource ARNs for the CopySnapshot and other actions, you can create an AWS Identity and Access Management (IAM) policy in Visual format.
  • Then Click “NEXT”

⇨ Review and Create:

  • After configuring the policy, review the summary.
  • Click on the “Add” button to generate the policy.
  • Permissions defined in this policy:

Permissions defined in this policy document specify which actions are allowed or denied. To define permissions for an IAM identity (user, user group, or role), attach a policy to it.

If you want to change the permissions, go to right side of tab and click the “Edit.”

then you can edit the permissions defined in this policy.

  • Then click on the “Create policy” icon.
  • Now we successfully created the policy. If you want to view the policy, click on the “View policy.”

⇨ Policy details:

1. Type: policy type

2. Edited time: When the policy edited

3. Creation time: When the policy created

4. ARN: Policy ARN

Permissions defined in this policy in JSON format:

{
"Version": "2012-10-17",
"Statement": [
{
"Sid": "VisualEditor0",
"Effect": "Allow",
"Action": [
"ec2:ModifyVpcEndpointServicePermissions",
"ec2:DeleteNetworkInterfacePermission",
"ec2:ModifySnapshotAttribute",
"ec2:CreateNetworkInterfacePermission",
"ec2:ResetSnapshotAttribute"
],
"Resource": "arn:aws:ec2:*::snapshot/*"
}
]
}

⇨ Apply the Policy:

  • Once generated, you can attach the policy to IAM users, groups, or roles based on your use case.

Use Case 2: S3 Bucket Access Control

Using JSON:

  • If you are using JSON, you need to write the policy.

⇨ Define Permissions:

  • Select the service (e.g., S3) and actions needed for bucket access control.
  • Specify actions like Put Object, Delete Bucket Policy, etc.

⇨ Select Resources:

  • Choose whether the policy applies to all S3 buckets or specific buckets.
  • If selecting specific buckets, specify the bucket ARN.

1. Resource type: object/bucket

2. Resource ARN:

Bucket Name: your Bucket Name

Object Name: your Object Name

⇨ Review and Create:

  • After configuring the policy, review the summary.

If you want to change the permissions, go to right side of tab and click the “Edit.”

  • Click on the “Add” button to generate the policy.

⇨ Policy details:

In ARN

arn:aws:iam::”Account ID”:policy/”Policy Name”

1. The Account ID (who create the policy)

2. The Policy Name (Given by you)

The JSON Policy:

{
"Version": "2012-10-17",
"Statement": [
{
"Sid": "Statement1",
"Effect": "Allow",
"Action": [
"s3:PutObject",
"s3:DeleteBucketPolicy",
"s3:PutBucketTagging"
],
"Resource": [
"*"
]
}
]
}

By following these step-by-step instructions for each use case, you can craft IAM policies tailored to your specific needs for EC2 snapshot management and S3 bucket access control.

⇒ Conclusion:

In wrapping up, IAM policies serve as the backbone of security within AWS, offering precise control over resource access and bolstering defenses against cyber threats. Through this exploration, we’ve gained insights into their structure, significance, and practical implementation. As businesses navigate the cloud landscape, mastering IAM policies is paramount for safeguarding data and infrastructure.

For further discussions on cloud security and IAM best practices, feel free to connect with me on LinkedIn. Let’s continue fortifying our cloud environments together.

--

--

Mohasina Clt

🌟 🎓📊➡️💻 Freelance cloud consultant, educator @ Insight for Innovation, & Medium writer. Let's empower, inspire, & innovate! ✨🚀📝