🔒 Understanding AWS IAM Policies: A Comprehensive Guide 🔒

Mohasina Clt
14 min readMar 11, 2024

--

📚 Table of Contents:

  1. Introduction
  2. Understanding IAM Policies
  3. Types of IAM Policies
  4. Conclusion

🚀 Introduction:

IAM policies play a pivotal role in the security infrastructure of AWS, serving as the gatekeepers to the vast array of cloud resources. By delineating who can access what and under what conditions, IAM policies form the bedrock of security and compliance within AWS environments. Effectively managing these permissions is paramount, not only for safeguarding sensitive data but also for ensuring regulatory adherence. In this guide, we’ll delve into the intricacies of IAM policies, exploring how they enable organizations to fortify their AWS deployments against unauthorized access and maintain robust compliance standards.

💡 Understanding IAM Policies:

IAM policies are rules that define permissions for accessing AWS resources. They specify who has access to which resources and what actions they can perform.

IAM policies are critical for maintaining security by controlling access to AWS resources. They ensure compliance with regulatory requirements by enforcing access controls. Additionally, IAM policies facilitate efficient resource management by allowing organizations to grant appropriate permissions to users, groups, and roles.

🔐 Types of IAM Policies:

1️⃣ Identity-based policies

Identity-based policies in AWS Identity and Access Management (IAM) are policies that you attach to IAM identities, such as users, groups, or roles. These policies define the permissions that are granted to the associated identity. In other words, Identity-based policies are JSON permissions policy documents that control what actions an identity (users, groups of users, and roles) can perform, on which resources, and under what conditions.

There are two main types of identity-based policies: managed policies and inline policies.

⇒ a) Managed policies:

Managed policies are standalone policies that you can attach to multiple IAM identities or users, groups, and roles in your AWS account. They are created and managed independently from IAM users, groups, or roles. Managed policies are a powerful tool in IAM, providing a convenient way to assign permissions to IAM entities. They contribute to the principle of least privilege by allowing you to grant only the necessary permissions for specific tasks.

Managed policies come in two types:

1. AWS managed policies:

6

These are predefined policies created and managed by AWS. Examples include the AWS managed policies for read-only access, administrator access, and more. You can attach these policies to your IAM identities.

AWS managed policies make it convenient for you to assign appropriate permissions to users, groups, and roles. It is faster than writing the policies yourself and includes permissions for many common use cases. You cannot change the permissions defined in AWS managed policies. And These policies are updated as new services and features are introduced. Some examples of AWS Managed Policies include:

  • Administrator Access: Provides full access to AWS services and resources. This policy is intended for administrators who need complete control over all resources.
  • Read Only Access: Grants read-only access to all AWS services and resources. Users with this policy can view configurations and details but cannot make changes.
  • AmazonS3FullAccess: Grants full access to Amazon S3, allowing users to perform any action on S3 buckets and objects.

These managed policies are designed to make it easy to assign common permissions without manually specifying each individual permission. You can attach these policies directly to IAM users, groups, or roles.

2.Customer managed policies

Managed policies that you create and manage in your AWS account. Customer managed policies provide more precise control over your policies than AWS managed policies or in other words They provide more flexibility and control over the permissions you want to grant. You can create and attach customer managed policies to IAM identities.

You can create standalone policies in your own AWS account that you can attach to principal entities (users, groups, and roles). You create these customer managed policies for your specific use cases, and you can change and update them as often as you like. Like AWS managed policies, when you attach a policy to a principal entity, you give the entity the permissions that are defined in the policy. When you update permissions in the policy, the changes are applied to all principal entities that the policy is attached to.

Example of a Customer Managed Policy:

{
"Version": "2012–10–17",
"Statement": [
{
"Effect": "Allow",
"Action": "s3:ListBucket",
"Resource": "arn:aws:s3:::test-bucket"
},
{
"Effect": "Deny",
"Action": "s3:*",
"Resource": "arn:aws:s3:::test-bucket/sensitive-data/*"
}
]
}

In this example:

  • Allows listing the contents of the “test-bucket” in Amazon S3.
  • Denies any S3 action on objects within the “sensitive-data” prefix of the “test-bucket.”

⇒ b) Inline policies:

