Docs / IAM Enforcement

IAM Policy Enforcement

Evaluate IAM policies on every API request before service dispatch. Test your permission boundaries, resource policies, and least-privilege setups locally.

Enabling IAM Enforcement

Strict mode: denied requests return 403 AccessDenied

Terminal
$ IAM_ENFORCEMENT=1 localemu start
IAM policy enforcement: enabled
Ready.

Soft mode: denied requests are logged but still allowed

Terminal
$ IAM_ENFORCEMENT=soft localemu start
IAM policy enforcement: soft mode (log only)
Ready.

# Denied requests are logged but still allowed:
WARN IAM: would deny s3:GetObject for arn:aws:iam::000000000000:user/dev on arn:aws:s3:::my-bucket/*

Soft mode is useful for auditing existing workflows before switching to strict enforcement.

How It Works

Every API request is intercepted before it reaches the service handler. The enforcement engine extracts the caller identity, the action, and the target resource, then evaluates all applicable policies using the AWS policy evaluation algorithm:

1. Explicit deny in any policy results in immediate denial
2. Resource-based policy is evaluated (S3 bucket policy, SQS queue policy, etc.)
3. Identity-based policy is evaluated (user/role/group policies)
4. Permission boundary is checked (if attached to the principal)
5. If no explicit allow is found, the request is denied by default

Supported Policy Features

Feature Details
Action matchingExact match, wildcards (s3:*, s3:Get*)
Resource matchingFull ARN matching with wildcards
NotAction / NotResourceInverse matching for actions and resources
Condition operators26 operators: StringEquals, StringLike, IpAddress, ArnLike, DateLessThan, NumericGreaterThan, Bool, Null, and more
IfExists variantsStringEqualsIfExists, IpAddressIfExists, etc. - condition passes if the key is absent
Set operatorsForAllValues and ForAnyValue qualifiers for multi-valued condition keys
Identity-based policiesInline and managed policies on users, groups, and roles
Resource-based policiesS3 bucket policies, SQS queue policies, SNS topic policies, KMS key policies, Lambda function policies, EventBridge event bus policies
Permission boundariesMaximum permissions boundary attached to users or roles

Special Rules

Root principal bypass

Requests signed with a root access key bypass all IAM checks. Default root keys are AKIAIOSFODNN7EXAMPLE and 000000000000. The awsemu CLI uses AKIAIOSFODNN7EXAMPLE by default. To add your own root key IDs, set ROOT_ACCESS_KEYS to a comma-separated list of access key IDs you want to exempt.

26 unconditionally exempt actions

A fixed list of 26 actions bypasses enforcement entirely, mirroring what AWS itself never gates behind IAM: 4 STS bootstrap actions (sts:GetCallerIdentity, GetSessionToken, AssumeRoleWithWebIdentity, AssumeRoleWithSAML) so callers can identify or authenticate themselves before they have any permissions, plus 18 cognito-idp actions and 4 cognito-identity actions that an app calls before it holds any AWS credentials (sign-up, sign-in, token/MFA management, and the unauthenticated identity-pool bootstrap calls). Every other action, including the rest of STS (AssumeRole) and all of IAM, is evaluated against policies.

Internal-call sentinel

LocalEmu's own cross-service calls (e.g., an S3 PutObject that triggers a Lambda, or an Event-Source-Mapping reading from SQS) bypass enforcement via an internal sentinel key. Users never produce this key, it exists so the emulator's plumbing is not blocked by user policies.

Error format

Denied requests return HTTP 403 with an AccessDenied error. The message includes the caller ARN, the attempted action, and the target resource.

Revoking issued sessions with aws:TokenIssueTime

Assumed-role sessions carry the aws:TokenIssueTime condition key (UTC, ISO 8601). It supports the incident-response pattern of denying every session issued before a containment time while leaving sessions issued afterwards untouched:

{
  "Effect": "Deny", "Action": "*", "Resource": "*",
  "Condition": { "DateLessThan": { "aws:TokenIssueTime": "2026-10-08T16:16:11Z" } }
}

Timestamps have one-second precision, so a session issued in the same second as the cut-off is not older than it and is not denied. IAM users and sessions with no recorded issue time do not get the key. The key is also present on GetSessionToken and GetFederationToken sessions.

GetSessionToken and GetFederationToken

GetSessionToken credentials act as the IAM user that requested them (the root account's act as root), and GetCallerIdentity returns the user ARN. A later Deny added to the user applies to the session too. sts:GetSessionToken needs no IAM permission, as in AWS.

GetFederationToken (which does need sts:GetFederationToken) returns a federated-user/<Name> principal. Its permissions are the requesting user's policies intersected with the Policy passed in the call. With no policy passed, the federated user has no permissions, as in AWS. Both kinds of credentials stop working at their expiry.

ARN Building

The enforcement engine builds resource ARNs automatically for each service. This determines what the Resource field in your policy should match.

Service ARN Pattern
S3arn:aws:s3:::bucket-name/*
DynamoDBarn:aws:dynamodb:us-east-1:000000000000:table/name
Lambdaarn:aws:lambda:us-east-1:000000000000:function:name
SQSarn:aws:sqs:us-east-1:000000000000:queue-name
SNSarn:aws:sns:us-east-1:000000000000:topic-name
KMSarn:aws:kms:us-east-1:000000000000:key/key-id
IAMarn:aws:iam::000000000000:user/name
EC2arn:aws:ec2:us-east-1:000000000000:instance/i-id
CloudFormationarn:aws:cloudformation:us-east-1:000000000000:stack/name/uuid
CloudWatch Logsarn:aws:logs:us-east-1:000000000000:log-group:name
Secrets Managerarn:aws:secretsmanager:us-east-1:000000000000:secret:name
SSMarn:aws:ssm:us-east-1:000000000000:parameter/name
Step Functionsarn:aws:states:us-east-1:000000000000:stateMachine:name
EventBridgearn:aws:events:us-east-1:000000000000:rule/name
Kinesisarn:aws:kinesis:us-east-1:000000000000:stream/name
API Gatewayarn:aws:apigateway:us-east-1::/restapis/id

Example: Create User, Attach Policy, Verify

Step 1: Create an IAM user with access keys

Terminal
$ aws --endpoint-url=http://localhost:4566 iam create-user --user-name dev
$ aws --endpoint-url=http://localhost:4566 iam create-access-key --user-name dev

AccessKeyId: AKIA_DEV_KEY
SecretAccessKey: dev_secret_key

Step 2: Attach an inline policy allowing S3 read access

Terminal
$ aws --endpoint-url=http://localhost:4566 iam put-user-policy \
    --user-name dev \
    --policy-name s3-read \
    --policy-document '{
  "Version": "2012-10-17",
  "Statement": [{
    "Effect": "Allow",
    "Action": ["s3:GetObject", "s3:ListBucket"],
    "Resource": [
      "arn:aws:s3:::my-bucket",
      "arn:aws:s3:::my-bucket/*"
    ]
  }]
}'

Step 3: List objects succeeds (s3:ListBucket is allowed)

Terminal
$ AWS_ACCESS_KEY_ID=AKIA_DEV_KEY \
  AWS_SECRET_ACCESS_KEY=dev_secret_key \
  aws --endpoint-url=http://localhost:4566 s3 ls s3://my-bucket/

2026-04-10 12:00:00  1024 file.txt

Step 4: Delete object fails (s3:DeleteObject is not in the policy)

Terminal
$ AWS_ACCESS_KEY_ID=AKIA_DEV_KEY \
  AWS_SECRET_ACCESS_KEY=dev_secret_key \
  aws --endpoint-url=http://localhost:4566 s3 rm s3://my-bucket/file.txt

An error occurred (AccessDenied): User: arn:aws:iam::000000000000:user/dev
is not authorized to perform: s3:DeleteObject on resource:
arn:aws:s3:::my-bucket/file.txt

Resource-Based Policies

Six services support resource-based policies: S3, SQS, SNS, KMS, Lambda, and EventBridge. These are evaluated alongside identity-based policies during the enforcement check.

Terminal
# S3 bucket policy allowing cross-account access
$ aws --endpoint-url=http://localhost:4566 s3api put-bucket-policy \
    --bucket shared-data \
    --policy '{
  "Version": "2012-10-17",
  "Statement": [{
    "Effect": "Allow",
    "Principal": {"AWS": "arn:aws:iam::000000000000:user/reader"},
    "Action": "s3:GetObject",
    "Resource": "arn:aws:s3:::shared-data/*"
  }]
}'