fix(iam): enforce STS session policies (#1636)

* test(iam): expose STS session policy S3 deny gap

* fix(iam): enforce STS session policies

## Summary

STS session policies were recorded on temporary credentials but IAM enforcement evaluated only the caller's identity policies. As a result, an assumed role with broad role permissions could still perform an action even when the inline `AssumeRole` session policy should have denied or narrowed it.

This changes enforcement to evaluate the full caller context, including identity policies, session policies, and permission boundaries. It also keeps temporary-credential lookup account-independent so assumed-role sessions can be resolved after account routing moves the request into the role account, and it uses the resolved request account when building resource ARNs for policy evaluation.

## Type of change

- [x] Bug fix (`fix:`)

## AWS Compatibility

Incorrect behavior: STS `AssumeRole` accepted the standard inline `Policy` parameter, but later requests signed with those temporary credentials did not have that session policy applied by IAM enforcement.

The fix matches AWS policy evaluation semantics: explicit denies in session policies participate in the deny pass, and a present session policy must also explicitly allow the request for the role's permissions to be effective. This preserves the existing Floci bypass behavior for unknown local credentials and the `test` root credential.

## What changed

- `IamEnforcementFilter` resolves a `CallerContext` and evaluates the complete IAM context instead of identity-policy documents only.
- `IamService` resolves STS sessions across account namespaces for caller context, caller ARN, account routing, and temporary secret lookup.
- Enforcement resource ARN construction uses the request account already resolved by `AccountContextFilter`, so assumed-role credentials evaluate account-scoped resources against the role account.
- IAM and multi-account docs now describe session-policy intersection and temporary-credential resolution accurately.
- Java SDK compatibility coverage now checks that an assumed-role session policy deny overrides a role allow.

## Checklist

- [x] `./mvnw test` passes locally - attempted; only failures were unrelated LambdaReactiveSyncIntegrationTest container startup Broken pipe errors
- [x] Selected Java SDK compatibility tests pass locally - in `compatibility-tests/sdk-test-java`: `mvn -q -Dtest=IamEnforcementTest,IamTest,StsTest,S3Test test`
- [x] New or updated integration test added
- [x] Commit messages follow Conventional Commits

* fix(iam): tighten cross-account session lookup
This commit is contained in:
Robert Stupp authored and GitHub committed 2026-07-02 23:29:23 -05:00
1 parent 3304184bd3
commit 4f4e7be90e
8 files changed
+372 -23

No files matched your search

@@ -30,6 +30,7 @@ import static org.assertj.core.api.Assertions.*;
* <li>Wildcard action policy grants access → ALLOW</li>
* <li>Assumed role with no policies → DENY</li>
* <li>Assumed role with attached allow policy → ALLOW</li>
* <li>Assumed role session policy deny overrides role allow → DENY</li>
* </ul>
*/
@DisplayName("IAM Enforcement Mode")
@@ -63,6 +64,12 @@ class IamEnforcementTest {
{"Effect":"Allow","Action":"s3:*","Resource":"*"}
]}""";
private static final String DENY_S3_LIST_SESSION_POLICY = """
{"Version":"2012-10-17","Statement":[
{"Effect":"Allow","Action":"s3:ListAllMyBuckets","Resource":"*"},
{"Effect":"Deny","Action":"s3:ListAllMyBuckets","Resource":"*"}
]}""";
// ── Shared state ───────────────────────────────────────────────────────────
private static IamClient iam;
private static StsClient sts;
@@ -293,4 +300,30 @@ class IamEnforcementTest {
assertThatCode(s3::listBuckets).doesNotThrowAnyException();
}
}
@Test
@Order(7)
@DisplayName("assumed role session policy deny overrides role allow")
void assumedRoleSessionPolicyDenyOverridesRoleAllow() {
assumeEnforcementEnabled();
iam.attachRolePolicy(AttachRolePolicyRequest.builder()
.roleName(ROLE).policyArn(allowPolicyArn).build());
AssumeRoleResponse assumed = sts.assumeRole(AssumeRoleRequest.builder()
.roleArn(roleArn)
.roleSessionName("enf-test-session-deny")
.policy(DENY_S3_LIST_SESSION_POLICY)
.build());
try (S3Client s3 = s3WithSessionCredentials(
assumed.credentials().accessKeyId(),
assumed.credentials().secretAccessKey(),
assumed.credentials().sessionToken())) {
assertThatThrownBy(s3::listBuckets)
.isInstanceOf(S3Exception.class)
.extracting(e -> ((S3Exception) e).statusCode())
.isEqualTo(403);
}
}
}