Inline policies are policies that you embed directly into a single IAM identity. Unlike managed policies, inline policies are part of the IAM identity to which they are attached. Inline policies maintain a strict one-to-one relationship between a policy and an identity. When you delete the IAM identity, the inline policy is also deleted. Inline policies provide a way to customize permissions for a specific IAM identity without the need for separate policy management.

Inline policies are created and managed directly within the IAM user, group, or role to which they are attached. When you create an inline policy, it is associated with that specific IAM entity. Inline policies are included as part of the IAM entity’s configuration. You’ll find them in the AWS Management Console, AWS Command Line Interface (CLI), or AWS SDKs when viewing the details of the IAM entity. Inline policies provide flexibility in defining and customizing permissions for a specific IAM entity. You can tailor the permissions precisely to the needs of that entity without affecting others.

Consider an example of an inline policy in JSON format:

{
"Version": "2012–10–17",
"Statement": [
{
"Effect": "Allow",
"Action": [
"s3:GetObject",
"s3:ListBucket"
],
"Resource": [
"arn:aws:s3:::test-bucket/*",
"arn:aws:s3:::test-bucket"
]
},
{
"Effect": "Deny",
"Action": "s3:DeleteObject",
"Resource": "arn:aws:s3:::test-bucket/sensitive-data.txt"
}
]
}

In this example:

  • Allows the IAM entity to get objects and list the contents of the “test-bucket” in Amazon S3.
  • Denies the IAM entity the ability to delete the “sensitive-data.txt” object within the “test-bucket.”

⇨ Choosing between managed policies and inline policies

When making the decision between managed policies and inline policies in AWS IAM, it’s essential to weigh the specific needs of your use case against the features each option offers. Managed policies, whether AWS Managed Policies or customer managed, provide predefined sets of permissions and centralized management, making them efficient choices for broad permission assignment and updates. They adhere to best practices, support versioning, and ensure continuity even after deletion. On the other hand, inline policies offer fine-grained customization and are specific to individual IAM entities, making them ideal for entity-specific requirements or temporary permissions. However, managing inline policies requires careful consideration to avoid complexity and ensure alignment with security best practices. Overall, while managed policies are recommended for their convenience and adherence to best practices, inline policies offer flexibility for specific use cases that require tailored permissions.

2️⃣ Resource-based policies

Resource-based policies in AWS are a type of access policy that is associated with an AWS resource. These policies define who has access to the resource and what actions they can perform on it. Unlike identity-based policies, which are attached to IAM users, groups, or roles, resource-based policies are attached directly to the AWS resource itself.

Here are key aspects of resource-based policies:

  1. Resource Ownership:
  • Resource-based policies are typically associated with AWS resources like Amazon S3 buckets, Lambda functions, SNS topics, and others.
  • They allow resource owners to control access to their resources and specify who (accounts, users, or entities) can interact with the resource.

2. JSON Policy Documents:

  • Resource-based policies are written in JSON format, similar to identity-based policies.
  • These policy documents specify the permissions for the resource, including the allowed actions and the entities (principals) that are granted or denied access.

3. Cross-Account Access:

Resource-based policies often facilitate cross-account access, allowing resources to be shared across AWS accounts.

  • For example, an S3 bucket owner can grant permissions to another AWS account to read or write objects in that bucket.

4. Fine-Grained Control:

  • Resource-based policies provide fine-grained control over who can access the resource and what operations they can perform.
  • They are commonly used to control access to shared resources in a multi-account environment.

5. Supported AWS Services:

  • Various AWS services support resource-based policies, including S3, Lambda, SNS, SQS, KMS, and more.
  • Each service’s resource-based policy may have specific elements tailored to the nature of the service.

Here’s a simplified example of an S3 bucket resource-based policy:

{
"Version": "2012–10–17",
"Statement": [
{
"Effect": "Allow",
"Principal": {
"AWS": "arn:aws:iam::account-ID-without-hyphens:root"
},
"Action": "s3:GetObject",
"Resource": "arn:aws:s3:::test-bucket/*"
},
{
"Effect": "Allow",
"Principal": {
"AWS": "arn:aws:iam::another-account-ID:root"
},
"Action": "s3:PutObject",
"Resource": "arn:aws:s3:::test-bucket/uploaded-files/*"
}
]
}

In this example:

  • The first statement allows the root user of the account with account-ID-without-hyphens to retrieve objects from the "test-bucket."
  • The second statement allows the root user of another AWS account (another-account-ID) to upload objects to the "uploaded-files" directory within the same bucket.

