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

@@ -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);