From 5f75b7dff07b754b766417a0d1245df120fc9092 Mon Sep 17 00:00:00 2001 From: zgy <101915083+bfs2021@users.noreply.github.com> Date: Wed, 21 Oct 2026 12:17:19 +0800 Subject: [PATCH] fix(sts): issue GetSessionToken without IAM permissions (#6051) AWS's GetSessionToken reference says no permissions are required for the call and that policies cannot control authentication operations. IAM enforcement evaluated it like any other action, so an explicit deny, or simply no allow, answered AccessDenied where AWS mints credentials. Exempt sts:GetSessionToken alongside sts:GetCallerIdentity. The request still needs valid, active, unexpired credentials, and the handler still refuses temporary callers. Other STS actions stay policy-decided. Fixes #6041 --- .../core/common/IamEnforcementFilter.java | 7 ++++ ...ationCallerEnforcementIntegrationTest.java | 34 +++++++++++++++++-- 2 files changed, 39 insertions(+), 2 deletions(-) diff --git a/src/main/java/io/github/hectorvent/floci/core/common/IamEnforcementFilter.java b/src/main/java/io/github/hectorvent/floci/core/common/IamEnforcementFilter.java index 1531304c65..fccaf84bc7 100644 --- a/src/main/java/io/github/hectorvent/floci/core/common/IamEnforcementFilter.java +++ b/src/main/java/io/github/hectorvent/floci/core/common/IamEnforcementFilter.java @@ -67,6 +67,8 @@ import java.util.regex.Pattern; *
  • The action cannot be resolved (unknown mapping → permissive)
  • *
  • The action is {@code sts:GetCallerIdentity}, which AWS allows without permissions. The * key itself is still checked.
  • + *
  • The action is {@code sts:GetSessionToken}, which AWS also allows without permissions: + * policies cannot control authentication operations. The key itself is still checked.
  • * * *

    Authenticated temporary callers of {@code sts:GetFederationToken} are refused here with @@ -383,6 +385,11 @@ public class IamEnforcementFilter implements ContainerRequestFilter { if ("sts:GetCallerIdentity".equals(action)) { return; // AWS returns caller identity even when an identity policy explicitly denies it } + if ("sts:GetSessionToken".equals(action)) { + // AWS: "No permissions are required for users to perform this operation... You cannot + // use policies to control authentication operations." An explicit deny does not stop it. + return; + } if ("sts:GetFederationToken".equals(action) && IamService.isTemporaryAccessKey(akid)) { ctx.abortWith(queryXmlAccessDenied(IamService.FEDERATION_TOKEN_SESSION_MESSAGE)); diff --git a/src/test/java/io/github/hectorvent/floci/services/iam/StsFederationCallerEnforcementIntegrationTest.java b/src/test/java/io/github/hectorvent/floci/services/iam/StsFederationCallerEnforcementIntegrationTest.java index 603f80d0e8..15def3a5de 100644 --- a/src/test/java/io/github/hectorvent/floci/services/iam/StsFederationCallerEnforcementIntegrationTest.java +++ b/src/test/java/io/github/hectorvent/floci/services/iam/StsFederationCallerEnforcementIntegrationTest.java @@ -36,6 +36,11 @@ class StsFederationCallerEnforcementIntegrationTest { private static final String ACCOUNT = "000000000000"; private static final String ALLOW_STS = "{\"Version\":\"2012-10-17\",\"Statement\":[" + "{\"Effect\":\"Allow\",\"Action\":\"sts:*\",\"Resource\":\"*\"}]}"; + private static final String DENY_SESSION_TOKEN = "{\"Version\":\"2012-10-17\",\"Statement\":[" + + "{\"Effect\":\"Deny\",\"Action\":\"sts:GetSessionToken\",\"Resource\":\"*\"}]}"; + private static final String ALLOW_STS_DENY_FEDERATION_TOKEN = "{\"Version\":\"2012-10-17\",\"Statement\":[" + + "{\"Effect\":\"Allow\",\"Action\":\"sts:*\",\"Resource\":\"*\"}," + + "{\"Effect\":\"Deny\",\"Action\":\"sts:GetFederationToken\",\"Resource\":\"*\"}]}"; @Inject IamService iam; @RegisterExtension final PartitionCleanup cleanup = new PartitionCleanup(); @@ -90,6 +95,27 @@ class StsFederationCallerEnforcementIntegrationTest { } } + @Test + void getSessionTokenIsIssuedEvenWhenAPolicyExplicitlyDeniesIt() throws Exception { + Credentials user = userWithPolicy(DENY_SESSION_TOKEN); + remember(request(user, "GetSessionToken", Map.of()), "GetSessionToken"); + } + + @Test + void getSessionTokenIsIssuedWithoutAPolicyThatAllowsIt() throws Exception { + Credentials user = user(false); + remember(request(user, "GetSessionToken", Map.of()), "GetSessionToken"); + } + + @Test + void otherStsActionsStayDecidedByPolicies() throws Exception { + Credentials user = userWithPolicy(ALLOW_STS_DENY_FEDERATION_TOKEN); + request(user, "GetFederationToken", Map.of("Name", "still-denied")).then().statusCode(403) + .body("ErrorResponse.Error.Code", equalTo("AccessDenied")) + .body("ErrorResponse.Error.Message", + equalTo("User is not authorized to perform: sts:GetFederationToken")); + } + @Test void federationSessionKeepsOtherIamAndStsRestrictions() throws Exception { Credentials issued = issue("GetFederationToken"); @@ -118,13 +144,17 @@ class StsFederationCallerEnforcementIntegrationTest { } private Credentials user(boolean allowed) { + return userWithPolicy(allowed ? ALLOW_STS : null); + } + + private Credentials userWithPolicy(String policyDocument) { String name = "fed-enforced-" + UUID.randomUUID(); iam.createUser(name, "/"); cleanup.register(() -> iam.deleteUser(name)); AccessKey key = iam.createAccessKey(name); cleanup.register(() -> iam.deleteAccessKey(name, key.getAccessKeyId())); - if (allowed) { - iam.putUserPolicy(name, "sts", ALLOW_STS); + if (policyDocument != null) { + iam.putUserPolicy(name, "sts", policyDocument); cleanup.register(() -> iam.deleteUserPolicy(name, "sts")); } return new Credentials(key.getAccessKeyId(), key.getSecretAccessKey(), null);