mirror of
https://github.com/floci-io/floci.git
synced 2026-12-01 01:12:48 -05:00
feat(sts): read every modelled operation's constraints from the model (#6925)
The seven operations that still answered an absent member from a check of their own are read against the vendored shapes now, which leaves every STS operation that models a member reading its constraints from the model: `AssumeRole`, `AssumeRoleWithSAML`, `AssumeRoleWithWebIdentity`, `AssumeRoot`, `DecodeAuthorizationMessage`, `GetDelegatedAccessToken` and `GetFederationToken`. `GetCallerIdentity` carries no member, so there is nothing to read for it. Two answers move, both onto the form the model and the rest of this package give. A member the request leaves out is named as a constraint message spells it, `roleSessionName` rather than `RoleSessionName`, and every absent member is reported together in the order the model lists them, where the check it replaces answered the first it found. A member sent empty is a value the request carries, so it breaks its own minimum length rather than reading as absent. That is the reading #6811 settled for the two services and what `validateRequired` was the last of in this handler. What the seven gain is every bound beside the required members, none of which was read at all: `RoleArn` at 20 to 2048 characters, `RoleSessionName` at 2 to 64, `ExternalId`, `SourceIdentity`, `SerialNumber`, `TokenCode`, `Policy`, `PolicyArns`, `Tags`, `TransitiveTagKeys` and `ProvidedContexts` on `AssumeRole`, `SAMLAssertion` at 4 to 100000, `WebIdentityToken` at 4 to 20000, `ProviderId` at 4 to 2048, `Name` at 2 to 32, `EncodedMessage` at 1 to 10240, and the `DurationSeconds` and `MinimumSessionTokenSize` ranges each operation declares. `AssumeRoot`'s own length check on `TargetPrincipal` said what the model says, so it comes off with the rest. One reading is this emulator's own, and `docs/services/sts.md` says so. `TradeInToken` is required and declares no length, so a request sending it empty carries a value: it reaches the lookup and is answered `ExpiredTradeInTokenException`, the refusal any token that cannot be redeemed gets, where the check it replaces called it absent. Nothing published says what AWS answers an empty trade-in token. Each operation keeps the refusals it answers ahead of the constraints: `GetFederationToken` and `GetSessionToken` turn away session credentials first, and `AssumeRoot` refuses the global endpoint first. Three test fixtures carried values AWS refuses and now carry values it takes. A `RoleSessionName` of `s` is one character where the model declares two, and a `WebIdentityToken` of `jwt` three where it declares four, so the fixtures that sent them are a character longer, as are the two assertions that read a session name back out of an assumed-role ARN and a condition key. The name the shared role-session fixture opens under has one writer now, `EnforcementFixtures.SESSION_NAME`, read by every test asserting on that session rather than spelled again in each: an `aws:userid` condition, a `PrincipalArn` condition, two authorization-denial messages and the ARN two trust-policy cases read back. Each of those carried the one-character name, which is a 403 where the case wants a 200, or a prefix match that no longer pins the whole ARN.
This commit is contained in:
1 parent
c9bc1e7cb8
commit
34269655ba
15 files changed
+493
-161
No files matched your search
+4
-2
@@ -56,7 +56,8 @@ class PassedNetworkConnectorsIntegrationTest {
|
||||
String roleArn = EnforcementFixtures.createRole(cleanup, port, ACCOUNT, "/", name,
|
||||
policy("lambda:CreateWebFunctionRevision", ""));
|
||||
Session session = EnforcementFixtures.assumeRole(port, ACCOUNT, roleArn);
|
||||
String denied = "User: arn:aws:sts::" + ACCOUNT + ":assumed-role/" + name + "/s is not authorized to perform:"
|
||||
String denied = "User: arn:aws:sts::" + ACCOUNT + ":assumed-role/" + name + "/"
|
||||
+ EnforcementFixtures.SESSION_NAME + " is not authorized to perform:"
|
||||
+ " lambda:PassNetworkConnector on resource: " + CONNECTOR + ":1 ";
|
||||
|
||||
revision(session, CONNECTOR + ":1").statusCode(403)
|
||||
@@ -105,7 +106,8 @@ class PassedNetworkConnectorsIntegrationTest {
|
||||
String roleArn = EnforcementFixtures.createRole(cleanup, port, ACCOUNT, "/", name,
|
||||
policy("lambda:RunMicrovm", ""));
|
||||
Session session = EnforcementFixtures.assumeRole(port, ACCOUNT, roleArn);
|
||||
String denied = "User: arn:aws:sts::" + ACCOUNT + ":assumed-role/" + name + "/s is not authorized to perform:"
|
||||
String denied = "User: arn:aws:sts::" + ACCOUNT + ":assumed-role/" + name + "/"
|
||||
+ EnforcementFixtures.SESSION_NAME + " is not authorized to perform:"
|
||||
+ " lambda:PassNetworkConnector on resource: ";
|
||||
String noAllow = " because no identity-based policy allows the lambda:PassNetworkConnector action";
|
||||
|
||||
|
||||
+20
-20
@@ -53,9 +53,9 @@ class AssumeRoleTrustConditionsIntegrationTest {
|
||||
"Principal":{"AWS":"arn:aws:iam::%s:root"},"Action":"sts:AssumeRole",
|
||||
"Condition":{"StringEquals":{"sts:ExternalId":"expected-id"}}}]}""".formatted(TRUSTED_ACCOUNT));
|
||||
|
||||
assertTrustDenied(assumeRole(TRUSTED_ACCOUNT, role, "s", null), role);
|
||||
assertTrustDenied(assumeRole(TRUSTED_ACCOUNT, role, "s", "other-id"), role);
|
||||
assumeRole(TRUSTED_ACCOUNT, role, "s", "expected-id").then().statusCode(200);
|
||||
assertTrustDenied(assumeRole(TRUSTED_ACCOUNT, role, "sx", null), role);
|
||||
assertTrustDenied(assumeRole(TRUSTED_ACCOUNT, role, "sx", "other-id"), role);
|
||||
assumeRole(TRUSTED_ACCOUNT, role, "sx", "expected-id").then().statusCode(200);
|
||||
}
|
||||
|
||||
@Test
|
||||
@@ -66,9 +66,9 @@ class AssumeRoleTrustConditionsIntegrationTest {
|
||||
{"Effect":"Deny","Principal":{"AWS":"arn:aws:iam::%1$s:root"},"Action":"sts:AssumeRole",
|
||||
"Condition":{"StringNotEquals":{"sts:ExternalId":"expected-id"}}}]}""".formatted(TRUSTED_ACCOUNT));
|
||||
|
||||
assertTrustDenied(assumeRole(TRUSTED_ACCOUNT, role, "s", null), role);
|
||||
assertTrustDenied(assumeRole(TRUSTED_ACCOUNT, role, "s", "other-id"), role);
|
||||
assumeRole(TRUSTED_ACCOUNT, role, "s", "expected-id").then().statusCode(200);
|
||||
assertTrustDenied(assumeRole(TRUSTED_ACCOUNT, role, "sx", null), role);
|
||||
assertTrustDenied(assumeRole(TRUSTED_ACCOUNT, role, "sx", "other-id"), role);
|
||||
assumeRole(TRUSTED_ACCOUNT, role, "sx", "expected-id").then().statusCode(200);
|
||||
}
|
||||
|
||||
@Test
|
||||
@@ -98,8 +98,8 @@ class AssumeRoleTrustConditionsIntegrationTest {
|
||||
String trustsDefault = createRole(trustAccountRoot(DEFAULT_ACCOUNT));
|
||||
String trustsOwnAccount = createRole(trustAccountRoot(OTHER_ACCOUNT));
|
||||
|
||||
assertTrustDenied(assumeRole(accessKeyId, trustsDefault, "s", null), trustsDefault);
|
||||
assumeRole(accessKeyId, trustsOwnAccount, "s", null).then().statusCode(200);
|
||||
assertTrustDenied(assumeRole(accessKeyId, trustsDefault, "sx", null), trustsDefault);
|
||||
assumeRole(accessKeyId, trustsOwnAccount, "sx", null).then().statusCode(200);
|
||||
}
|
||||
|
||||
@Test
|
||||
@@ -112,8 +112,8 @@ class AssumeRoleTrustConditionsIntegrationTest {
|
||||
String namesSomeoneElse = createRole(trustWithCondition(ownerRoot,
|
||||
"{\"StringEquals\":{\"aws:username\":\"someone-else\"}}"));
|
||||
|
||||
assumeRole(accessKeyId, namesTheCaller, "s", null).then().statusCode(200);
|
||||
assertTrustDenied(assumeRole(accessKeyId, namesSomeoneElse, "s", null), namesSomeoneElse);
|
||||
assumeRole(accessKeyId, namesTheCaller, "sx", null).then().statusCode(200);
|
||||
assertTrustDenied(assumeRole(accessKeyId, namesSomeoneElse, "sx", null), namesSomeoneElse);
|
||||
}
|
||||
|
||||
@Test
|
||||
@@ -127,10 +127,10 @@ class AssumeRoleTrustConditionsIntegrationTest {
|
||||
String onlySessions = createRole(trustWithCondition("*",
|
||||
"{\"StringEquals\":{\"aws:PrincipalType\":\"AssumedRole\"}}"));
|
||||
|
||||
assumeRole(accessKeyId, onlyUsers, "s", null).then().statusCode(200);
|
||||
assumeRole(accessKeyId, onlyUsers, "sx", null).then().statusCode(200);
|
||||
assertTrustDenied(assumeRoleWithSession(session, onlyUsers), onlyUsers);
|
||||
assumeRoleWithSession(session, onlySessions).then().statusCode(200);
|
||||
assertTrustDenied(assumeRole(accessKeyId, onlySessions, "s", null), onlySessions);
|
||||
assertTrustDenied(assumeRole(accessKeyId, onlySessions, "sx", null), onlySessions);
|
||||
}
|
||||
|
||||
@Test
|
||||
@@ -139,8 +139,8 @@ class AssumeRoleTrustConditionsIntegrationTest {
|
||||
String onlyTheRoot = createRole(trustWithCondition("*",
|
||||
"{\"StringEquals\":{\"aws:PrincipalType\":\"Account\",\"aws:userid\":\"" + TRUSTED_ACCOUNT + "\"}}"));
|
||||
|
||||
assumeRole(TRUSTED_ACCOUNT, onlyTheRoot, "s", null).then().statusCode(200);
|
||||
assertTrustDenied(assumeRole(accessKeyId, onlyTheRoot, "s", null), onlyTheRoot);
|
||||
assumeRole(TRUSTED_ACCOUNT, onlyTheRoot, "sx", null).then().statusCode(200);
|
||||
assertTrustDenied(assumeRole(accessKeyId, onlyTheRoot, "sx", null), onlyTheRoot);
|
||||
}
|
||||
|
||||
@Test
|
||||
@@ -150,14 +150,14 @@ class AssumeRoleTrustConditionsIntegrationTest {
|
||||
createCallerRole(callerRole, "/");
|
||||
Session session = assumeCallerRole(callerRole, "/");
|
||||
// A user's aws:userid is its own unique id; a session's is role-id:session-name, and the
|
||||
// session below was issued under the name s.
|
||||
// session below was issued under the name sx.
|
||||
String userIds = createRole(trustWithCondition("*", "{\"StringLike\":{\"aws:userid\":\"AIDA*\"}}"));
|
||||
String sessionIds = createRole(trustWithCondition("*", "{\"StringLike\":{\"aws:userid\":\"AROA*:s\"}}"));
|
||||
String sessionIds = createRole(trustWithCondition("*", "{\"StringLike\":{\"aws:userid\":\"AROA*:sx\"}}"));
|
||||
|
||||
assumeRole(accessKeyId, userIds, "s", null).then().statusCode(200);
|
||||
assumeRole(accessKeyId, userIds, "sx", null).then().statusCode(200);
|
||||
assertTrustDenied(assumeRoleWithSession(session, userIds), userIds);
|
||||
assumeRoleWithSession(session, sessionIds).then().statusCode(200);
|
||||
assertTrustDenied(assumeRole(accessKeyId, sessionIds, "s", null), sessionIds);
|
||||
assertTrustDenied(assumeRole(accessKeyId, sessionIds, "sx", null), sessionIds);
|
||||
}
|
||||
|
||||
@Test
|
||||
@@ -246,7 +246,7 @@ class AssumeRoleTrustConditionsIntegrationTest {
|
||||
.formParam("Action", "AssumeRole")
|
||||
.formParam("Version", "2011-06-15")
|
||||
.formParam("RoleArn", "arn:aws:iam::" + ROLE_ACCOUNT + ":role/" + role)
|
||||
.formParam("RoleSessionName", "s")
|
||||
.formParam("RoleSessionName", "sx")
|
||||
.header("Authorization", auth(session.accessKeyId(), "sts"))
|
||||
.header("X-Amz-Security-Token", session.sessionToken())
|
||||
.when().post("/");
|
||||
@@ -265,7 +265,7 @@ class AssumeRoleTrustConditionsIntegrationTest {
|
||||
.formParam("Action", "AssumeRole")
|
||||
.formParam("Version", "2011-06-15")
|
||||
.formParam("RoleArn", "arn:aws:iam::" + ROLE_ACCOUNT + ":role/" + role)
|
||||
.formParam("RoleSessionName", "s")
|
||||
.formParam("RoleSessionName", "sx")
|
||||
.when().post("/");
|
||||
}
|
||||
|
||||
|
||||
+9
-6
@@ -20,6 +20,9 @@ import static org.hamcrest.Matchers.startsWith;
|
||||
@TestProfile(IamEnforcementProfile.class)
|
||||
class AssumeRoleTrustPolicyIntegrationTest {
|
||||
|
||||
/** The session name every request here opens, which the ARN assertions read rather than respell. */
|
||||
private static final String SESSION = "sx";
|
||||
|
||||
private static final String ACCOUNT_A = "111111111111";
|
||||
private static final String ACCOUNT_B = "222222222222";
|
||||
private static final String ACCOUNT_C = "333333333333";
|
||||
@@ -57,7 +60,7 @@ class AssumeRoleTrustPolicyIntegrationTest {
|
||||
.contentType("application/x-www-form-urlencoded")
|
||||
.formParam("Action", "AssumeRole")
|
||||
.formParam("RoleArn", "arn:aws:iam::" + ACCOUNT_B + ":role/" + role)
|
||||
.formParam("RoleSessionName", "s")
|
||||
.formParam("RoleSessionName", SESSION)
|
||||
.header("Authorization", auth(ACCOUNT_A, "sts"))
|
||||
.when().post("/")
|
||||
.then().statusCode(200)
|
||||
@@ -73,13 +76,13 @@ class AssumeRoleTrustPolicyIntegrationTest {
|
||||
.contentType("application/x-www-form-urlencoded")
|
||||
.formParam("Action", "AssumeRole")
|
||||
.formParam("RoleArn", "arn:aws-cn:iam::" + ACCOUNT_B + ":role/" + role)
|
||||
.formParam("RoleSessionName", "s")
|
||||
.formParam("RoleSessionName", SESSION)
|
||||
.header("Authorization", auth(ACCOUNT_A, "sts"))
|
||||
.when().post("/")
|
||||
.then().statusCode(200)
|
||||
.body("AssumeRoleResponse.AssumeRoleResult.Credentials.AccessKeyId", startsWith("ASIA"))
|
||||
.body("AssumeRoleResponse.AssumeRoleResult.AssumedRoleUser.Arn",
|
||||
containsString("arn:aws:sts::" + ACCOUNT_B + ":assumed-role/" + role + "/s"))
|
||||
containsString("arn:aws:sts::" + ACCOUNT_B + ":assumed-role/" + role + "/" + SESSION))
|
||||
.extract().path("AssumeRoleResponse.AssumeRoleResult.Credentials.AccessKeyId");
|
||||
|
||||
given()
|
||||
@@ -89,7 +92,7 @@ class AssumeRoleTrustPolicyIntegrationTest {
|
||||
.when().post("/")
|
||||
.then().statusCode(200)
|
||||
.body("GetCallerIdentityResponse.GetCallerIdentityResult.Arn",
|
||||
containsString("arn:aws:sts::" + ACCOUNT_B + ":assumed-role/" + role + "/s"));
|
||||
containsString("arn:aws:sts::" + ACCOUNT_B + ":assumed-role/" + role + "/" + SESSION));
|
||||
}
|
||||
|
||||
@Test
|
||||
@@ -137,7 +140,7 @@ class AssumeRoleTrustPolicyIntegrationTest {
|
||||
.contentType("application/x-www-form-urlencoded")
|
||||
.formParam("Action", "AssumeRole")
|
||||
.formParam("RoleArn", "arn:aws:iam::" + ACCOUNT_B + ":role/" + role)
|
||||
.formParam("RoleSessionName", "s")
|
||||
.formParam("RoleSessionName", SESSION)
|
||||
.header("Authorization", auth(ACCOUNT_C, "sts"))
|
||||
.when().post("/")
|
||||
.then().statusCode(403)
|
||||
@@ -156,7 +159,7 @@ class AssumeRoleTrustPolicyIntegrationTest {
|
||||
.contentType("application/x-www-form-urlencoded")
|
||||
.formParam("Action", "AssumeRole")
|
||||
.formParam("RoleArn", roleArn)
|
||||
.formParam("RoleSessionName", "s")
|
||||
.formParam("RoleSessionName", SESSION)
|
||||
.header("Authorization", auth(ACCOUNT_C, "sts"))
|
||||
.when().post("/")
|
||||
.then().statusCode(403)
|
||||
|
||||
+2
-1
@@ -85,7 +85,8 @@ class PrincipalContextKeysEnforcementIntegrationTest {
|
||||
{"Effect":"Allow","Action":"iam:ListRoles","Resource":"*",
|
||||
"Condition":{"StringEquals":{"aws:username":"%s"}}},
|
||||
{"Effect":"Allow","Action":"iam:ListGroups","Resource":"*",
|
||||
"Condition":{"StringLike":{"aws:userid":"AROA*:s"}}}]}""".formatted(role));
|
||||
"Condition":{"StringLike":{"aws:userid":"AROA*:%2$s"}}}]}"""
|
||||
.formatted(role, EnforcementFixtures.SESSION_NAME));
|
||||
Session session = EnforcementFixtures.assumeRole(baseUri.getPort(), ACCOUNT, roleArn);
|
||||
|
||||
iamCall(session.accessKeyId(), session.sessionToken(), "ListUsers").then().statusCode(200);
|
||||
|
||||
+2
-1
@@ -46,7 +46,8 @@ class RoleSessionPrincipalArnEnforcementIntegrationTest {
|
||||
void aRoleSessionsPrincipalArnIsItsRolesArnWithItsPath() {
|
||||
String role = "principal-arn-" + UUID.randomUUID().toString().substring(0, 8);
|
||||
String roleArn = "arn:aws:iam::" + ACCOUNT + ":role/team/" + role;
|
||||
String sessionArn = "arn:aws:sts::" + ACCOUNT + ":assumed-role/" + role + "/s";
|
||||
String sessionArn = "arn:aws:sts::" + ACCOUNT + ":assumed-role/" + role + "/"
|
||||
+ EnforcementFixtures.SESSION_NAME;
|
||||
createRole(role, """
|
||||
{"Version":"2012-10-17","Statement":[
|
||||
{"Effect":"Allow","Action":"iam:ListUsers","Resource":"*",
|
||||
|
||||
+2
-2
@@ -98,7 +98,7 @@ class StsAssumeRoleResourceEnforcementIntegrationTest {
|
||||
given().port(baseUri.getPort()).urlEncodingEnabled(false)
|
||||
.contentType("application/x-www-form-urlencoded")
|
||||
.header("Authorization", auth(caller.accessKeyId(), "sts"))
|
||||
.body("Action=AssumeRole&RoleSessionName=s&RoleArn="
|
||||
.body("Action=AssumeRole&RoleSessionName=" + EnforcementFixtures.SESSION_NAME + "&RoleArn="
|
||||
+ URLEncoder.encode(deniedArn, StandardCharsets.UTF_8) + "%ZZ")
|
||||
.when().post("/")
|
||||
.then().statusCode(not(200)).body(not(containsString("AccessKeyId")));
|
||||
@@ -116,7 +116,7 @@ class StsAssumeRoleResourceEnforcementIntegrationTest {
|
||||
.header("Authorization", auth(caller.accessKeyId(), "sts"))
|
||||
.formParam("Action", "AssumeRole")
|
||||
.formParam("RoleArn", roleArn)
|
||||
.formParam("RoleSessionName", "s")
|
||||
.formParam("RoleSessionName", EnforcementFixtures.SESSION_NAME)
|
||||
.when().post("/");
|
||||
}
|
||||
}
|
||||
+2
-2
@@ -93,7 +93,7 @@ class StsIssuedSessionEnforcementIntegrationTest {
|
||||
"Principal":{"AWS":"arn:aws:iam::%s:root"},"Action":"sts:AssumeRole"}]}""".formatted(ACCOUNT));
|
||||
iam("PutRolePolicy", "RoleName", role, "PolicyName", "s3", "PolicyDocument", ALL_S3);
|
||||
given().filter(tokenOnlySession).formParam("Action", "AssumeRole")
|
||||
.formParam("RoleArn", "arn:aws:iam::" + ACCOUNT + ":role/" + role).formParam("RoleSessionName", "s")
|
||||
.formParam("RoleArn", "arn:aws:iam::" + ACCOUNT + ":role/" + role).formParam("RoleSessionName", "sx")
|
||||
.when().post("/").then().statusCode(403);
|
||||
|
||||
S3RequestSigner readerSession = sessionToken(reader);
|
||||
@@ -271,7 +271,7 @@ class StsIssuedSessionEnforcementIntegrationTest {
|
||||
|
||||
private static void assumeRole(S3RequestSigner caller, String role, int status) {
|
||||
given().filter(caller).formParam("Action", "AssumeRole")
|
||||
.formParam("RoleArn", "arn:aws:iam::" + ACCOUNT + ":role/" + role).formParam("RoleSessionName", "s")
|
||||
.formParam("RoleArn", "arn:aws:iam::" + ACCOUNT + ":role/" + role).formParam("RoleSessionName", "sx")
|
||||
.when().post("/").then().statusCode(status);
|
||||
}
|
||||
|
||||
|
||||
@@ -789,8 +789,8 @@ class StsQueryHandlerTest {
|
||||
role.setAssumeRolePolicyDocument("{}");
|
||||
when(iamService.findRole("000000000000", "web-role")).thenReturn(Optional.of(role));
|
||||
WebIdentityTokenVerifier verifier = mock(WebIdentityTokenVerifier.class);
|
||||
when(verifier.peekIssuer("jwt")).thenReturn(Optional.of(issuer));
|
||||
when(verifier.verify(eq("jwt"), any(), eq(issuer), anyString()))
|
||||
when(verifier.peekIssuer("jwt0")).thenReturn(Optional.of(issuer));
|
||||
when(verifier.verify(eq("jwt0"), any(), eq(issuer), anyString()))
|
||||
.thenReturn(new WebIdentityToken(issuer, "system:serviceaccount:default:app",
|
||||
List.of("sts.amazonaws.com")));
|
||||
OidcIssuerKeyLookup keys = mock(OidcIssuerKeyLookup.class);
|
||||
@@ -806,7 +806,7 @@ class StsQueryHandlerTest {
|
||||
MultivaluedMap<String, String> params = new MultivaluedHashMap<>();
|
||||
params.putSingle("RoleArn", requestedRoleArn);
|
||||
params.putSingle("RoleSessionName", "app");
|
||||
params.putSingle("WebIdentityToken", "jwt");
|
||||
params.putSingle("WebIdentityToken", "jwt0");
|
||||
|
||||
Response response = handler.handle("AssumeRoleWithWebIdentity", params);
|
||||
|
||||
@@ -821,7 +821,7 @@ class StsQueryHandlerTest {
|
||||
void assumeRoleMintsTheSessionInTheRolesPartition() {
|
||||
MultivaluedMap<String, String> params = new MultivaluedHashMap<>();
|
||||
params.putSingle("RoleArn", "arn:aws:iam::000000000000:role/commercial-role");
|
||||
params.putSingle("RoleSessionName", "s");
|
||||
params.putSingle("RoleSessionName", "sx");
|
||||
IamRole role = new IamRole();
|
||||
role.setRoleName("commercial-role");
|
||||
role.setArn("arn:aws:iam::000000000000:role/commercial-role");
|
||||
@@ -830,7 +830,7 @@ class StsQueryHandlerTest {
|
||||
.handle("AssumeRole", params);
|
||||
|
||||
assertEquals(200, response.getStatus());
|
||||
assertEquals("arn:aws:sts::000000000000:assumed-role/commercial-role/s",
|
||||
assertEquals("arn:aws:sts::000000000000:assumed-role/commercial-role/sx",
|
||||
extract(ARN, (String) response.getEntity()));
|
||||
}
|
||||
|
||||
@@ -875,7 +875,7 @@ class StsQueryHandlerTest {
|
||||
|
||||
MultivaluedMap<String, String> params = new MultivaluedHashMap<>();
|
||||
params.putSingle("RoleArn", role.getArn());
|
||||
params.putSingle("RoleSessionName", "s");
|
||||
params.putSingle("RoleSessionName", "sx");
|
||||
params.putSingle("DurationSeconds", "900");
|
||||
|
||||
Response response = handler.handle("AssumeRole", params);
|
||||
@@ -884,7 +884,7 @@ class StsQueryHandlerTest {
|
||||
assertEquals(expected, extract(EXPIRATION, (String) response.getEntity()));
|
||||
ArgumentCaptor<Instant> sessionExpiration = ArgumentCaptor.forClass(Instant.class);
|
||||
verify(iamService).registerSession(anyString(), anyString(), anyString(), eq(role.getArn()),
|
||||
sessionExpiration.capture(), isNull(), eq("000000000000"), eq("s"), anyString());
|
||||
sessionExpiration.capture(), isNull(), eq("000000000000"), eq("sx"), anyString());
|
||||
assertEquals(expiration, sessionExpiration.getValue());
|
||||
}
|
||||
|
||||
|
||||
+138
-1
@@ -12,7 +12,12 @@ import static org.hamcrest.Matchers.not;
|
||||
/**
|
||||
* The declared constraints STS reads from its model rather than from a check written by hand.
|
||||
*
|
||||
* <p>Three operations are read that way. {@code GetAccessKeyInfo} is the parity case: its own check
|
||||
* <p>Every operation that models a member is read that way now. The three read first are below,
|
||||
* then the seven that answered an absent member from a check of their own, which named the
|
||||
* parameter as the request writes it and read a blank value as an absent one. Both of those move
|
||||
* onto the model's form here.
|
||||
*
|
||||
* <p>Three operations were read first. {@code GetAccessKeyInfo} is the parity case: its own check
|
||||
* answered {@code accessKeyId} from the same bounds and the same pattern, and what changes is that
|
||||
* a value breaking both is answered for both, which is the reading #6402 settled for this package.
|
||||
* {@code GetSessionToken} brings members nothing read at all, so a {@code SerialNumber}, a
|
||||
@@ -35,6 +40,9 @@ class StsRequestConstraintsIntegrationTest {
|
||||
private static final String MESSAGE = "ErrorResponse.Error.Message";
|
||||
private static final String SESSION_KEY =
|
||||
"GetSessionTokenResponse.GetSessionTokenResult.Credentials.AccessKeyId";
|
||||
/** One of the five managed policies that may scope a privileged session. */
|
||||
private static final String ROOT_TASK_POLICY =
|
||||
"arn:aws:iam::aws:policy/root-task/IAMAuditRootUserCredentials";
|
||||
|
||||
private static RequestSpecification sts(String action) {
|
||||
return given().header("Authorization", STS_AUTH).formParam("Action", action);
|
||||
@@ -201,4 +209,133 @@ class StsRequestConstraintsIntegrationTest {
|
||||
.body(CODE, equalTo("AccessDenied"))
|
||||
.body(MESSAGE, containsString("Cannot call GetSessionToken with session credentials"));
|
||||
}
|
||||
|
||||
/**
|
||||
* An absent required member is reported under the name a constraint message spells, every one
|
||||
* the request leaves out in the order the model lists them, where the check this replaces
|
||||
* answered the first it found and named it as the request writes it. The acronym keeps the
|
||||
* model's own spelling with a lower first letter, {@code sAMLAssertion}, which is what Smithy
|
||||
* renders and what the recorded refusals carry.
|
||||
*/
|
||||
@Test
|
||||
void theRequiredMembersAreNamedTheWayTheModelSpellsThem() {
|
||||
sts("AssumeRole")
|
||||
.when().post("/").then().statusCode(400)
|
||||
.body(CODE, equalTo("ValidationError"))
|
||||
.body(MESSAGE, equalTo("2 validation errors detected: Value null at 'roleArn' failed"
|
||||
+ " to satisfy constraint: Member must not be null; Value null at"
|
||||
+ " 'roleSessionName' failed to satisfy constraint: Member must not be null"));
|
||||
|
||||
sts("AssumeRoleWithSAML")
|
||||
.when().post("/").then().statusCode(400)
|
||||
.body(MESSAGE, equalTo("3 validation errors detected: Value null at 'roleArn' failed"
|
||||
+ " to satisfy constraint: Member must not be null; Value null at"
|
||||
+ " 'principalArn' failed to satisfy constraint: Member must not be null;"
|
||||
+ " Value null at 'sAMLAssertion' failed to satisfy constraint: Member must"
|
||||
+ " not be null"));
|
||||
}
|
||||
|
||||
/**
|
||||
* A member sent empty is a member the request carries, so it breaks its own minimum length
|
||||
* where the check this replaces called it absent. The pattern is not broken as well: a session
|
||||
* name's own pattern matches an empty value, and only the length refuses it.
|
||||
*/
|
||||
@Test
|
||||
void aBlankMemberBreaksItsLengthWhereItUsedToReadAsAbsent() {
|
||||
sts("AssumeRole")
|
||||
.formParam("RoleArn", "arn:aws:iam::000000000000:role/Reader")
|
||||
.formParam("RoleSessionName", "")
|
||||
.when().post("/").then().statusCode(400)
|
||||
.body(MESSAGE, equalTo("1 validation error detected: Value '' at 'roleSessionName'"
|
||||
+ " failed to satisfy constraint: Member must have length greater than or"
|
||||
+ " equal to 2"));
|
||||
}
|
||||
|
||||
/**
|
||||
* {@code AssumeRoot}'s own length check on {@code TargetPrincipal} said what the model says, so
|
||||
* it comes off, and the duration and the token size come with it. The structure member arrives
|
||||
* as {@code TaskPolicyArn.arn}, so a request naming none of its fields is the member reading as
|
||||
* null. The global endpoint is still refused ahead of all of it.
|
||||
*/
|
||||
@Test
|
||||
void theRootSessionsBoundsComeFromTheModel() {
|
||||
sts("AssumeRoot")
|
||||
.when().post("/").then().statusCode(400)
|
||||
.body(MESSAGE, equalTo("2 validation errors detected: Value null at 'targetPrincipal'"
|
||||
+ " failed to satisfy constraint: Member must not be null; Value null at"
|
||||
+ " 'taskPolicyArn' failed to satisfy constraint: Member must not be null"));
|
||||
|
||||
sts("AssumeRoot")
|
||||
.formParam("TargetPrincipal", "00000000000")
|
||||
.formParam("TaskPolicyArn.arn", ROOT_TASK_POLICY)
|
||||
.formParam("DurationSeconds", "901")
|
||||
.when().post("/").then().statusCode(400)
|
||||
.body(MESSAGE, equalTo("2 validation errors detected: Value '00000000000' at"
|
||||
+ " 'targetPrincipal' failed to satisfy constraint: Member must have length"
|
||||
+ " greater than or equal to 12; Value '901' at 'durationSeconds' failed to"
|
||||
+ " satisfy constraint: Member must have value less than or equal to 900"));
|
||||
}
|
||||
|
||||
/** The bounds the other three operations gained, each from its own shape. */
|
||||
@Test
|
||||
void theFederationNameAndTheEncodedMessageAreHeldToTheirShapes() {
|
||||
sts("GetFederationToken")
|
||||
.formParam("Name", "a")
|
||||
.when().post("/").then().statusCode(400)
|
||||
.body(MESSAGE, equalTo("1 validation error detected: Value 'a' at 'name' failed to"
|
||||
+ " satisfy constraint: Member must have length greater than or equal to 2"));
|
||||
|
||||
sts("GetFederationToken")
|
||||
.formParam("Name", "bad name")
|
||||
.when().post("/").then().statusCode(400)
|
||||
.body(MESSAGE, equalTo("1 validation error detected: Value 'bad name' at 'name' failed"
|
||||
+ " to satisfy constraint: Member must satisfy regular expression pattern:"
|
||||
+ " [\\w+=,.@-]*"));
|
||||
|
||||
sts("DecodeAuthorizationMessage")
|
||||
.formParam("EncodedMessage", "")
|
||||
.when().post("/").then().statusCode(400)
|
||||
.body(MESSAGE, equalTo("1 validation error detected: Value '' at 'encodedMessage'"
|
||||
+ " failed to satisfy constraint: Member must have length greater than or"
|
||||
+ " equal to 1"));
|
||||
}
|
||||
|
||||
/**
|
||||
* {@code TradeInToken} is required and carries no length at all, so a blank one is a value the
|
||||
* request sent: it reaches the lookup and is answered as a token that cannot be redeemed, where
|
||||
* the check this replaces called it absent. That is Floci's reading, nothing published saying
|
||||
* what AWS answers an empty trade-in token, and the docs record it.
|
||||
*/
|
||||
@Test
|
||||
void aBlankTradeInTokenIsAValueAndReachesTheLookup() {
|
||||
sts("GetDelegatedAccessToken")
|
||||
.when().post("/").then().statusCode(400)
|
||||
.body(MESSAGE, equalTo("1 validation error detected: Value null at 'tradeInToken'"
|
||||
+ " failed to satisfy constraint: Member must not be null"));
|
||||
|
||||
sts("GetDelegatedAccessToken")
|
||||
.formParam("TradeInToken", "")
|
||||
.when().post("/").then().statusCode(400)
|
||||
.body(CODE, equalTo("ExpiredTradeInTokenException"));
|
||||
}
|
||||
|
||||
/**
|
||||
* A tag arrives as a member of a list of structures, so its fields are named under the index
|
||||
* the request spelled, and a key that is empty breaks both the length and the pattern its shape
|
||||
* declares rather than the first of them.
|
||||
*/
|
||||
@Test
|
||||
void aSessionTagBreaksItsOwnShapeUnderTheIndexTheRequestSpelled() {
|
||||
sts("AssumeRole")
|
||||
.formParam("RoleArn", "arn:aws:iam::000000000000:role/Reader")
|
||||
.formParam("RoleSessionName", "session")
|
||||
.formParam("Tags.member.1.Key", "")
|
||||
.formParam("Tags.member.1.Value", "v")
|
||||
.when().post("/").then().statusCode(400)
|
||||
.body(MESSAGE, equalTo("2 validation errors detected: Value '' at 'tags.1.member.key'"
|
||||
+ " failed to satisfy constraint: Member must have length greater than or"
|
||||
+ " equal to 1; Value '' at 'tags.1.member.key' failed to satisfy constraint:"
|
||||
+ " Member must satisfy regular expression pattern:"
|
||||
+ " [\\p{L}\\p{Z}\\p{N}_.:/=+\\-@]+"));
|
||||
}
|
||||
}
|
||||
+3
-3
@@ -264,7 +264,7 @@ class S3BucketPolicyEnforcementIntegrationTest {
|
||||
{"Version":"2012-10-17","Statement":[{"Effect":"Allow","Action":"s3:*","Resource":"*"}]}""")
|
||||
.header("Authorization", auth("000000000000", "iam")).when().post("/").then().statusCode(200);
|
||||
ExtractableResponse<Response> assumed = given().formParam("Action", "AssumeRole")
|
||||
.formParam("RoleArn", roleArn).formParam("RoleSessionName", "s")
|
||||
.formParam("RoleArn", roleArn).formParam("RoleSessionName", "sx")
|
||||
.header("Authorization", auth("000000000000", "sts")).when().post("/")
|
||||
.then().statusCode(200).extract();
|
||||
String sessionArn = assumed.path("AssumeRoleResponse.AssumeRoleResult.AssumedRoleUser.Arn");
|
||||
@@ -310,7 +310,7 @@ class S3BucketPolicyEnforcementIntegrationTest {
|
||||
putBucketPolicy(bucket, """
|
||||
{"Version":"2012-10-17","Statement":[
|
||||
{"Effect":"Deny","Principal":"*","Action":"s3:GetObject","Resource":"arn:aws:s3:::%1$s/userid/*",
|
||||
"Condition":{"StringNotLike":{"aws:userid":"AROA*:s"}}},
|
||||
"Condition":{"StringNotLike":{"aws:userid":"AROA*:sx"}}},
|
||||
{"Effect":"Deny","Principal":"*","Action":"s3:GetObject","Resource":"arn:aws:s3:::%1$s/type/*",
|
||||
"Condition":{"StringNotEquals":{"aws:PrincipalType":"AssumedRole"}}},
|
||||
{"Effect":"Deny","Principal":"*","Action":"s3:GetObject","Resource":"arn:aws:s3:::%1$s/username/*",
|
||||
@@ -417,7 +417,7 @@ class S3BucketPolicyEnforcementIntegrationTest {
|
||||
.header("Authorization", auth(accountId, "iam")).when().post("/").then().statusCode(200);
|
||||
ExtractableResponse<Response> assumed = given().formParam("Action", "AssumeRole")
|
||||
.formParam("RoleArn", "arn:aws:iam::" + accountId + ":role/team/" + role)
|
||||
.formParam("RoleSessionName", "s")
|
||||
.formParam("RoleSessionName", "sx")
|
||||
.header("Authorization", auth(accountId, "sts")).when().post("/")
|
||||
.then().statusCode(200).extract();
|
||||
return S3RequestSigner.signedAs(
|
||||
|
||||
@@ -37,6 +37,13 @@ import static io.restassured.RestAssured.given;
|
||||
*/
|
||||
public final class EnforcementFixtures {
|
||||
|
||||
/**
|
||||
* The name {@link #assumeRole} opens its session under, which a caller asserting on the
|
||||
* session's ARN or on {@code aws:userid} reads from here rather than spelling again. Two
|
||||
* characters because the model declares {@code roleSessionNameType} as 2 to 64.
|
||||
*/
|
||||
public static final String SESSION_NAME = "sx";
|
||||
|
||||
private static final DateTimeFormatter AMZ_DATE =
|
||||
DateTimeFormatter.ofPattern("yyyyMMdd'T'HHmmss'Z'").withZone(ZoneOffset.UTC);
|
||||
|
||||
@@ -157,12 +164,13 @@ public final class EnforcementFixtures {
|
||||
}
|
||||
|
||||
/**
|
||||
* Assumes {@code roleArn} as {@code callerAccessKeyId}, in a session named {@code s}, and returns
|
||||
* the session's credentials. The role's trust policy has to admit the caller.
|
||||
* Assumes {@code roleArn} as {@code callerAccessKeyId}, in a session named
|
||||
* {@link #SESSION_NAME}, and returns the session's credentials. The role's trust policy has to
|
||||
* admit the caller.
|
||||
*/
|
||||
public static Session assumeRole(int port, String callerAccessKeyId, String roleArn) {
|
||||
XmlPath credentials = query(port, auth(callerAccessKeyId, "sts"), "AssumeRole",
|
||||
"RoleArn", roleArn, "RoleSessionName", "s")
|
||||
"RoleArn", roleArn, "RoleSessionName", SESSION_NAME)
|
||||
.statusCode(200).extract().xmlPath();
|
||||
return new Session(
|
||||
credentials.getString("AssumeRoleResponse.AssumeRoleResult.Credentials.AccessKeyId"),
|
||||
|
||||
Reference in new issue
Block a user