Resource-based policies play a crucial role in managing access to AWS resources, especially in scenarios where sharing resources across accounts or defining access at the resource level is required. They provide a flexible and granular way to control access to resources within the AWS environment.

3️⃣ Permissions boundaries

Permissions boundaries in AWS IAM serve as a crucial tool for enforcing granular control over the permissions of IAM entities, including users, groups, and roles. Here are key characteristics and benefits of permissions boundaries:

  1. Maximum Permissions Control:

Permission boundaries in AWS IAM set the maximum permissions for IAM entities by attaching an IAM policy. This prevents entities from gaining excessive permissions, improving security and compliance.

2. Limiting Access to Resources:

Permission boundaries are crucial for restricting access to specific AWS resources or services, enforcing security policies, and thwarting unauthorized access to sensitive resources.

3. Hierarchy in IAM Entities:

Permission boundaries are integrated within hierarchical IAM entity structures, enabling precise permission control. For example, a user may have a permission boundary set, constraining their permissions despite belonging to groups with wider access. This hierarchical method ensures efficient management and enforcement of permissions across various levels of IAM entities.

4. Granular Control:

Permission boundaries offer granular control over the actions that an IAM entity can execute on specific resources. By following the principle of least privilege, organizations can establish precise permissions across different levels of the IAM hierarchy, thus reducing the potential for unauthorized access.

Note:

Permission boundaries leverage managed policies to establish the maximum permissions allocated to an IAM entity. An entity’s permissions boundary confines its actions to the intersection of permissions permitted by both its identity-based policies and permission boundaries. This alignment ensures that entities operate within defined boundaries, adhering to security best practices and organizational policies.

4️⃣ Organization Policies (Service Control Policies)

Organization policies, also known as Service Control Policies (SCPs), are an essential feature of AWS Organizations. They serve as a mechanism for governing permissions and access controls across the entire AWS Organization. SCPs enable administrators to establish rules that restrict or allow access to specific AWS services or actions, helping to enforce compliance, security, and governance standards.

Features:

  1. Centralized Governance: SCPs provide a centralized approach to managing permissions across all member accounts within an AWS Organization.
  2. Access Control: Administrators can use SCPs to define granular permissions, restricting access to certain AWS services or actions based on organizational policies.
  3. Hierarchical Structure: SCPs can be applied at different levels within the organization’s hierarchy, allowing for fine-grained control over permissions at the organization, organizational unit (OU), or individual account level.
  4. Compliance Enforcement: SCPs help enforce compliance standards by ensuring that access to sensitive services or actions is limited to authorized entities only.
  5. Default Deny Principle: SCPs adhere to the “deny-by-default” principle, meaning that all actions are denied unless explicitly allowed by the policy.
  6. Impact on IAM Policies: SCPs can override or augment the permissions granted by IAM policies attached to individual IAM entities within member accounts.

Use Cases:

  1. Security Standards: SCPs are valuable for enforcing security standards across the organization, ensuring that only authorized actions are permitted and mitigating the risk of unauthorized access.
  2. Cost Controls: SCPs can be used to manage costs by restricting access to expensive AWS services or actions that may lead to unnecessary expenses.
  3. Compliance Requirements: Organizations subject to regulatory compliance requirements can use SCPs to enforce access controls and data protection measures mandated by regulations.
  4. Custom Governance Policies: SCPs can be tailored to meet the specific security and governance needs of the organization, providing flexibility in policy enforcement while maintaining compliance.

In summary, Organization Policies (Service Control Policies) offer a robust framework for controlling access to AWS resources within AWS Organizations, facilitating security, compliance, and efficient resource management across the entire organization’s AWS environment.

5️⃣ Access Control Lists (ACLs)

Access Control Lists (ACLs) are a mechanism used in computer security to define and manage permissions at the resource level. They specify which users or system processes are granted access to objects, as well as what operations they are allowed to perform on those objects. ACLs are typically associated with files, directories, network resources, or other system resources, and they provide a granular level of control over access permissions.

ACLs play a crucial role in managing permissions by allowing administrators to define who can access specific resources and what actions they can perform on those resources. By configuring ACLs, administrators can enforce security policies, restrict unauthorized access, and ensure compliance with regulatory requirements. ACLs complement other access control mechanisms such as user roles, groups, and policies, providing an additional layer of control at the resource level.

