fix(sts): give AssumeRole's identity-based policies the sts:RoleSessionName and sts:ExternalId keys (#8922)

With IAM enforcement on, the caller's identity-based policy, permissions boundary, session
policy and SCPs were evaluated for sts:AssumeRole without the request's sts:RoleSessionName
and sts:ExternalId, which the role's trust policy already sees, so a condition on either never
matched. The Service Authorization Reference lists both among the condition keys of
AssumeRole. STS now joins the generated request condition key table, which reads them from the
AssumeRole form; an AssumeRole without ExternalId names no sts:ExternalId. AssumeRoleWithSAML
carries no session name member, so it is listed as not reading it from the request.

sts:SourceIdentity, sts:TransitiveTagKeys and the session tag keys are not read: Floci does not
model source identity or session tags, as the STS page already says.

Closes #8921
This commit is contained in:
Jeremy Chapeau authored and GitHub committed 2026-11-19 17:17:17 -04:00
1 parent 76f9481bb1
commit 3a9f529158
8 files changed
+200 -3

No files matched your search

+1 -1
View File
@@ -930,7 +930,7 @@ s3control-tag-condition-keys-verify: ## Check the S3 Control tag condition actio
$(PYTHON) tools/aws/regen_s3control_tag_condition_keys.py --verify
.PHONY: request-condition-keys-sync request-condition-keys-check request-condition-keys-verify
request-condition-keys-sync: ## Regenerate the Lambda Web, Redshift and Route 53 request condition keys from AWS and botocore
request-condition-keys-sync: ## Regenerate the Lambda Web, Redshift, Route 53 and STS request condition keys from AWS and botocore
$(PYTHON) tools/aws/regen_request_condition_keys.py
request-condition-keys-check: ## Check the request condition key members against pinned botocore
$(PYTHON) tools/aws/regen_request_condition_keys.py --check
+7
View File
@@ -3745,6 +3745,13 @@ floci populates:
given a JSON null is absent, never the cluster's stored value. The actions, members and protocol come from
the same `request-condition-keys.json`. A boolean member given anything but a boolean or its text is refused
before it is read (see [EKS](eks.md)), so the key never misses a value the cluster takes.
- `sts:RoleSessionName` and `sts:ExternalId`: the `RoleSessionName` and `ExternalId` an `AssumeRole` request
passes, as given, for the caller's identity-based policies, permissions boundary, session policy and SCPs, as
the role's trust policy reads them (see [STS](sts.md)); `sts:ExternalId` is absent when the request passes none.
The actions and request members come from the same `request-condition-keys.json`.
`AssumeRoleWithWebIdentity` and `AssumeRoleWithSAML` are not signed, so no identity-based policy is
evaluated for them. `sts:SourceIdentity`, `sts:TransitiveTagKeys`, `aws:RequestTag/<key>` and `aws:TagKeys`
are not populated for `AssumeRole`: Floci does not model source identity or session tags.
**Any other condition key is absent from the request context.** A positive scalar operator
without `IfExists` on an absent key makes the whole statement *not apply*: it neither matches nor
+5
View File
@@ -394,6 +394,11 @@ forms are matched: `"*"`, an account id, an account-root ARN (`arn:aws:iam::<acc
and an explicit `Deny` always wins. Both `Action` and `NotAction` elements are honored when matching `sts:AssumeRole`.
The caller's own identity policy must allow `sts:AssumeRole` too, evaluated against the role's ARN, so a policy can
allow assuming one role and not another. Other STS actions are evaluated against `*`, whatever `RoleArn` they carry.
That evaluation sees the request's `sts:RoleSessionName`, and `sts:ExternalId` when the caller passes `ExternalId`,
as the trust policy does: the [Service Authorization Reference](https://docs.aws.amazon.com/service-authorization/latest/reference/list_awssecuritytokenservice.html)
lists both among the condition keys of `AssumeRole`, so an identity policy can require a session name, such as
`"sts:RoleSessionName": "${aws:username}"`, or an external ID, and a `Deny` conditioned on either applies only when
it matches.
The caller is the account that owns the request's credentials, whether they sign the
`Authorization` header or a presigned query string: an IAM user's or a role session's access key
@@ -51,6 +51,16 @@
"route53:ChangeResourceRecordSetsActions",
"route53:ChangeResourceRecordSetsNormalizedRecordNames",
"route53:ChangeResourceRecordSetsRecordTypes"
],
"sts:AssumeRole": [
"sts:ExternalId",
"sts:RoleSessionName"
],
"sts:AssumeRoleWithSAML": [
"sts:RoleSessionName"
],
"sts:AssumeRoleWithWebIdentity": [
"sts:RoleSessionName"
]
},
"members": {
@@ -120,6 +130,19 @@
"route53:ChangeResourceRecordSetsRecordTypes": [
"ChangeBatch.Changes.Change.ResourceRecordSet.Type"
]
},
"sts:AssumeRole": {
"sts:ExternalId": [
"ExternalId"
],
"sts:RoleSessionName": [
"RoleSessionName"
]
},
"sts:AssumeRoleWithWebIdentity": {
"sts:RoleSessionName": [
"RoleSessionName"
]
}
},
"memberShapes": {
@@ -150,12 +173,20 @@
"ChangeBatch.Changes.Change.Action": "ChangeAction",
"ChangeBatch.Changes.Change.ResourceRecordSet.Name": "DNSName",
"ChangeBatch.Changes.Change.ResourceRecordSet.Type": "RRType"
},
"sts:AssumeRole": {
"ExternalId": "externalIdType",
"RoleSessionName": "roleSessionNameType"
},
"sts:AssumeRoleWithWebIdentity": {
"RoleSessionName": "roleSessionNameType"
}
},
"protocols": {
"eks": "rest-json",
"lambda": "rest-json",
"redshift": "query",
"route53": "rest-xml"
"route53": "rest-xml",
"sts": "query"
}
}
@@ -236,6 +236,17 @@ class IamConditionContextResolverTest {
formRequest("Action=GetClusterCredentials")));
}
@Test
void anAssumeRoleRequestCarriesItsSessionNameAndExternalId() {
assertEquals(Map.of("sts:RoleSessionName", List.of("alice"), "sts:ExternalId", List.of("partner-42")),
resolver.resolve("sts", "sts:AssumeRole", formRequest(
"Action=AssumeRole&RoleArn=arn%3Aaws%3Aiam%3A%3A111111111111%3Arole%2Fr"
+ "&RoleSessionName=alice&ExternalId=partner-42")));
assertEquals(Map.of("sts:RoleSessionName", List.of("alice")), resolver.resolve("sts", "sts:AssumeRole",
formRequest("Action=AssumeRole&RoleSessionName=alice")), "no ExternalId, no sts:ExternalId");
assertNull(resolver.resolve("sts", "sts:GetCallerIdentity", formRequest("Action=GetCallerIdentity")));
}
@Test
void logStreamTagsUseRawParentNameAndRequestRegion() throws Exception {
ContainerRequestContext request = mock(ContainerRequestContext.class);
@@ -0,0 +1,118 @@
package io.floci.aws.services.iam;
import io.floci.aws.testing.EnforcementFixtures;
import io.floci.aws.testing.EnforcementFixtures.UserCredentials;
import io.floci.aws.testing.IamEnforcementProfile;
import io.floci.aws.testing.PartitionCleanup;
import io.quarkus.test.common.http.TestHTTPResource;
import io.quarkus.test.junit.QuarkusTest;
import io.quarkus.test.junit.TestProfile;
import io.restassured.response.Response;
import io.restassured.specification.RequestSpecification;
import org.junit.jupiter.api.Test;
import org.junit.jupiter.api.extension.RegisterExtension;
import java.net.URI;
import java.util.UUID;
import static io.floci.aws.testing.EnforcementFixtures.auth;
import static io.restassured.RestAssured.given;
/**
* With {@code iam.enforcement-enabled=true}, the caller's identity policy for {@code sts:AssumeRole}
* is evaluated with the {@code sts:RoleSessionName} and {@code sts:ExternalId} the request carries,
* which the Service Authorization Reference lists among the condition keys of {@code AssumeRole}.
* Every role here trusts its account, so the identity policy decides.
*/
@QuarkusTest
@TestProfile(IamEnforcementProfile.class)
class StsAssumeRoleIdentityConditionKeysIntegrationTest {
private static final String ACCOUNT = "111111111111";
@TestHTTPResource
URI baseUri;
@RegisterExtension
final PartitionCleanup cleanup = new PartitionCleanup();
@Test
void anIdentityPolicyRequiringAnExternalIdAllowsOnlyThatExternalId() {
String suffix = UUID.randomUUID().toString().substring(0, 8);
String roleArn = createRole("external-id-" + suffix);
UserCredentials caller = callerWithPolicy("external-id-caller-" + suffix, """
{"Version":"2012-10-17","Statement":[
{"Effect":"Allow","Action":"sts:AssumeRole","Resource":"%s",
"Condition":{"StringEquals":{"sts:ExternalId":"partner-42"}}}]}""".formatted(roleArn));
assumeRole(caller, roleArn, "s1", "partner-42").then().statusCode(200);
assumeRole(caller, roleArn, "s2", "partner-43").then().statusCode(403);
assumeRole(caller, roleArn, "s3", null).then().statusCode(403);
}
@Test
void anIdentityPolicyRequiringTheUserNameAsSessionNameAllowsOnlyThatName() {
String suffix = UUID.randomUUID().toString().substring(0, 8);
String roleArn = createRole("session-name-" + suffix);
String user = "session-caller-" + suffix;
UserCredentials caller = callerWithPolicy(user, """
{"Version":"2012-10-17","Statement":[
{"Effect":"Allow","Action":"sts:AssumeRole","Resource":"%s",
"Condition":{"StringEquals":{"sts:RoleSessionName":"${aws:username}"}}}]}""".formatted(roleArn));
assumeRole(caller, roleArn, user, null).then().statusCode(200);
assumeRole(caller, roleArn, "someone-else", null).then().statusCode(403);
}
@Test
void aDenyOnASessionNamePatternRefusesOnlyThoseNames() {
String suffix = UUID.randomUUID().toString().substring(0, 8);
String roleArn = createRole("session-deny-" + suffix);
UserCredentials caller = callerWithPolicy("session-deny-caller-" + suffix, """
{"Version":"2012-10-17","Statement":[
{"Effect":"Allow","Action":"sts:AssumeRole","Resource":"%s"},
{"Effect":"Deny","Action":"sts:AssumeRole","Resource":"*",
"Condition":{"StringLike":{"sts:RoleSessionName":"admin-*"}}}]}""".formatted(roleArn));
assumeRole(caller, roleArn, "admin-1", null).then().statusCode(403);
assumeRole(caller, roleArn, "batch-1", null).then().statusCode(200);
}
@Test
void anIdentityPolicyWithoutConditionAllowsWithOrWithoutAnExternalId() {
String suffix = UUID.randomUUID().toString().substring(0, 8);
String roleArn = createRole("no-condition-" + suffix);
UserCredentials caller = callerWithPolicy("no-condition-caller-" + suffix, """
{"Version":"2012-10-17","Statement":[
{"Effect":"Allow","Action":"sts:AssumeRole","Resource":"%s"}]}""".formatted(roleArn));
assumeRole(caller, roleArn, "s1", null).then().statusCode(200);
assumeRole(caller, roleArn, "s2", "partner-42").then().statusCode(200);
}
private UserCredentials callerWithPolicy(String user, String policy) {
String iamAuth = auth(ACCOUNT, "iam");
UserCredentials caller = EnforcementFixtures.createUser(cleanup, baseUri.getPort(), iamAuth, user);
EnforcementFixtures.putUserPolicy(baseUri.getPort(), iamAuth, user, "assume", policy);
return caller;
}
private String createRole(String role) {
return EnforcementFixtures.createRole(cleanup, baseUri.getPort(), ACCOUNT, "/", role, """
{"Version":"2012-10-17","Statement":[
{"Effect":"Allow","Action":"iam:ListUsers","Resource":"*"}]}""");
}
private Response assumeRole(UserCredentials caller, String roleArn, String sessionName, String externalId) {
RequestSpecification request = given().port(baseUri.getPort())
.contentType("application/x-www-form-urlencoded")
.header("Authorization", auth(caller.accessKeyId(), "sts"))
.formParam("Action", "AssumeRole")
.formParam("RoleArn", roleArn)
.formParam("RoleSessionName", sessionName);
if (externalId != null) {
request = request.formParam("ExternalId", externalId);
}
return request.when().post("/");
}
}
+15
View File
@@ -22,6 +22,12 @@ it. `SERVICES` names, for each namespace, the keys read and where:
name as `route53:ChangeResourceRecordSetsActions`, `...RecordTypes` and `...NormalizedRecordNames`. The names
are read as `DNSName` members, which Route 53 spells as AWS normalizes them for the key, through the spelling
the service registers for that shape.
- `sts`: an AssumeRole request is checked with the session name and external ID it passes as
`sts:RoleSessionName` and `sts:ExternalId`, so the caller's identity-based policy can require them as a
trust policy can; an AssumeRole without `ExternalId` names none. AssumeRoleWithWebIdentity carries
`RoleSessionName` too, but is not signed, so no identity-based policy is evaluated for it.
`sts:SourceIdentity`, `sts:TransitiveTagKeys` and the session tags are not read: Floci does not model source
identity or session tags.
The table comes from two sources:
@@ -118,6 +124,15 @@ SERVICES = {
"stored": (),
"not_in_request": {},
},
"sts": {
"model": "sts",
"request": {"sts:ExternalId": "ExternalId", "sts:RoleSessionName": "RoleSessionName"},
"stored": (),
"not_in_request": {
("sts:AssumeRoleWithSAML", "sts:RoleSessionName"): "the session name is the assertion's RoleSessionName "
"attribute, not a request member",
},
},
}
+11 -1
View File
@@ -133,7 +133,7 @@ def test_the_vendored_table_covers_its_namespaces():
assert document["memberShapes"]["route53:ChangeResourceRecordSets"][
"ChangeBatch.Changes.Change.ResourceRecordSet.Name"] == "DNSName"
assert document["protocols"] == {"eks": "rest-json", "lambda": "rest-json",
"redshift": "query", "route53": "rest-xml"}
"redshift": "query", "route53": "rest-xml", "sts": "query"}
@pytest.mark.parametrize("changed", [
@@ -197,3 +197,13 @@ def test_eks_cluster_request_members_and_create_only_bootstrap_key():
key: paths for key, paths in create.items() if key != "eks:bootstrapClusterCreatorAdminPermissions"
}
assert "eks:DescribeCluster" not in document["actions"]
def test_assume_role_reads_its_session_name_and_external_id():
document = json.loads(OUTPUT.read_text())
assert document["members"]["sts:AssumeRole"] == {
"sts:ExternalId": ["ExternalId"], "sts:RoleSessionName": ["RoleSessionName"]}
assert document["members"]["sts:AssumeRoleWithWebIdentity"] == {"sts:RoleSessionName": ["RoleSessionName"]}
assert document["actions"]["sts:AssumeRoleWithSAML"] == ["sts:RoleSessionName"]
assert "sts:AssumeRoleWithSAML" not in document["members"]
assert "sts:GetCallerIdentity" not in document["actions"]