The IAM oversight that could sink your security
Imagine leaving the front door of your house wide open with a sign that says, "Help yourself."
Seems absurd, right? Yet in the cloud, failing to control access to your AWS environment is the digital equivalent—a wide-open door that anyone can walk through.
That’s where AWS Identity and Access Management (IAM) comes in. IAM lets you decide who can do what, when, and where—giving you the tools to secure your resources without compromising usability.
IAM handles two critical tasks: authentication (verifying identities) and authorization (defining permissions). It's a core, critical part of cloud security that ensures that only the right people—and services—can access your resources, and only under the right conditions.
In this newsletter, we'll cover:
What IAM policies are and why they’re critical to AWS security
The different types of policies and when to use them
Best practices for writing secure, effective policies
By the end, you’ll have the tools to safeguard your AWS environment with precision – keeping your resources secure without hindering productivity.
Let’s dive in.
A quick overview of IAM#
First things first: Let's clarify what IAM is and how we use it.
AWS Identity and Access Management (IAM) is about defining who can do what in your cloud environment. Its real power lies in policies—JSON-based documents that specify the exact permissions granted to users, roles, or resources.
IAM policies let you:
Grant precise permissions for specific tasks.
Attach rules directly to resources like S3 buckets for fine-grained access control.
Apply conditions like IP ranges or MFA status to enforce security requirements.
By understanding and applying IAM policies effectively, you can secure your AWS environment while ensuring smooth, efficient operations for your teams and services.
Let’s explore into the different types of IAM policies and how to use them effectively.
IAM identities #
IAM has many authentication tools called IAM identities. The most widely used of these identities are IAM users and IAM roles. We won’t delve into their details as they are outside the scope of this blog.
Want to learn more? Check out the “Identity and Access Management” section of our “Master AWS Certified Solutions Architect Associate SAA-C03 Exam” course.
Once authentication is done through IAM, the next crucial element is authorization, which is where IAM policies come into play.
AWS IAM policies#
AWS IAM policy functions like a set of access rules provided to security personnel, determining which areas of the house (AWS resources and services within the account) the authenticated identity can access. These policies are written in JSON format and specify which actions the authenticated identity can perform on which resources.
Types of AWS IAM policies#
Based on their usage, IAM has five types of policies.
Before we delve into the details, you must be familiar with the term principal, as we’ll use it throughout our discussion. A principal is any entity that requests permission to perform actions on resources. In the context of IAM, a principal can be a user, a role, a service, or even an application making requests to access resources.
Now that you’re familiar with the term principal, it’s time to explore the different types of AWS IAM policies in AWS.
1. Identity-based policies#
Identity-based policies are attached to IAM identities. These policies determine the permissions of the principals using those identities for authentication. These policies can be used to define:
What actions can the principal perform?
On which resources/services can the principal perform those actions.
When can the principal perform those actions?
Components of an identity-based policy#
The JSON document of an identity-based policy can have the following elements:
Version(optional): Indicates the IAM policy language version being used.Statement(required): Contains the core elements of the policy. It is an array that contains the groups of these core elements in the form of array elements. It can contain the following elements:Sid(optional): Used to write the description of an individual statement array element. Its value should be a string. It must be unique within the policy.Action(required): This field contains the list of actions to be allowed or denied. It can contain any AWS-defined actions that specify a specific action related to an IAM service.NotAction(required): Contains the list of actions not to be allowed or denied. It is the inverse of the allowed action. A single statement element can contain eitherActionorNotActionand requires at least one to be present.Effect(required): Specifies if theActions/NotActionsare allowed or denied. Its value can either beAlloworDeny.Resource(required): This field contains the list of AWS resources’ s to which the statement provides or prevents access.ARN Amazon resource name (ARN) is a unique identifier AWS uses to identify each resource NotResource(required): Contains the list of AWS resources’ ARNs to which the statement is not providing or preventing access. A single statement can contain either Resource or NotResource and requires at least one of them to be present.Condition(optional): Contains conditions that must be met for the statement to take effect.
An identity-based policy would look as follows:
This policy attaches to the authenticating IAM resource. It allows the principal entity to create an S3 bucket by the name demo-bucket. The Condition element restricts the s3:CreateBucket permission to requests from the specified IP range. This sample policy only contains a single statement and, within that, the required elements. It can contain multiple statements depending on the user’s authorization.
Types of identity-based policies#
These policies can be categorized into the following types:
Managed policies: These are discrete identity-based policies that exist independently of any other IAM resource. Managed policies can be attached to multiple IAM resources at the same time. Managed policies are further categorized into two types:
AWS-managed policies: These are prebuilt policies created and managed by AWS. They are ready to use but less flexible as they cannot be modified.
Customer-managed policies: These are the identity-based policies created and managed in our AWS account. As they are custom-built policies, you can draft and modify them according to your specific requirements.
Use case: Consider a scenario where a new member joins your data analysis team. You want to give them full access to the AWS Lambda function only. You create an IAM user for them and simply assign them the
AWSLambda_FullAccessAWS-managed policy. Now, you want to give them access to specific resources from the machine learning team. You can create a customer-managed policy (allowing restricted access to Amazon Bedrock and SageMaker) and attach this policy to the IAM user.
Inline policies: These are custom policies drafted when creating an IAM resource. Inline policies are attached with the IAM identities when created and get deleted when that identity is deleted.
2. Resource-based policies#
Resource-based policies are very similar to identity-based policies. The primary distinction between them is the type of entity they are associated with.
Identity-based policies are attached directly to IAM identities (such as users, groups, or roles) to specify the identity’s permissions across various AWS resources.
In contrast, resource-based policies are attached to AWS resources (like S3 buckets or SNS topics) to control which identities or external accounts can access that particular resource.
Interesting insight: The IAM role is an IAM resource with which identity-based and resource-based policies can be attached.
Components of a resource-based policy#
The components of a resource-based policy are the same as those of identity-based policies. However, there are a few additional elements, which are listed below:
Id(optional): Specifies a unique identifier for the policy. Its value must be a string.Principal(required): Specifies the principal entity. The format of its value depends on the kind of principal that you want to specify. These are the kinds of entities you can specify as a principal in a resource-based policy:AWS principals: These are used to specify an AWS account or a specific AWS resource as the principal entity. The structure for these types of principals within the policy is as follows:
AWS-account-id: The 12-digit identifier for the AWS account. This specifies which account is granted access to the resource.AWS-resource-ARN: The specific IAM resource within the account that needs access, which could be an IAM user, IAM role, or other resource.OIDC session principals: These principals are used in policies for IAM roles that external users can assume after authenticating with an OpenID Connect (OIDC) provider. When a user logs in through an external OIDC provider, AWS issues a role session based on this trusted provider. To specify an OIDC session principal in your policy, use the following format:
provider-identifierrepresents the identity provider’s identifier or ARN. For example,"graph.facebook.com"is used as a provider’s identifier for Facebook if configured as an OIDC provider in AWS.Service principals: These are used to specify an AWS service as the principal. The generic format for this type of principal is as follows:
<AWS-service-identifier>is essentially the unique identifier of the AWS service, such asecs.amazonaws.comfor ECS ors3.amazonaws.comfor S3.All principals: You can also specify
*as the principal, indicating that you want all principals to be able to perform the actions specified in the policy. This wildcard symbol is a shorthand that grants access to any principal, regardless of their identity. This principal is specified as follows:
A resource-based policy would look as follows:
This IAM policy permits AWS Lambda (lambda.amazonaws.com) to retrieve an object (s3:GetObject) from a specific S3 bucket (demo-bucket/demo-object). The access is restricted to requests made between 2024-11-01T00:00:00Z and 2024-11-01T23:59:59Z, using the aws:RequestTime condition to enforce this time-based restriction.
Identity-based and resource-based policies are the primary IAM policies used in AWS. The other three policy types are generally used to set limits or upper bounds on permissions. These additional policies help refine access controls but not replace the core identity and resource-based policy frameworks.
These policies share the same structure as identity-based policies, so we don't need to detail their components. Instead, we’ll focus on understanding where these policies are applied and how they contribute to refining access control within AWS.
3. Permissions boundary policies#
Permission boundary policies specify the highest permissions an identity-based policy can grant to an entity. Even if an identity-based policy grants wide permissions, the permissions boundary restricts those permissions to the maximum allowed within the boundary, ensuring that no permissions can exceed a defined limit.
For example, suppose an IAM user or role has an identity-based policy granting broad access but is assigned a permissions boundary restricting access to certain resources. In that case, the user can only access the resources allowed within the identity-based policy and the permissions boundary.
In essence, while identity-based policies specify what an identity can do, permissions boundaries set an upper limit to how far those actions can go.
4. Session policies#
When a principal assumes an IAM role to access AWS resources or services, a session is set up for them. This session includes the permissions associated with their role, defining what actions they can perform during that session. You can attach session policies with these sessions to define the highest level of permissions granted within the sessions, overriding the permissions in the identity-based policy.
By using session policies, you can apply additional, granular control over what a principal can do during their temporary role session, making them particularly useful in scenarios where you need to limit access further than the permissions granted in the identity-based policy.
Want to learn more? Implement this architecture by exploring our Cloud Lab: Configuring Role-Specific Temporary Access to an AWS Account.
5. Organizations Service Control Policies (SCPs)#
You can use AWS Organizations to manage multiple accounts through one single account.
Service Control Policies (SCPs) become useful in such a scenario. They are used at the organizational level within AWS Organizations to define the maximum available permissions for the children accounts. SCPs allow administrators to set policies determining the highest permissions that can be granted to any identity-based policy, effectively controlling the scope of what users and roles in those accounts can do, regardless of what is specified in the account’s individual IAM policies.
Effectively, SCPs cannot grant permissions directly; they restrict the permissions that the identity-based policies can assign.
Building on the detailed discussion of IAM policies, here’s a quick overview of the key IAM policy types, their usage, and when to apply each one.
Policy Type | Where It’s Attached | Scope | Reusability | Best For |
AWS-managed policies | IAM identities | Broad, predefined use cases | High | Quickly granting common permissions |
Customer-managed policies | IAM identities | Custom-tailored use cases | High | Defining organization-specific permissions |
Inline policies | Specific IAM identity | Specific to that identity | None | Tightly controlled, one-off permissions |
Resource-based policies | AWS resources | Resource-specific access control | Medium | Cross-account access or resource-specific rules |
Permissions boundaries | IAM identity | Restricts maximum permissions | Medium | Enforcing consistent restrictions |
Session policies | Temporary sessions | Refines session-specific permissions | Low | Temporary, granular access control |
Service control policies | AWS Organizations (Organization Units/accounts) | Global restrictions across multiple accounts | High | Organizational compliance and global policies |
IAM policy evaluation#
So far, we’ve explored the significance of IAM policies in an AWS environment and examined the different types of IAM policies in detail. Now, let’s delve into how AWS evaluates these policies to determine whether a specific action is allowed or denied.
AWS follows a structured set of rules to evaluate permissions for any action requested by an authenticated principal:
Implicit deny by default: By default, any action that is not explicitly allowed by a policy is denied. This implicit denial ensures that IAM principals must be explicitly granted permission to perform actions.
Explicit Allow vs. Explicit Deny: The request is permitted if at least one identity-based or resource-based policy explicitly allows the requested action and no policy denies it. However, if any policy explicitly denies the action, the request is denied—regardless of other policies that might allow it.
Impact of different policies: Each policy type has its own rules for evaluation and can affect the final decision. For example, IAM permissions boundaries set the maximum permissions that an identity-based policy can grant, while AWS Organizations SCPs specify the maximum permissions for an organization or organizational unit. The diagram below depicts the flow in which a policy is evaluated.
In simple terms, AWS first checks whether the identity-based policy for the principal or the resource-based policy attached to the resource explicitly allows the requested action. If it is allowed, AWS then verifies that no other applicable policy explicitly denies the action. The action is permitted if no explicit denial exists; otherwise, the request is denied.
Now, let's examine some best practices you can apply to writing your own IAM policies.
Best practices for writing AWS IAM policies#
Creating IAM policies can be tricky. Here are some best practices to ensure your policies are both secure and effective:
1. Follow the principle of least privilege#
Always aim to give the minimal access necessary for a user or service to perform their tasks. Avoid granting excessive permissions like AdministratorAccess unless necessary.
For example, if a user only needs to read objects from a specific S3 bucket, create a policy that grants s3:GetObject on that bucket alone.
2. Use conditions to restrict access#
AWS IAM policy conditions are powerful tools for controlling when and how permissions are applied. Conditions can restrict access based on criteria such as IP addresses, user attributes, or even MFA status.
For instance, you can restrict starting the EC2 instance to only those instances that are tagged with Environment: Production:
{"Effect": "Allow","Action": "ec2:StartInstances","Resource": "arn:aws:ec2:region:account-id:instance/instance-id","Condition": {"StringEquals": {"aws:RequestTag/Environment": "Production"}}}
3. Test policies in a safe environment#
Before applying the AWS IAM policies in a production environment, always test them in a safe, non-production environment. This helps you ensure they function as intended without inadvertently exposing sensitive resources or disrupting operations.
4. Use managed policies for common use cases#
AWS-managed policies provide a good starting point for common scenarios like granting read-only access to the AWS resources. Consider a scenario where you want to allow the user to only view the S3 buckets and objects. You can use the AmazonS3ReadOnlyAccess AWS Managed Policy for this.
The managed policies’ benefit is that AWS regularly updates them to cover best practices and new services.
5. Review and audit policies regularly#
Over time, your AWS environment will change, and so should your policies. Make it a habit to periodically review IAM policies to ensure they still align with AWS security best practices and your access requirements. AWS IAM Access Analyzer and AWS CloudTrail can help you audit and monitor access patterns.
Take control of your AWS environment#
AWS IAM is your best ally for managing access to your cloud resources. By mastering IAM policies, you’re taking a critical step toward building a secure, scalable, and well-managed AWS environment.
Now it’s time to apply what you’ve learned:
Build policies that follow best practices
Audit them regularly
Test your configurations in a safe environment
Follow these best practices, and you'll make sure your front door is always open for those who need it—and locked for those who don't.
Ready to take your knowledge further? Jump into a real AWS environment and gain hands-on experience with our Cloud Lab on IAM policies:
Cloud Lab: Securing AWS Resources: Managing Access with IAM
This lab covers IAM policies and integrates other IAM components to demonstrate their practical applications.