Common Uses and Impact on Access Control:

  1. File Systems: In file systems, ACLs are used to control access to files and directories. For example, an ACL on a file may specify which users or groups are allowed to read, write, or execute the file. This allows administrators to restrict access to sensitive files or directories based on user identity or group membership.
  2. Network Resources: ACLs are commonly used in network devices such as routers, switches, and firewalls to control traffic flow and enforce security policies. By configuring ACLs on network interfaces or ports, administrators can filter incoming and outgoing traffic based on source and destination IP addresses, protocols, and ports.
  3. Cloud Services: In cloud computing environments, ACLs are used to control access to cloud resources such as storage buckets, databases, and virtual machines. By defining ACLs on these resources, administrators can manage access permissions for users, applications, and services accessing the cloud infrastructure.
  4. Database Systems: ACLs are employed in database management systems to regulate access to database objects such as tables, views, and stored procedures. Database ACLs specify which users or roles have permission to perform operations such as querying data, modifying schema, or executing SQL commands.
  5. Web Servers: ACLs are utilized in web servers to control access to web content and applications. By configuring ACLs on directories or files within the web server's document root, administrators can restrict access to sensitive files, directories, or web applications based on client IP addresses, authentication credentials, or other criteria.

Overall, ACLs provide a flexible and powerful mechanism for managing permissions at the resource level, allowing administrators to enforce access control policies tailored to their specific security requirements. However, it's essential to carefully design and configure ACLs to avoid unintended access permissions or security vulnerabilities. Regular audits and reviews of ACL configurations are recommended to ensure effective access control and mitigate security risks.

6️⃣ Session Policies

Session policies in AWS Identity and Access Management (IAM) are temporary permissions that are dynamically applied to a user or role during a specific session. Unlike identity-based policies, which are attached to IAM entities such as users, groups, or roles, session policies are not stored or attached directly. Instead, they are passed as parameters when initiating a session, typically through services like AWS Security Token Service (STS) or AWS Identity Federation.

Features:

  1. Temporary Permissions: Session policies provide temporary permissions that are only valid for the duration of a specific session. Once the session expires, the permissions are automatically revoked.
  2. Dynamic Assignment: Session policies are dynamically applied to users or roles when they assume temporary credentials, allowing for flexible and on-demand access control.
  3. Limited Scope: Session policies can define a subset of permissions compared to permanent identity-based policies, providing a more restricted scope of access for specific tasks or operations.
  4. Flexible Access Control: Session policies enable fine-grained control over permissions, allowing administrators to tailor access rights based on the requirements of individual sessions or applications.
  5. Security Benefits: By providing temporary credentials with limited permissions, session policies help reduce the risk of unauthorized access and privilege escalation in the event of credential compromise.
  6. Auditing and Compliance: Session policies contribute to auditing and compliance efforts by providing visibility into the specific permissions granted during each session, aiding in tracking and monitoring access activities.

Use Cases:

  1. Temporary Access: Session policies are commonly used to grant temporary access to AWS resources for users or applications that require short-term permissions.
  2. Cross-Account Access:

Organizations often use session policies to enable cross-account access, allowing users from one AWS account to assume roles in another account with specific permissions.

3. Federated Identity Access:

Session policies facilitate federated identity access scenarios, where users authenticate through external identity providers and receive temporary credentials with scoped permissions.

4. Least Privilege Principle:

By applying session policies with the principle of least privilege, organizations can ensure that users and applications only have access to the resources necessary to perform their intended tasks, reducing the risk of unauthorized actions.

In summary, session policies offer a flexible and secure approach to temporary access control in AWS IAM, providing organizations with the ability to grant precisely scoped permissions for short-lived sessions or specific use cases while maintaining strong security posture and compliance standards.

🌟 Conclusion:

IAM policies serve as the cornerstone of security infrastructure within AWS environments, offering essential control over access permissions and ensuring compliance with regulatory standards. Mastery of IAM policy management is essential for organizations seeking to fortify their cloud deployments against unauthorized access and maintain adherence to compliance requirements. By understanding the intricacies of IAM policies and employing best practices in their management, organizations can establish and uphold robust security postures in the dynamic landscape of cloud computing.

For further insights and discussions on AWS IAM policies and cloud security, feel free to connect with me on LinkedIn!Let’s secure the cloud together! 🛡️💼

--

--

Mohasina Clt

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