mirror of
https://github.com/floci-io/floci.git
synced 2026-11-23 06:00:46 -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
+27
-7
@@ -20,9 +20,10 @@
|
||||
|
||||
## Request Constraints
|
||||
|
||||
Three operations are held to the constraints their model declares rather than to a check written
|
||||
by hand, `tools/aws/regen_sts_shapes.py` vendoring them for `GetAccessKeyInfo`, `GetSessionToken`
|
||||
and `GetWebIdentityToken` and the walk being the one IAM reads its own file with. One word of the
|
||||
Every operation that models a constraint is held to the one its model declares rather than to a
|
||||
check written by hand, which is all ten that carry a member: `tools/aws/regen_sts_shapes.py`
|
||||
vendors them and the walk is the one IAM reads its own file with. `GetCallerIdentity` models no
|
||||
member at all, so there is nothing to read for it. One word of the
|
||||
message differs between the two: STS quotes the offending value, `Value 'x' at 'serialNumber'`,
|
||||
where IAM names the member and leaves it out, which is what each service's own captures carry (see
|
||||
the [IAM service doc](iam.md)). Every violation
|
||||
@@ -49,10 +50,29 @@ the constraints, while a digit string is held to the range whatever width it ove
|
||||
of `99999999999` breaks the maximum rather than being called no integer. The whitespace around a
|
||||
number is not part of it, both where the range is read and where the duration is then used, so a
|
||||
`DurationSeconds` of ` 3600 ` is an hour rather than the default a raw parse would have fallen back
|
||||
to, which is how IAM reads its own `maxItems`. Every other operation
|
||||
that takes a member answers an absent one from a check of its own, which names the parameter as
|
||||
the request writes it, `RoleArn` rather than `roleArn`, and reads a blank value as an absent one.
|
||||
Those are drifts of their own, and taking those operations over is what settles them.
|
||||
to, which is how IAM reads its own `maxItems`.
|
||||
|
||||
The seven operations read last answered an absent member from a check of their own, which named the
|
||||
parameter as the request writes it, `RoleArn` rather than `roleArn`, and read a blank value as an
|
||||
absent one. Both of those move onto the form above, so a request missing `RoleSessionName` is
|
||||
answered `Value null at 'roleSessionName' failed to satisfy constraint: Member must not be null`,
|
||||
and one sending it empty breaks its minimum length instead, which is the reading the model gives
|
||||
and the one the rest of this package already answers. What those seven gain is every bound the
|
||||
model declares beside the required members: `RoleArn` at 20 to 2048 characters,
|
||||
`RoleSessionName` at 2 to 64 of `[\w+=,.@-]`, `ExternalId`, `SourceIdentity`, `Policy`,
|
||||
`PolicyArns`, `Tags`, `TransitiveTagKeys` and `ProvidedContexts` on `AssumeRole`, `SAMLAssertion`
|
||||
at 4 to 100000 on `AssumeRoleWithSAML`, `WebIdentityToken` at 4 to 20000 and `ProviderId` at 4 to
|
||||
2048 on `AssumeRoleWithWebIdentity`, `Name` at 2 to 32 on `GetFederationToken`, `EncodedMessage` at
|
||||
1 to 10240 on `DecodeAuthorizationMessage`, and `TargetPrincipal` at 12 to 2048 on `AssumeRoot`,
|
||||
whose own length check said the same thing by hand. Each operation keeps the refusals it answers
|
||||
ahead of the constraints: `GetFederationToken` and `GetSessionToken` still turn away session
|
||||
credentials first, and `AssumeRoot` still refuses the global endpoint first.
|
||||
|
||||
One reading is Floci's own. `TradeInToken` on `GetDelegatedAccessToken` is required and carries no
|
||||
length at all, so a request sending it empty is a request that carries it: 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, and the model is what is in hand, so the blank is read as the value it is.
|
||||
|
||||
## Privileged Root Sessions
|
||||
|
||||
|
||||
@@ -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
|
||||
|
||||
@@ -6,9 +6,95 @@
|
||||
"operations": {
|
||||
"GetAccessKeyInfo": "GetAccessKeyInfoRequest",
|
||||
"GetSessionToken": "GetSessionTokenRequest",
|
||||
"GetWebIdentityToken": "GetWebIdentityTokenRequest"
|
||||
"GetWebIdentityToken": "GetWebIdentityTokenRequest",
|
||||
"AssumeRole": "AssumeRoleRequest",
|
||||
"AssumeRoleWithSAML": "AssumeRoleWithSAMLRequest",
|
||||
"AssumeRoleWithWebIdentity": "AssumeRoleWithWebIdentityRequest",
|
||||
"AssumeRoot": "AssumeRootRequest",
|
||||
"DecodeAuthorizationMessage": "DecodeAuthorizationMessageRequest",
|
||||
"GetDelegatedAccessToken": "GetDelegatedAccessTokenRequest",
|
||||
"GetFederationToken": "GetFederationTokenRequest"
|
||||
},
|
||||
"shapes": {
|
||||
"AssumeRoleRequest": {
|
||||
"type": "structure",
|
||||
"required": [
|
||||
"RoleArn",
|
||||
"RoleSessionName"
|
||||
],
|
||||
"members": {
|
||||
"RoleArn": "arnType",
|
||||
"RoleSessionName": "roleSessionNameType",
|
||||
"PolicyArns": "policyDescriptorListType",
|
||||
"Policy": "unrestrictedSessionPolicyDocumentType",
|
||||
"DurationSeconds": "roleDurationSecondsType",
|
||||
"Tags": "tagListType",
|
||||
"TransitiveTagKeys": "tagKeyListType",
|
||||
"ExternalId": "externalIdType",
|
||||
"SerialNumber": "serialNumberType",
|
||||
"TokenCode": "tokenCodeType",
|
||||
"SourceIdentity": "sourceIdentityType",
|
||||
"ProvidedContexts": "ProvidedContextsListType",
|
||||
"MinimumSessionTokenSize": "minimumSessionTokenSizeType"
|
||||
}
|
||||
},
|
||||
"AssumeRoleWithSAMLRequest": {
|
||||
"type": "structure",
|
||||
"required": [
|
||||
"RoleArn",
|
||||
"PrincipalArn",
|
||||
"SAMLAssertion"
|
||||
],
|
||||
"members": {
|
||||
"RoleArn": "arnType",
|
||||
"PrincipalArn": "arnType",
|
||||
"SAMLAssertion": "SAMLAssertionType",
|
||||
"PolicyArns": "policyDescriptorListType",
|
||||
"Policy": "sessionPolicyDocumentType",
|
||||
"DurationSeconds": "roleDurationSecondsType",
|
||||
"MinimumSessionTokenSize": "minimumSessionTokenSizeType"
|
||||
}
|
||||
},
|
||||
"AssumeRoleWithWebIdentityRequest": {
|
||||
"type": "structure",
|
||||
"required": [
|
||||
"RoleArn",
|
||||
"RoleSessionName",
|
||||
"WebIdentityToken"
|
||||
],
|
||||
"members": {
|
||||
"RoleArn": "arnType",
|
||||
"RoleSessionName": "roleSessionNameType",
|
||||
"WebIdentityToken": "clientTokenType",
|
||||
"ProviderId": "urlType",
|
||||
"PolicyArns": "policyDescriptorListType",
|
||||
"Policy": "sessionPolicyDocumentType",
|
||||
"DurationSeconds": "roleDurationSecondsType",
|
||||
"MinimumSessionTokenSize": "minimumSessionTokenSizeType"
|
||||
}
|
||||
},
|
||||
"AssumeRootRequest": {
|
||||
"type": "structure",
|
||||
"required": [
|
||||
"TargetPrincipal",
|
||||
"TaskPolicyArn"
|
||||
],
|
||||
"members": {
|
||||
"TargetPrincipal": "TargetPrincipalType",
|
||||
"TaskPolicyArn": "PolicyDescriptorType",
|
||||
"DurationSeconds": "RootDurationSecondsType",
|
||||
"MinimumSessionTokenSize": "minimumSessionTokenSizeType"
|
||||
}
|
||||
},
|
||||
"DecodeAuthorizationMessageRequest": {
|
||||
"type": "structure",
|
||||
"required": [
|
||||
"EncodedMessage"
|
||||
],
|
||||
"members": {
|
||||
"EncodedMessage": "encodedMessageType"
|
||||
}
|
||||
},
|
||||
"GetAccessKeyInfoRequest": {
|
||||
"type": "structure",
|
||||
"required": [
|
||||
@@ -18,6 +104,29 @@
|
||||
"AccessKeyId": "accessKeyIdType"
|
||||
}
|
||||
},
|
||||
"GetDelegatedAccessTokenRequest": {
|
||||
"type": "structure",
|
||||
"required": [
|
||||
"TradeInToken"
|
||||
],
|
||||
"members": {
|
||||
"TradeInToken": "tradeInTokenType"
|
||||
}
|
||||
},
|
||||
"GetFederationTokenRequest": {
|
||||
"type": "structure",
|
||||
"required": [
|
||||
"Name"
|
||||
],
|
||||
"members": {
|
||||
"Name": "userNameType",
|
||||
"Policy": "sessionPolicyDocumentType",
|
||||
"PolicyArns": "policyDescriptorListType",
|
||||
"DurationSeconds": "durationSecondsType",
|
||||
"Tags": "tagListType",
|
||||
"MinimumSessionTokenSize": "minimumSessionTokenSizeType"
|
||||
}
|
||||
},
|
||||
"GetSessionTokenRequest": {
|
||||
"type": "structure",
|
||||
"members": {
|
||||
@@ -40,6 +149,35 @@
|
||||
"Tags": "tagListType"
|
||||
}
|
||||
},
|
||||
"PolicyDescriptorType": {
|
||||
"type": "structure",
|
||||
"members": {
|
||||
"arn": "arnType"
|
||||
}
|
||||
},
|
||||
"ProvidedContext": {
|
||||
"type": "structure",
|
||||
"members": {
|
||||
"ProviderArn": "arnType",
|
||||
"ContextAssertion": "contextAssertionType"
|
||||
}
|
||||
},
|
||||
"ProvidedContextsListType": {
|
||||
"type": "list",
|
||||
"min": 1,
|
||||
"max": 5,
|
||||
"member": "ProvidedContext"
|
||||
},
|
||||
"RootDurationSecondsType": {
|
||||
"type": "integer",
|
||||
"min": 0,
|
||||
"max": 900
|
||||
},
|
||||
"SAMLAssertionType": {
|
||||
"type": "string",
|
||||
"min": 4,
|
||||
"max": 100000
|
||||
},
|
||||
"Tag": {
|
||||
"type": "structure",
|
||||
"required": [
|
||||
@@ -51,17 +189,49 @@
|
||||
"Value": "tagValueType"
|
||||
}
|
||||
},
|
||||
"TargetPrincipalType": {
|
||||
"type": "string",
|
||||
"min": 12,
|
||||
"max": 2048
|
||||
},
|
||||
"accessKeyIdType": {
|
||||
"type": "string",
|
||||
"min": 16,
|
||||
"max": 128,
|
||||
"pattern": "[\\w]*"
|
||||
},
|
||||
"arnType": {
|
||||
"type": "string",
|
||||
"min": 20,
|
||||
"max": 2048,
|
||||
"pattern": "[\\u0009\\u000A\\u000D\\u0020-\\u007E\\u0085\\u00A0-\\uD7FF\\uE000-\\uFFFD\\u10000-\\u10FFFF]+"
|
||||
},
|
||||
"clientTokenType": {
|
||||
"type": "string",
|
||||
"min": 4,
|
||||
"max": 20000
|
||||
},
|
||||
"contextAssertionType": {
|
||||
"type": "string",
|
||||
"min": 4,
|
||||
"max": 2048
|
||||
},
|
||||
"durationSecondsType": {
|
||||
"type": "integer",
|
||||
"min": 900,
|
||||
"max": 129600
|
||||
},
|
||||
"encodedMessageType": {
|
||||
"type": "string",
|
||||
"min": 1,
|
||||
"max": 10240
|
||||
},
|
||||
"externalIdType": {
|
||||
"type": "string",
|
||||
"min": 2,
|
||||
"max": 1224,
|
||||
"pattern": "[\\w+=,.@:\\/-]*"
|
||||
},
|
||||
"jwtAlgorithmType": {
|
||||
"type": "string",
|
||||
"min": 5,
|
||||
@@ -72,12 +242,44 @@
|
||||
"min": 0,
|
||||
"max": 4096
|
||||
},
|
||||
"policyDescriptorListType": {
|
||||
"type": "list",
|
||||
"member": "PolicyDescriptorType"
|
||||
},
|
||||
"roleDurationSecondsType": {
|
||||
"type": "integer",
|
||||
"min": 900,
|
||||
"max": 43200
|
||||
},
|
||||
"roleSessionNameType": {
|
||||
"type": "string",
|
||||
"min": 2,
|
||||
"max": 64,
|
||||
"pattern": "[\\w+=,.@-]*"
|
||||
},
|
||||
"serialNumberType": {
|
||||
"type": "string",
|
||||
"min": 9,
|
||||
"max": 256,
|
||||
"pattern": "[\\w+=/:,.@-]*"
|
||||
},
|
||||
"sessionPolicyDocumentType": {
|
||||
"type": "string",
|
||||
"min": 1,
|
||||
"max": 2048,
|
||||
"pattern": "[\\u0009\\u000A\\u000D\\u0020-\\u00FF]+"
|
||||
},
|
||||
"sourceIdentityType": {
|
||||
"type": "string",
|
||||
"min": 2,
|
||||
"max": 64,
|
||||
"pattern": "[\\w+=,.@-]*"
|
||||
},
|
||||
"tagKeyListType": {
|
||||
"type": "list",
|
||||
"max": 50,
|
||||
"member": "tagKeyType"
|
||||
},
|
||||
"tagKeyType": {
|
||||
"type": "string",
|
||||
"min": 1,
|
||||
@@ -101,6 +303,25 @@
|
||||
"max": 6,
|
||||
"pattern": "[\\d]*"
|
||||
},
|
||||
"tradeInTokenType": {
|
||||
"type": "string"
|
||||
},
|
||||
"unrestrictedSessionPolicyDocumentType": {
|
||||
"type": "string",
|
||||
"min": 1,
|
||||
"pattern": "[\\u0009\\u000A\\u000D\\u0020-\\u00FF]+"
|
||||
},
|
||||
"urlType": {
|
||||
"type": "string",
|
||||
"min": 4,
|
||||
"max": 2048
|
||||
},
|
||||
"userNameType": {
|
||||
"type": "string",
|
||||
"min": 2,
|
||||
"max": 32,
|
||||
"pattern": "[\\w+=,.@-]*"
|
||||
},
|
||||
"webIdentityTokenAudienceListType": {
|
||||
"type": "list",
|
||||
"min": 1,
|
||||
|
||||
+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"),
|
||||
|
||||
@@ -22,23 +22,26 @@ from request_shapes import REPO_ROOT
|
||||
OUTPUT = REPO_ROOT / "src/main/resources/aws/sts-request-shapes.json"
|
||||
MODEL = Path("sts/2011-06-15")
|
||||
|
||||
# One wave per group, each chosen so that no operation in it answers a declared constraint in a
|
||||
# wording of its own, which is what keeps the vendored shapes adding the refusals AWS answers
|
||||
# rather than rewording an answer already given.
|
||||
# Every operation STS models with a constraint of its own, which is all eleven but
|
||||
# `GetCallerIdentity`, whose request carries no member at all.
|
||||
#
|
||||
# `GetAccessKeyInfo` is the parity case: its hand-written check already answered `accessKeyId` in
|
||||
# `GetAccessKeyInfo` was the parity case: its hand-written check already answered `accessKeyId` in
|
||||
# Smithy's form, from the same bounds and the same pattern. `GetSessionToken` and
|
||||
# `GetWebIdentityToken` are the first read through the list walk. `SerialNumber`, `TokenCode` and
|
||||
# `MinimumSessionTokenSize` are read by nothing at all today, and the audience and tag checks the
|
||||
# token operation carried by hand named their members the way this file's walk does.
|
||||
#
|
||||
# The seven that are left all answer an absent member through `validateRequired`, which names the
|
||||
# parameter as the request writes it rather than as a constraint message spells it, so taking one
|
||||
# over rewords an answer already merged.
|
||||
# `GetWebIdentityToken` came next, for members read by nothing at all. The seven below answered an
|
||||
# absent member through `validateRequired`, which named the parameter as the request writes it and
|
||||
# read a blank value as an absent one, so taking them over rewords those answers onto the form the
|
||||
# model and the rest of this package give, which is what `docs/services/sts.md` records.
|
||||
OPERATIONS = (
|
||||
"GetAccessKeyInfo",
|
||||
"GetSessionToken",
|
||||
"GetWebIdentityToken",
|
||||
"AssumeRole",
|
||||
"AssumeRoleWithSAML",
|
||||
"AssumeRoleWithWebIdentity",
|
||||
"AssumeRoot",
|
||||
"DecodeAuthorizationMessage",
|
||||
"GetDelegatedAccessToken",
|
||||
"GetFederationToken",
|
||||
)
|
||||
|
||||
|
||||
|
||||
Reference in new issue
Block a user