Kill the Castle: How AWS IAM Moves Beyond the Network Perimeter
In this article
AWS Identity and Access Management (IAM) replaces the traditional castle-and-moat security model by authenticating and authorizing every API request individually, regardless of where it originates. Instead of trusting anything inside the corporate network, IAM treats every request as untrusted and checks it against policies that define exactly what a principal (user, role, or service) may do. This article explains how IAM shifts security from network location to identity, how policies work, and what you need to consider when adopting this model.
The Castle-and-Moat Model and Its Limits
For decades, network security relied on a hard outer shell: firewalls, VPNs, and physical data centers created a trusted internal network. Anything inside the perimeter was assumed safe, and anything outside was blocked. This model worked when applications lived on servers in a building, but it breaks in the cloud for several reasons:
- Cloud resources are accessible from anywhere, so the perimeter is no longer a physical boundary.
- Users work from home, on mobile devices, and from partner networks, making VPNs a bottleneck and a single point of failure.
- Microservices and serverless functions communicate across the internet, so internal traffic is indistinguishable from external traffic.
- Compromised internal hosts become attack vectors because the network trusts them.
AWS IAM addresses these issues by making identity the primary security boundary. Every request to AWS is authenticated (who are you?) and authorized (are you allowed to do this?), regardless of IP address or network path.
How IAM Works: Authentication and Authorization
IAM is a global service that manages identities and policies. When you make an API call (e.g., starting an EC2 instance, reading an S3 object), the request is sent to the AWS service, which forwards it to IAM for evaluation. IAM checks:
- Authentication: The request must include credentials (access keys, temporary session tokens, or a signed request) that prove the caller is who they claim to be.
- Authorization: IAM evaluates all applicable policies to determine whether the caller is allowed to perform the requested action on the specified resource.
If both pass, the request is allowed; otherwise, it is denied. This evaluation happens for every single API call, so even a user inside a VPC or behind a NAT gateway must have valid IAM credentials and permissions.
Policies: The Core of IAM
Policies are JSON documents that define permissions. They are attached to identities (users, groups, roles) or to resources (like S3 buckets). A policy contains statements with:
- Effect: Allow or Deny.
- Action: The specific API operations (e.g., s3:GetObject).
- Resource: The ARN (Amazon Resource Name) of the resource (e.g., arn:aws:s3:::example-bucket/*).
- Condition: Optional constraints like IP address, date, or MFA presence.
IAM evaluates policies in a specific order: explicit deny overrides allow, and if there is no explicit allow, the request is denied by default. This is known as the default deny principle. For example, a policy that allows s3:GetObject on a bucket but denies it when the user is not using MFA would block access from a non-MFA session.
Beyond Users: Roles and Temporary Credentials
IAM is not just about human users. AWS recommends using IAM roles for applications and services. A role is an identity with permissions that can be assumed temporarily. When an EC2 instance needs to access S3, it assumes a role and receives temporary credentials (via the instance metadata service). These credentials expire after a short time (default 1 hour), reducing the risk of stolen keys.
Roles also enable cross-account access. For example, a central security team can assume a role in a production account to perform audits, without needing long-lived credentials in that account. This is a key part of the "kill the castle" approach: you don't give out permanent keys; you grant temporary, scoped access.
Identity Federation: Bringing Your Own Identity
To fully move beyond the network perimeter, IAM supports identity federation with external identity providers (IdPs) like Okta, Active Directory, or Google. Users authenticate against the IdP, and AWS issues temporary credentials based on the SAML or OIDC assertion. This means:
- Users do not have IAM usernames or passwords; they use their corporate credentials.
- You can enforce multi-factor authentication (MFA) at the IdP level.
- You can revoke access centrally by disabling the user in the IdP.
Federation is essential for a zero-trust model because it decouples access from the network. A user on a public Wi-Fi network with valid MFA can access AWS resources, while a user on the corporate LAN without MFA cannot.
Common Pitfalls and Misconceptions
Many organizations still think of IAM as just a way to manage users. Here are common mistakes:
- Using the root user for daily tasks: The root user has unrestricted access. AWS recommends creating an admin user with MFA and using the root only for account-level tasks.
- Overly permissive policies: Using "*" for actions or resources is easy but dangerous. Always grant the least privilege needed.
- Ignoring conditions: Conditions like aws:SourceIp, aws:MultiFactorAuthPresent, and aws:PrincipalOrgID add context to policies. Without them, a stolen key works from anywhere.
- Confusing IAM with network ACLs: IAM controls API access, while security groups and NACLs control network traffic. They are complementary, not interchangeable.
A common misconception is that IAM alone replaces all network security. In reality, you still need security groups, VPCs, and encryption to protect data in transit and at rest. IAM is the identity layer, but defense in depth remains important.
How to Implement IAM Effectively
To truly move beyond the network perimeter, follow these practices:
- Use roles for everything: Avoid access keys for applications. Use roles for EC2, Lambda, ECS, and even for CLI access (via IAM Identity Center).
- Enforce MFA: Require MFA for all human users, and add a condition to policies that denies access if MFA is not present.
- Implement least privilege: Start with no permissions and grant only the required actions on specific resources. Use IAM Access Analyzer to identify over-permissive policies.
- Use conditions: Add conditions like aws:SourceIp (for trusted ranges), aws:PrincipalOrgID (for organization accounts), and aws:RequestedRegion (to restrict to specific regions).
- Monitor and audit: Enable CloudTrail to log all API calls, and use IAM Access Advisor to see which services are actually used.
- Rotate credentials: For the few cases where access keys are unavoidable, rotate them regularly and use separate keys for different environments.
Frequently Asked Questions
Does IAM replace security groups?
No. IAM controls who can make API calls, while security groups control network traffic at the instance level. They work together: a security group might allow traffic from a certain CIDR, but IAM still determines whether the caller can start or stop an instance.
Can IAM work without a network perimeter?
Yes, that's the point. IAM evaluates every request based on identity and policy, not on the network source. You can have users access resources from any IP, as long as they have valid credentials and permissions. However, you can still add network-based conditions to policies if you want to restrict to certain IP ranges.
What is the difference between IAM user and IAM role?
An IAM user has long-term credentials (password or access keys) and is typically used for human users. An IAM role has no permanent credentials; it is assumed temporarily by a user or service to obtain short-lived credentials. Roles are preferred for applications and for cross-account access.
How do I grant a user access to only one S3 bucket?
Create a policy that allows s3:ListBucket on the bucket ARN and s3:GetObject, s3:PutObject on the ARN with /*. Attach the policy to the user or a group. Add a condition to deny access if the user is not using MFA for extra security.
Can I use IAM to restrict access to a specific VPC?
Yes, you can use the aws:SourceVpc condition in a policy to allow actions only when the request originates from a specific VPC. This combines identity and network context, but the primary control is still IAM.
What happens if I don't use IAM at all?
You would have to use the root user for everything, which is extremely dangerous. The root user has full access and cannot be restricted. AWS strongly recommends creating IAM users or roles and using the root only for account-level tasks like closing the account.