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
This commit is contained in:
zgy authored and GitHub committed 2026-10-21 00:17:19 -04:00
1 parent 883cd4f1c2
commit 5f75b7dff0
2 files changed
+39 -2

No files matched your search

@@ -67,6 +67,8 @@ import java.util.regex.Pattern;
* <li>The action cannot be resolved (unknown mapping → permissive)</li>
* <li>The action is {@code sts:GetCallerIdentity}, which AWS allows without permissions. The
* key itself is still checked.</li>
* <li>The action is {@code sts:GetSessionToken}, which AWS also allows without permissions:
* policies cannot control authentication operations. The key itself is still checked.</li>
* </ul>
*
* <p>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));
@@ -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);