mirror of
https://github.com/floci-io/floci.git
synced 2026-11-27 07:39:24 -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
@@ -58,7 +58,6 @@ public class StsQueryHandler {
|
||||
private static final String ROOT_TASK_POLICY_PATH = "/root-task/";
|
||||
/** "the maximum session duration of 900 seconds (15 minutes)", which is also the default here. */
|
||||
private static final int MAX_ROOT_SESSION_SECONDS = 900;
|
||||
private static final int MAX_SESSION_TOKEN_SIZE = 4096;
|
||||
/** "If not specified, the default duration is 300 seconds (5 minutes)." */
|
||||
private static final int DEFAULT_TOKEN_SECONDS = 300;
|
||||
private static final String STS_AUDIENCE = "sts.amazonaws.com"; // partition-literal: web-identity audience; no source outside the commercial partition (P9)
|
||||
@@ -151,14 +150,14 @@ public class StsQueryHandler {
|
||||
}
|
||||
|
||||
private Response handleAssumeRole(MultivaluedMap<String, String> params) {
|
||||
Response validation = validateRequired(params, "RoleArn", "RoleSessionName");
|
||||
Response integerMembers = validateIntegerMembers(params, "DurationSeconds", "MinimumSessionTokenSize");
|
||||
if (integerMembers != null) {
|
||||
return integerMembers;
|
||||
}
|
||||
Response validation = validateDeclaredConstraints("AssumeRole", params);
|
||||
if (validation != null) {
|
||||
return validation;
|
||||
}
|
||||
Response durationValidation = validateDurationSeconds(params, 900, 43200);
|
||||
if (durationValidation != null) {
|
||||
return durationValidation;
|
||||
}
|
||||
String roleArn = getParam(params, "RoleArn");
|
||||
String sessionName = getParam(params, "RoleSessionName");
|
||||
int durationSeconds = getIntParam(params, "DurationSeconds", 3600);
|
||||
@@ -339,17 +338,17 @@ public class StsQueryHandler {
|
||||
}
|
||||
|
||||
private Response handleAssumeRoleWithWebIdentity(MultivaluedMap<String, String> params) {
|
||||
Response validation = validateRequired(params, "RoleArn", "RoleSessionName", "WebIdentityToken");
|
||||
Response integerMembers = validateIntegerMembers(params, "DurationSeconds", "MinimumSessionTokenSize");
|
||||
if (integerMembers != null) {
|
||||
return integerMembers;
|
||||
}
|
||||
Response validation = validateDeclaredConstraints("AssumeRoleWithWebIdentity", params);
|
||||
if (validation != null) {
|
||||
return validation;
|
||||
}
|
||||
validation = validateIamRoleArn(getParam(params, "RoleArn"));
|
||||
if (validation != null) {
|
||||
return validation;
|
||||
}
|
||||
Response durationValidation = validateDurationSeconds(params, 900, 43200);
|
||||
if (durationValidation != null) {
|
||||
return durationValidation;
|
||||
Response roleArnShape = validateIamRoleArn(getParam(params, "RoleArn"));
|
||||
if (roleArnShape != null) {
|
||||
return roleArnShape;
|
||||
}
|
||||
String roleArn = getParam(params, "RoleArn");
|
||||
String sessionName = getParam(params, "RoleSessionName");
|
||||
@@ -529,14 +528,14 @@ public class StsQueryHandler {
|
||||
}
|
||||
|
||||
private Response handleAssumeRoleWithSAML(MultivaluedMap<String, String> params) {
|
||||
Response validation = validateRequired(params, "RoleArn", "PrincipalArn", "SAMLAssertion");
|
||||
Response integerMembers = validateIntegerMembers(params, "DurationSeconds", "MinimumSessionTokenSize");
|
||||
if (integerMembers != null) {
|
||||
return integerMembers;
|
||||
}
|
||||
Response validation = validateDeclaredConstraints("AssumeRoleWithSAML", params);
|
||||
if (validation != null) {
|
||||
return validation;
|
||||
}
|
||||
Response durationValidation = validateDurationSeconds(params, 900, 43200);
|
||||
if (durationValidation != null) {
|
||||
return durationValidation;
|
||||
}
|
||||
String roleArn = getParam(params, "RoleArn");
|
||||
String principalArn = getParam(params, "PrincipalArn");
|
||||
int durationSeconds = getIntParam(params, "DurationSeconds", 3600);
|
||||
@@ -610,14 +609,14 @@ public class StsQueryHandler {
|
||||
return AwsQueryResponse.error("AccessDenied", IamService.FEDERATION_TOKEN_SESSION_MESSAGE,
|
||||
AwsNamespaces.STS, 403);
|
||||
}
|
||||
Response validation = validateRequired(params, "Name");
|
||||
Response integerMembers = validateIntegerMembers(params, "DurationSeconds", "MinimumSessionTokenSize");
|
||||
if (integerMembers != null) {
|
||||
return integerMembers;
|
||||
}
|
||||
Response validation = validateDeclaredConstraints("GetFederationToken", params);
|
||||
if (validation != null) {
|
||||
return validation;
|
||||
}
|
||||
Response durationValidation = validateDurationSeconds(params, 900, 129600);
|
||||
if (durationValidation != null) {
|
||||
return durationValidation;
|
||||
}
|
||||
String name = getParam(params, "Name");
|
||||
int durationSeconds = getIntParam(params, "DurationSeconds", 43200);
|
||||
|
||||
@@ -664,7 +663,7 @@ public class StsQueryHandler {
|
||||
* not populated for this operation.
|
||||
*/
|
||||
private Response handleGetDelegatedAccessToken(MultivaluedMap<String, String> params) {
|
||||
Response validation = validateRequired(params, "TradeInToken");
|
||||
Response validation = validateDeclaredConstraints("GetDelegatedAccessToken", params);
|
||||
if (validation != null) {
|
||||
return validation;
|
||||
}
|
||||
@@ -726,24 +725,15 @@ public class StsQueryHandler {
|
||||
+ " AssumeRoot. You must send this request to a Regional AWS STS endpoint.",
|
||||
AwsNamespaces.STS, 400);
|
||||
}
|
||||
Response validation = validateRequired(params, "TargetPrincipal", "TaskPolicyArn.arn");
|
||||
Response integerMembers = validateIntegerMembers(params, "DurationSeconds", "MinimumSessionTokenSize");
|
||||
if (integerMembers != null) {
|
||||
return integerMembers;
|
||||
}
|
||||
Response validation = validateDeclaredConstraints("AssumeRoot", params);
|
||||
if (validation != null) {
|
||||
return validation;
|
||||
}
|
||||
String targetPrincipal = getParam(params, "TargetPrincipal");
|
||||
Response principalLength = violation(
|
||||
SmithyValidationErrors.lengthOutOfRange("targetPrincipal", targetPrincipal, 12, 2048));
|
||||
if (principalLength != null) {
|
||||
return principalLength;
|
||||
}
|
||||
Response durationValidation = validateDurationSeconds(params, 0, 900);
|
||||
if (durationValidation != null) {
|
||||
return durationValidation;
|
||||
}
|
||||
Response tokenSizeValidation = validateMinimumSessionTokenSize(params);
|
||||
if (tokenSizeValidation != null) {
|
||||
return tokenSizeValidation;
|
||||
}
|
||||
String callerAccountId = regionResolver.getAccountId();
|
||||
Response rootCaller = refuseRootCredentials(callerAccountId);
|
||||
if (rootCaller != null) {
|
||||
@@ -803,28 +793,6 @@ public class StsQueryHandler {
|
||||
return AwsArnUtils.parse(arn).resource().startsWith("policy" + ROOT_TASK_POLICY_PATH);
|
||||
}
|
||||
|
||||
/**
|
||||
* {@code MinimumSessionTokenSize} is 0 to 4096 in the model, "The value must not exceed 4,096
|
||||
* bytes", and the size it asks for is materialized, so the bound is enforced rather than
|
||||
* clamped: a value outside it is the same {@code ValidationError} every other member violation
|
||||
* answers, and one that is no integer at all the same {@code InvalidParameterValue}
|
||||
* {@code DurationSeconds} gives.
|
||||
*/
|
||||
private Response validateMinimumSessionTokenSize(MultivaluedMap<String, String> params) {
|
||||
String value = params.getFirst("MinimumSessionTokenSize");
|
||||
if (value == null) {
|
||||
return null;
|
||||
}
|
||||
int size;
|
||||
try {
|
||||
size = Integer.parseInt(value);
|
||||
} catch (NumberFormatException e) {
|
||||
return notANumber("MinimumSessionTokenSize", value);
|
||||
}
|
||||
return violation(SmithyValidationErrors.outOfRange("minimumSessionTokenSize", size, 0,
|
||||
MAX_SESSION_TOKEN_SIZE));
|
||||
}
|
||||
|
||||
/** The account a {@code TargetPrincipal} names, whether it is an account id or a principal ARN. */
|
||||
private static String accountOf(String targetPrincipal) {
|
||||
if (targetPrincipal.matches("\\d{12}")) {
|
||||
@@ -864,7 +832,7 @@ public class StsQueryHandler {
|
||||
}
|
||||
|
||||
private Response handleDecodeAuthorizationMessage(MultivaluedMap<String, String> params) {
|
||||
Response validation = validateRequired(params, "EncodedMessage");
|
||||
Response validation = validateDeclaredConstraints("DecodeAuthorizationMessage", params);
|
||||
if (validation != null) {
|
||||
return validation;
|
||||
}
|
||||
@@ -873,18 +841,6 @@ public class StsQueryHandler {
|
||||
return Response.ok(AwsQueryResponse.envelope("DecodeAuthorizationMessage", AwsNamespaces.STS, result)).build();
|
||||
}
|
||||
|
||||
private Response validateRequired(MultivaluedMap<String, String> params, String... names) {
|
||||
for (String name : names) {
|
||||
String value = params.getFirst(name);
|
||||
if (value == null || value.isBlank()) {
|
||||
return AwsQueryResponse.error("ValidationError",
|
||||
SmithyValidationErrors.message(List.of(SmithyValidationErrors.notNull(name))),
|
||||
AwsNamespaces.STS, 400);
|
||||
}
|
||||
}
|
||||
return null;
|
||||
}
|
||||
|
||||
/**
|
||||
* The constraints the model declares for {@code action}, answered the way this handler answers
|
||||
* every other refusal: one {@code ValidationError} naming every violation it found, in the
|
||||
@@ -952,26 +908,6 @@ public class StsQueryHandler {
|
||||
+ name + " is invalid. Reason: Must be an integer.", AwsNamespaces.STS, 400);
|
||||
}
|
||||
|
||||
/**
|
||||
* Validates the optional {@code DurationSeconds} parameter against {@code minSeconds}/{@code maxSeconds}.
|
||||
* Returns {@code null} when the parameter is absent or valid; otherwise a {@code ValidationError} (out of
|
||||
* range) or {@code InvalidParameterValue} (not an integer) response, matching AWS's own wire behavior.
|
||||
*/
|
||||
private Response validateDurationSeconds(MultivaluedMap<String, String> params, int minSeconds, int maxSeconds) {
|
||||
String value = params.getFirst("DurationSeconds");
|
||||
if (value == null) {
|
||||
return null;
|
||||
}
|
||||
int durationSeconds;
|
||||
try {
|
||||
durationSeconds = Integer.parseInt(value);
|
||||
} catch (NumberFormatException e) {
|
||||
return notANumber("DurationSeconds", value);
|
||||
}
|
||||
return violation(SmithyValidationErrors.outOfRange("durationSeconds", durationSeconds,
|
||||
minSeconds, maxSeconds));
|
||||
}
|
||||
|
||||
/**
|
||||
* {@code GetWebIdentityToken} answers "a signed JSON Web Token (JWT) that represents the
|
||||
* calling Amazon Web Services identity", signed by STS and verifiable "using the verification
|
||||
|
||||
Reference in new issue
Block a user