AWS IAM Deep Dive: Roles, Policy Evaluation & Enterprise Governance
Master AWS Identity and Access Management (IAM): the 6-step policy evaluation algorithm, STS assume-role mechanics, permission boundaries, and least-privilege automation.
AWS IAM Deep Dive: Roles, Policy Evaluation & Enterprise Governance
Section titled βAWS IAM Deep Dive: Roles, Policy Evaluation & Enterprise GovernanceβAWS Identity and Access Management (IAM) is the central control plane of all AWS cloud operations. In cloud security, identity is the new perimeter. Unlike on-premises networks where access was governed by physical firewall boundaries, AWS evaluates every single API actionβfrom spinning up an EC2 instance to reading an S3 objectβagainst IAM policies.
A single misconfigured wildcard (Action: "*", Resource: "*") can allow an attacker with compromised credentials on one low-priority microservice to gain full administrative takeover of your entire enterprise AWS account.
1. The 6-Step IAM Policy Evaluation Engine
Section titled β1. The 6-Step IAM Policy Evaluation EngineβWhen an API request arrives at an AWS endpoint, the IAM evaluation engine runs an algorithmic check against all relevant policies in strict order:
[ Incoming AWS API Request ] β Step 1: Check for an EXPLICIT DENY in any applicable policy βββ YES ββ> [ ACCESS DENIED ] (Permanent & Immediate!) βββ NO β Step 2: Evaluate AWS Organizations Service Control Policies (SCPs) βββ NOT ALLOWED ββ> [ ACCESS DENIED ] βββ ALLOWED β Step 3: Evaluate Resource-Based Policies (e.g. S3 Bucket Policy, KMS Key) βββ ALLOWED ββ> [ Proceed to check explicit deny, then GRANT ] βββ NO POLICY β Step 4: Evaluate Identity-Based Policies (Attached to IAM Role / User) βββ NOT ALLOWED ββ> [ ACCESS DENIED ] (Default Implicit Deny) βββ ALLOWED β Step 5: Evaluate IAM Permissions Boundaries (Delegated Admin Maximum Cap) βββ NOT ALLOWED ββ> [ ACCESS DENIED ] βββ ALLOWED β Step 6: Evaluate Session Policies (STS AssumeRole Scoping Restrictions) βββ NOT ALLOWED ββ> [ ACCESS DENIED ] βββ ALLOWED ββ> [ ACCESS GRANTED β ]The Three Golden Rules of IAM Evaluation:
Section titled βThe Three Golden Rules of IAM Evaluation:β- Default Deny: All requests are implicitly denied by default until an explicit
Allowis found. - Explicit Deny Always Wins: If even a single statement in any policy explicitly evaluates to
Effect: Deny, access is blocked permanentlyβeven if 10 other policies grantAllow. - Cross-Account Authorization: When accessing resources in another AWS account, both the senderβs identity policy and the receiverβs resource policy must explicitly permit the action!
2. Eliminating Long-Lived Credentials: STS & GitHub Actions OIDC
Section titled β2. Eliminating Long-Lived Credentials: STS & GitHub Actions OIDCβIn enterprise DevSecOps, static IAM users with access keys (AKIA...) are strictly prohibited. Static keys are frequently leaked in GitHub commits, exposed in bash histories, or stored unencrypted on developer laptops.
The Modern Standard: GitHub Actions OpenID Connect (OIDC)
Section titled βThe Modern Standard: GitHub Actions OpenID Connect (OIDC)βInstead of storing secret AWS keys in your GitHub repository secrets, your CI/CD runner requests temporary cryptographic tokens via OIDC federation:
[ GitHub Actions Workflow ] β (Presents signed JWT token with repo claims) βΌ[ AWS Security Token Service (STS) ] β (Validates token against OIDC Provider: https://token.actions.githubusercontent.com) βΌ (Returns temporary 15-minute STS credentials: SessionToken + SecretKey)[ AWS IAM Role: Role-GitHub-CI-CD ] β βΌ[ Provisions Infrastructure safely via Terraform / AWS CLI ]Production IAM Role Trust Policy for GitHub Actions OIDC:
Section titled βProduction IAM Role Trust Policy for GitHub Actions OIDC:β{ "Version": "2012-10-17", "Statement": [ { "Sid": "AllowGitHubActionsOIDCFederation", "Effect": "Allow", "Principal": { "Federated": "arn:aws:iam::123456789012:oidc-provider/token.actions.githubusercontent.com" }, "Action": "sts:AssumeRoleWithWebIdentity", "Condition": { "StringEquals": { "token.actions.githubusercontent.com:aud": "sts.amazonaws.com" }, "StringLike": { "token.actions.githubusercontent.com:sub": "repo:my-enterprise-org/core-infrastructure:ref:refs/heads/main" } } } ]}Notice the strict StringLike condition: Only commits running on the main branch of that exact repository can assume this role!
3. IAM Permission Boundaries: Guardrails for Delegated Developers
Section titled β3. IAM Permission Boundaries: Guardrails for Delegated DevelopersβIn modern platform engineering, centralized security teams donβt want to create every single IAM role requested by developers. However, allowing developers to create IAM roles directly (iam:CreateRole) enables privilege escalation: a developer could simply create a role with AdministratorAccess and assume it.
IAM Permission Boundaries solve this by setting an immutable ceiling on permissions:
Actual Effective Permissions = Developer Attached Policy β© Permission BoundaryProduction Enforcement Pattern:
Section titled βProduction Enforcement Pattern:βSecurity teams attach a policy condition mandating that any developer creating a role must attach the boundary:
{ "Version": "2012-10-17", "Statement": [ { "Sid": "EnforcePermissionBoundaryOnRoleCreation", "Effect": "Allow", "Action": [ "iam:CreateRole", "iam:PutRolePolicy", "iam:AttachRolePolicy" ], "Resource": "*", "Condition": { "StringEquals": { "iam:PermissionsBoundary": "arn:aws:iam::123456789012:policy/DeveloperMaxPermissionBoundary" } } } ]}If a developer tries to create an IAM role without attaching the boundary, AWS rejects the API call with AccessDenied!
4. Real-Time Production Triage Runbook
Section titled β4. Real-Time Production Triage RunbookβIncident: Mysterious AccessDenied Error on an S3 or DynamoDB API Call
Section titled βIncident: Mysterious AccessDenied Error on an S3 or DynamoDB API CallβSymptom: Application receives AccessDenied (HTTP 403), but the attached IAM Policy clearly shows Action: "s3:GetObject".
Triage Protocol:
- Search AWS CloudTrail Event History:
Look for the failed event name (e.g.,
GetObject). Inspect theerrorMessagefield in the CloudTrail JSON. AWS now reports the exact evaluation failure reason (e.g.,"errorCode": "AccessDenied", "errorMessage": "User is not authorized to perform kms:Decrypt on resource arn:aws:kms:..."). - Check for KMS Key Policy Restrictions:
If the resource is encrypted with a KMS Customer Managed Key, the identity must have explicit
kms:Decryptorkms:GenerateDataKeypermissions in the KMS Key Policy, which operates independently from IAM! - Check for AWS Organizations SCPs:
Navigate to the AWS Organizations console and review Service Control Policies applied to the account or parent OU. Check if region restrictions or service denies (
DenyS3IfNotEncrypted) are blocking the call. - Use the AWS IAM Policy Simulator:
Run the IAM Policy Simulator CLI to test authorization logic deterministically without triggering live infrastructure changes:
Terminal window aws iam simulate-principal-policy \--policy-source-arn arn:aws:iam::123456789012:role/AppServiceRole \--action-names s3:GetObject \--resource-arns arn:aws:s3:::corp-secure-data/data.csv
π§ Architect Knowledge Check
Section titled βπ§ Architect Knowledge Checkβ1. An IAM role has an identity policy granting AdministratorAccess (*: *). However, an SCP attached to the account specifies Effect: Deny, Action: "ec2:*". Can an engineer assuming this role launch an EC2 instance?
Answer: No. An explicit
Denyin an AWS Organizations Service Control Policy (SCP) sets the maximum permission ceiling for the account. An explicit Deny in an SCP permanently overrides anyAllowgranted by identity-based or resource-based policies.
2. What is the fundamental difference between an IAM Role and an IAM Instance Profile when working with Amazon EC2?
Answer: An IAM Role is an identity container that defines a trust policy (who can assume it) and permission policies (what it can do). An Instance Profile is a specialized container used strictly by Amazon EC2 to pass the IAM Role to the instanceβs virtual hardware metadata service (IMDS). When using the AWS Console, the instance profile is generated automatically behind the scenes; when using Terraform or the AWS CLI, you must explicitly create the
aws_iam_instance_profileresource and associate it with theaws_iam_role.