fix(organizations): refuse a request member of the wrong JSON type (#8141)

The Organizations handler read each member with asText, asInt or path,
so a Tags that isn't a list was read as no tags, a number where a
string belongs as its text, and a string MaxResults as a number.

Vendor botocore's Organizations request shapes with
tools/aws/regen_organizations_shapes.py, kept in sync by make
aws-data-check. Once the switch in handle finds a served operation,
walk the request against that operation's input shape with
RequestShapeCheck before the operation reads it, as Rekognition's
handler does. An operation Floci doesn't serve still answers
UnknownOperationException, whatever its body.

A mismatch is a SerializationException worded as DynamoDB's
deserializer words it. Organizations' own error and wording haven't
been measured.

The tag checks parseTags already makes still run: a null member counts
as absent in the walk, so a null or missing Key or Value and a repeated
key keep their InvalidInputException.
This commit is contained in:
soreavis authored and GitHub committed 2026-11-12 16:10:12 -04:00
1 parent 81894c545d
commit 9ead504085
9 files changed
+891 -64

No files matched your search

+9
View File
@@ -23,6 +23,8 @@
# model by tools/aws/regen_apigateway_shapes.py.
# src/main/resources/aws/ecs-request-shapes.json is generated from botocore's ECS model
# by tools/aws/regen_ecs_shapes.py.
# src/main/resources/aws/organizations-request-shapes.json is generated from botocore's Organizations
# model by tools/aws/regen_organizations_shapes.py.
# src/main/resources/aws/ecr-request-shapes.json, the ECR request constraints, is generated
# from botocore's ECR model by tools/aws/regen_ecr_shapes.py.
# Athena request constraints for every operation are generated from botocore's Athena model
@@ -302,6 +304,7 @@ aws-data-sync-botocore: ## Regenerate only the AWS data derived from botocore, s
$(PYTHON) tools/aws/regen_apigateway_shapes.py
$(PYTHON) tools/aws/regen_apigateway_documentation_shapes.py
$(PYTHON) tools/aws/regen_ecs_shapes.py
$(PYTHON) tools/aws/regen_organizations_shapes.py
$(PYTHON) tools/aws/regen_emr_serverless_shapes.py
$(PYTHON) tools/aws/regen_query_services.py
$(PYTHON) tools/aws/regen_rest_routes.py
@@ -454,6 +457,12 @@ aws-data-check-botocore: ## The AWS data derived from botocore must match a fres
echo " Run 'make aws-data-sync' and commit the result."; \
exit 1; \
}
@$(PYTHON) tools/aws/regen_organizations_shapes.py --check || { \
echo ""; \
echo "error: src/main/resources/aws/organizations-request-shapes.json is out of date."; \
echo " Run 'make aws-data-sync' and commit the result."; \
exit 1; \
}
@$(PYTHON) tools/aws/regen_emr_serverless_shapes.py --check || { \
echo ""; \
echo "error: src/main/resources/aws/emr-serverless-shapes.json is out of date."; \
+7
View File
@@ -71,6 +71,13 @@ call `LeaveOrganization`. An account in no organization gets
- `DescribeEffectivePolicy` merges every policy of the requested type down the
root → OU → target chain, with the closest ancestor winning on conflicting keys. As on AWS,
the access-control types (`SERVICE_CONTROL_POLICY`, `RESOURCE_CONTROL_POLICY`) are rejected.
- A request member of the wrong JSON type, such as a `Tags` that is not a list or a string
`MaxResults`, fails with `SerializationException` before the operation runs, worded as DynamoDB's
deserializer words it (`Unexpected field type`, `STRING_VALUE cannot be converted to Integer`);
Organizations' own error and wording have not been measured. The request shapes are vendored in
`src/main/resources/aws/organizations-request-shapes.json`, generated by
`tools/aws/regen_organizations_shapes.py` from the botocore release pinned in
`tools/aws/requirements.txt`.
- Handshakes expire 15 days after they are created and report `EXPIRED` from then on.
- Organizations ARNs are global and carry no region:
`arn:aws:organizations::123456789012:organization/o-abc1234567`.
@@ -31,6 +31,7 @@ import java.util.LinkedHashMap;
import java.util.List;
import java.util.Map;
import java.util.function.Function;
import java.util.function.Supplier;
/**
* AWS Organizations JSON 1.1 handler. Dispatched from
@@ -63,68 +64,76 @@ public class OrganizationsJsonHandler {
public Response handle(String action, JsonNode request, String callerAccountId) {
LOG.debugv("Organizations action: {0}", action);
try {
return switch (action) {
case "CreateOrganization" -> createOrganization(request, callerAccountId);
case "DescribeOrganization" -> describeOrganization(callerAccountId);
case "DeleteOrganization" -> deleteOrganization(callerAccountId);
case "EnableAllFeatures" -> enableAllFeatures(callerAccountId);
case "ListRoots" -> listRoots(request, callerAccountId);
case "CreateOrganizationalUnit" -> createOrganizationalUnit(request, callerAccountId);
case "UpdateOrganizationalUnit" -> updateOrganizationalUnit(request, callerAccountId);
case "DeleteOrganizationalUnit" -> deleteOrganizationalUnit(request, callerAccountId);
case "DescribeOrganizationalUnit" -> describeOrganizationalUnit(request, callerAccountId);
case "ListOrganizationalUnitsForParent" -> listOrganizationalUnitsForParent(request, callerAccountId);
case "ListParents" -> listParents(request, callerAccountId);
case "ListChildren" -> listChildren(request, callerAccountId);
case "CreateAccount" -> createAccount(request, callerAccountId, false);
case "CreateGovCloudAccount" -> createAccount(request, callerAccountId, true);
case "DescribeCreateAccountStatus" -> describeCreateAccountStatus(request, callerAccountId);
case "ListCreateAccountStatus" -> listCreateAccountStatus(request, callerAccountId);
case "DescribeAccount" -> describeAccount(request, callerAccountId);
case "ListAccounts" -> listAccounts(request, callerAccountId);
case "ListAccountsForParent" -> listAccountsForParent(request, callerAccountId);
Supplier<Response> operation = switch (action) {
case "CreateOrganization" -> () -> createOrganization(request, callerAccountId);
case "DescribeOrganization" -> () -> describeOrganization(callerAccountId);
case "DeleteOrganization" -> () -> deleteOrganization(callerAccountId);
case "EnableAllFeatures" -> () -> enableAllFeatures(callerAccountId);
case "ListRoots" -> () -> listRoots(request, callerAccountId);
case "CreateOrganizationalUnit" -> () -> createOrganizationalUnit(request, callerAccountId);
case "UpdateOrganizationalUnit" -> () -> updateOrganizationalUnit(request, callerAccountId);
case "DeleteOrganizationalUnit" -> () -> deleteOrganizationalUnit(request, callerAccountId);
case "DescribeOrganizationalUnit" -> () -> describeOrganizationalUnit(request, callerAccountId);
case "ListOrganizationalUnitsForParent" ->
() -> listOrganizationalUnitsForParent(request, callerAccountId);
case "ListParents" -> () -> listParents(request, callerAccountId);
case "ListChildren" -> () -> listChildren(request, callerAccountId);
case "CreateAccount" -> () -> createAccount(request, callerAccountId, false);
case "CreateGovCloudAccount" -> () -> createAccount(request, callerAccountId, true);
case "DescribeCreateAccountStatus" -> () -> describeCreateAccountStatus(request, callerAccountId);
case "ListCreateAccountStatus" -> () -> listCreateAccountStatus(request, callerAccountId);
case "DescribeAccount" -> () -> describeAccount(request, callerAccountId);
case "ListAccounts" -> () -> listAccounts(request, callerAccountId);
case "ListAccountsForParent" -> () -> listAccountsForParent(request, callerAccountId);
case "ListAccountsWithInvalidEffectivePolicy" ->
listAccountsWithInvalidEffectivePolicy(request, callerAccountId);
case "MoveAccount" -> moveAccount(request, callerAccountId);
case "RemoveAccountFromOrganization" -> removeAccountFromOrganization(request, callerAccountId);
case "LeaveOrganization" -> leaveOrganization(callerAccountId);
case "CloseAccount" -> closeAccount(request, callerAccountId);
case "CreatePolicy" -> createPolicy(request, callerAccountId);
case "UpdatePolicy" -> updatePolicy(request, callerAccountId);
case "DeletePolicy" -> deletePolicy(request, callerAccountId);
case "DescribePolicy" -> describePolicy(request, callerAccountId);
case "ListPolicies" -> listPolicies(request, callerAccountId);
case "AttachPolicy" -> attachPolicy(request, callerAccountId);
case "DetachPolicy" -> detachPolicy(request, callerAccountId);
case "ListPoliciesForTarget" -> listPoliciesForTarget(request, callerAccountId);
case "ListTargetsForPolicy" -> listTargetsForPolicy(request, callerAccountId);
case "EnablePolicyType" -> enablePolicyType(request, callerAccountId);
case "DisablePolicyType" -> disablePolicyType(request, callerAccountId);
case "DescribeEffectivePolicy" -> describeEffectivePolicy(request, callerAccountId);
case "TagResource" -> tagResource(request, callerAccountId);
case "UntagResource" -> untagResource(request, callerAccountId);
case "ListTagsForResource" -> listTagsForResource(request, callerAccountId);
case "EnableAWSServiceAccess" -> enableAwsServiceAccess(request, callerAccountId);
case "DisableAWSServiceAccess" -> disableAwsServiceAccess(request, callerAccountId);
() -> listAccountsWithInvalidEffectivePolicy(request, callerAccountId);
case "MoveAccount" -> () -> moveAccount(request, callerAccountId);
case "RemoveAccountFromOrganization" -> () -> removeAccountFromOrganization(request, callerAccountId);
case "LeaveOrganization" -> () -> leaveOrganization(callerAccountId);
case "CloseAccount" -> () -> closeAccount(request, callerAccountId);
case "CreatePolicy" -> () -> createPolicy(request, callerAccountId);
case "UpdatePolicy" -> () -> updatePolicy(request, callerAccountId);
case "DeletePolicy" -> () -> deletePolicy(request, callerAccountId);
case "DescribePolicy" -> () -> describePolicy(request, callerAccountId);
case "ListPolicies" -> () -> listPolicies(request, callerAccountId);
case "AttachPolicy" -> () -> attachPolicy(request, callerAccountId);
case "DetachPolicy" -> () -> detachPolicy(request, callerAccountId);
case "ListPoliciesForTarget" -> () -> listPoliciesForTarget(request, callerAccountId);
case "ListTargetsForPolicy" -> () -> listTargetsForPolicy(request, callerAccountId);
case "EnablePolicyType" -> () -> enablePolicyType(request, callerAccountId);
case "DisablePolicyType" -> () -> disablePolicyType(request, callerAccountId);
case "DescribeEffectivePolicy" -> () -> describeEffectivePolicy(request, callerAccountId);
case "TagResource" -> () -> tagResource(request, callerAccountId);
case "UntagResource" -> () -> untagResource(request, callerAccountId);
case "ListTagsForResource" -> () -> listTagsForResource(request, callerAccountId);
case "EnableAWSServiceAccess" -> () -> enableAwsServiceAccess(request, callerAccountId);
case "DisableAWSServiceAccess" -> () -> disableAwsServiceAccess(request, callerAccountId);
case "ListAWSServiceAccessForOrganization" ->
listAwsServiceAccessForOrganization(request, callerAccountId);
case "RegisterDelegatedAdministrator" -> registerDelegatedAdministrator(request, callerAccountId);
case "DeregisterDelegatedAdministrator" -> deregisterDelegatedAdministrator(request, callerAccountId);
case "ListDelegatedAdministrators" -> listDelegatedAdministrators(request, callerAccountId);
case "ListDelegatedServicesForAccount" -> listDelegatedServicesForAccount(request, callerAccountId);
case "PutResourcePolicy" -> putResourcePolicy(request, callerAccountId);
case "DescribeResourcePolicy" -> describeResourcePolicy(callerAccountId);
case "DeleteResourcePolicy" -> deleteResourcePolicy(callerAccountId);
case "InviteAccountToOrganization" -> inviteAccountToOrganization(request, callerAccountId);
case "AcceptHandshake" -> acceptHandshake(request, callerAccountId);
case "DeclineHandshake" -> declineHandshake(request, callerAccountId);
case "CancelHandshake" -> cancelHandshake(request, callerAccountId);
case "DescribeHandshake" -> describeHandshake(request, callerAccountId);
case "ListHandshakesForAccount" -> listHandshakesForAccount(request, callerAccountId);
case "ListHandshakesForOrganization" -> listHandshakesForOrganization(request, callerAccountId);
default -> JsonErrorResponseUtils.createUnknownOperationErrorResponse(
"AWSOrganizationsV20161128." + action);
() -> listAwsServiceAccessForOrganization(request, callerAccountId);
case "RegisterDelegatedAdministrator" -> () -> registerDelegatedAdministrator(request, callerAccountId);
case "DeregisterDelegatedAdministrator" ->
() -> deregisterDelegatedAdministrator(request, callerAccountId);
case "ListDelegatedAdministrators" -> () -> listDelegatedAdministrators(request, callerAccountId);
case "ListDelegatedServicesForAccount" ->
() -> listDelegatedServicesForAccount(request, callerAccountId);
case "PutResourcePolicy" -> () -> putResourcePolicy(request, callerAccountId);
case "DescribeResourcePolicy" -> () -> describeResourcePolicy(callerAccountId);
case "DeleteResourcePolicy" -> () -> deleteResourcePolicy(callerAccountId);
case "InviteAccountToOrganization" -> () -> inviteAccountToOrganization(request, callerAccountId);
case "AcceptHandshake" -> () -> acceptHandshake(request, callerAccountId);
case "DeclineHandshake" -> () -> declineHandshake(request, callerAccountId);
case "CancelHandshake" -> () -> cancelHandshake(request, callerAccountId);
case "DescribeHandshake" -> () -> describeHandshake(request, callerAccountId);
case "ListHandshakesForAccount" -> () -> listHandshakesForAccount(request, callerAccountId);
case "ListHandshakesForOrganization" -> () -> listHandshakesForOrganization(request, callerAccountId);
default -> null;
};
if (operation == null) {
return JsonErrorResponseUtils.createUnknownOperationErrorResponse(
"AWSOrganizationsV20161128." + action);
}
OrganizationsRequestShapes.check(action, request);
return operation.get();
} catch (AwsException e) {
return JsonErrorResponseUtils.createErrorResponse(e);
} catch (Exception e) {
@@ -0,0 +1,54 @@
package io.floci.aws.services.organizations;
import com.fasterxml.jackson.databind.JsonNode;
import io.floci.aws.core.common.RequestShapeCheck;
import io.floci.aws.core.common.RequestShapeCheck.ByPosition;
import io.floci.aws.core.common.RequestShapeModel;
import java.util.Set;
/**
* Rejects an Organizations request member of the wrong JSON type before the operation reads it. The
* input shapes come from the vendored {@code aws/organizations-request-shapes.json}, generated from
* botocore's Organizations model by {@code tools/aws/regen_organizations_shapes.py}, and are walked by
* {@link RequestShapeCheck}.
*
* <p>Organizations' own answers have not been measured. The SerializationException and its wording are
* those DynamoDB's deserializer gives, and the JSON 1.1 dispatcher already answers a body that is not a
* JSON object with a SerializationException. Only strings and integers are checked, the only scalars in
* the requests of the operations Floci serves.
*/
final class OrganizationsRequestShapes {
private static final String UNKNOWN_ERROR = "UnknownError";
private static final ByPosition SCALAR_FOR_CONTAINER = new ByPosition("Unexpected field type", UNKNOWN_ERROR);
private static final RequestShapeCheck.Messages MESSAGES = new RequestShapeCheck.Messages(
"SerializationException",
"Start of structure or map found where not expected",
UNKNOWN_ERROR,
new ByPosition("Unexpected field type", "Unexpected value type in payload"),
SCALAR_FOR_CONTAINER,
SCALAR_FOR_CONTAINER,
"%s cannot be converted to %s",
true,
null,
null,
Set.of("string", "integer"));
private static final class Holder {
static final RequestShapeModel MODEL =
RequestShapeModel.load("aws/organizations-request-shapes.json", "Organizations request shapes");
}
private OrganizationsRequestShapes() {
}
/** Checks a request body against the input shape of {@code operation}, if the operation takes input. */
static void check(String operation, JsonNode request) {
String input = Holder.MODEL.operations().get(operation);
if (input != null) {
RequestShapeCheck.check(Holder.MODEL, input, request, MESSAGES);
}
}
}
@@ -0,0 +1,637 @@
{
"_source": {
"generator": "tools/aws/regen_organizations_shapes.py",
"botocore": "botocore 1.43.118 (installed package)"
},
"operations": {
"AcceptHandshake": "AcceptHandshakeRequest",
"AttachPolicy": "AttachPolicyRequest",
"CancelHandshake": "CancelHandshakeRequest",
"CloseAccount": "CloseAccountRequest",
"CreateAccount": "CreateAccountRequest",
"CreateGovCloudAccount": "CreateGovCloudAccountRequest",
"CreateOrganization": "CreateOrganizationRequest",
"CreateOrganizationalUnit": "CreateOrganizationalUnitRequest",
"CreatePolicy": "CreatePolicyRequest",
"DeclineHandshake": "DeclineHandshakeRequest",
"DeleteOrganizationalUnit": "DeleteOrganizationalUnitRequest",
"DeletePolicy": "DeletePolicyRequest",
"DeregisterDelegatedAdministrator": "DeregisterDelegatedAdministratorRequest",
"DescribeAccount": "DescribeAccountRequest",
"DescribeCreateAccountStatus": "DescribeCreateAccountStatusRequest",
"DescribeEffectivePolicy": "DescribeEffectivePolicyRequest",
"DescribeHandshake": "DescribeHandshakeRequest",
"DescribeOrganizationalUnit": "DescribeOrganizationalUnitRequest",
"DescribePolicy": "DescribePolicyRequest",
"DescribeResponsibilityTransfer": "DescribeResponsibilityTransferRequest",
"DetachPolicy": "DetachPolicyRequest",
"DisableAWSServiceAccess": "DisableAWSServiceAccessRequest",
"DisablePolicyType": "DisablePolicyTypeRequest",
"EnableAWSServiceAccess": "EnableAWSServiceAccessRequest",
"EnableAllFeatures": "EnableAllFeaturesRequest",
"EnablePolicyType": "EnablePolicyTypeRequest",
"InviteAccountToOrganization": "InviteAccountToOrganizationRequest",
"InviteOrganizationToTransferResponsibility": "InviteOrganizationToTransferResponsibilityRequest",
"ListAWSServiceAccessForOrganization": "ListAWSServiceAccessForOrganizationRequest",
"ListAccounts": "ListAccountsRequest",
"ListAccountsForParent": "ListAccountsForParentRequest",
"ListAccountsWithInvalidEffectivePolicy": "ListAccountsWithInvalidEffectivePolicyRequest",
"ListChildren": "ListChildrenRequest",
"ListCreateAccountStatus": "ListCreateAccountStatusRequest",
"ListDelegatedAdministrators": "ListDelegatedAdministratorsRequest",
"ListDelegatedServicesForAccount": "ListDelegatedServicesForAccountRequest",
"ListEffectivePolicyValidationErrors": "ListEffectivePolicyValidationErrorsRequest",
"ListHandshakesForAccount": "ListHandshakesForAccountRequest",
"ListHandshakesForOrganization": "ListHandshakesForOrganizationRequest",
"ListInboundResponsibilityTransfers": "ListInboundResponsibilityTransfersRequest",
"ListOrganizationalUnitsForParent": "ListOrganizationalUnitsForParentRequest",
"ListOutboundResponsibilityTransfers": "ListOutboundResponsibilityTransfersRequest",
"ListParents": "ListParentsRequest",
"ListPolicies": "ListPoliciesRequest",
"ListPoliciesForTarget": "ListPoliciesForTargetRequest",
"ListRoots": "ListRootsRequest",
"ListTagsForResource": "ListTagsForResourceRequest",
"ListTargetsForPolicy": "ListTargetsForPolicyRequest",
"MoveAccount": "MoveAccountRequest",
"PutResourcePolicy": "PutResourcePolicyRequest",
"RegisterDelegatedAdministrator": "RegisterDelegatedAdministratorRequest",
"RemoveAccountFromOrganization": "RemoveAccountFromOrganizationRequest",
"TagResource": "TagResourceRequest",
"TerminateResponsibilityTransfer": "TerminateResponsibilityTransferRequest",
"UntagResource": "UntagResourceRequest",
"UpdateOrganizationalUnit": "UpdateOrganizationalUnitRequest",
"UpdatePolicy": "UpdatePolicyRequest",
"UpdateResponsibilityTransfer": "UpdateResponsibilityTransferRequest"
},
"shapes": {
"AcceptHandshakeRequest": {
"type": "structure",
"members": {
"HandshakeId": "HandshakeId"
}
},
"AccountId": {
"type": "string"
},
"ActionType": {
"type": "string"
},
"AttachPolicyRequest": {
"type": "structure",
"members": {
"PolicyId": "PolicyId",
"TargetId": "PolicyTargetId"
}
},
"CancelHandshakeRequest": {
"type": "structure",
"members": {
"HandshakeId": "HandshakeId"
}
},
"ChildId": {
"type": "string"
},
"ChildType": {
"type": "string"
},
"CloseAccountRequest": {
"type": "structure",
"members": {
"AccountId": "AccountId"
}
},
"CreateAccountName": {
"type": "string"
},
"CreateAccountRequest": {
"type": "structure",
"members": {
"Email": "Email",
"AccountName": "CreateAccountName",
"RoleName": "RoleName",
"IamUserAccessToBilling": "IAMUserAccessToBilling",
"Tags": "Tags"
}
},
"CreateAccountRequestId": {
"type": "string"
},
"CreateAccountState": {
"type": "string"
},
"CreateAccountStates": {
"type": "list",
"member": "CreateAccountState"
},
"CreateGovCloudAccountRequest": {
"type": "structure",
"members": {
"Email": "Email",
"AccountName": "CreateAccountName",
"RoleName": "RoleName",
"IamUserAccessToBilling": "IAMUserAccessToBilling",
"Tags": "Tags"
}
},
"CreateOrganizationRequest": {
"type": "structure",
"members": {
"FeatureSet": "OrganizationFeatureSet"
}
},
"CreateOrganizationalUnitRequest": {
"type": "structure",
"members": {
"ParentId": "ParentId",
"Name": "OrganizationalUnitName",
"Tags": "Tags"
}
},
"CreatePolicyRequest": {
"type": "structure",
"members": {
"Content": "PolicyContent",
"Description": "PolicyDescription",
"Name": "PolicyName",
"Type": "PolicyType",
"Tags": "Tags"
}
},
"DeclineHandshakeRequest": {
"type": "structure",
"members": {
"HandshakeId": "HandshakeId"
}
},
"DeleteOrganizationalUnitRequest": {
"type": "structure",
"members": {
"OrganizationalUnitId": "OrganizationalUnitId"
}
},
"DeletePolicyRequest": {
"type": "structure",
"members": {
"PolicyId": "PolicyId"
}
},
"DeregisterDelegatedAdministratorRequest": {
"type": "structure",
"members": {
"AccountId": "AccountId",
"ServicePrincipal": "ServicePrincipal"
}
},
"DescribeAccountRequest": {
"type": "structure",
"members": {
"AccountId": "AccountId"
}
},
"DescribeCreateAccountStatusRequest": {
"type": "structure",
"members": {
"CreateAccountRequestId": "CreateAccountRequestId"
}
},
"DescribeEffectivePolicyRequest": {
"type": "structure",
"members": {
"PolicyType": "EffectivePolicyType",
"TargetId": "PolicyTargetId"
}
},
"DescribeHandshakeRequest": {
"type": "structure",
"members": {
"HandshakeId": "HandshakeId"
}
},
"DescribeOrganizationalUnitRequest": {
"type": "structure",
"members": {
"OrganizationalUnitId": "OrganizationalUnitId"
}
},
"DescribePolicyRequest": {
"type": "structure",
"members": {
"PolicyId": "PolicyId"
}
},
"DescribeResponsibilityTransferRequest": {
"type": "structure",
"members": {
"Id": "ResponsibilityTransferId"
}
},
"DetachPolicyRequest": {
"type": "structure",
"members": {
"PolicyId": "PolicyId",
"TargetId": "PolicyTargetId"
}
},
"DisableAWSServiceAccessRequest": {
"type": "structure",
"members": {
"ServicePrincipal": "ServicePrincipal"
}
},
"DisablePolicyTypeRequest": {
"type": "structure",
"members": {
"RootId": "RootId",
"PolicyType": "PolicyType"
}
},
"EffectivePolicyType": {
"type": "string"
},
"Email": {
"type": "string"
},
"EnableAWSServiceAccessRequest": {
"type": "structure",
"members": {
"ServicePrincipal": "ServicePrincipal"
}
},
"EnableAllFeaturesRequest": {
"type": "structure",
"members": {}
},
"EnablePolicyTypeRequest": {
"type": "structure",
"members": {
"RootId": "RootId",
"PolicyType": "PolicyType"
}
},
"HandshakeFilter": {
"type": "structure",
"members": {
"ActionType": "ActionType",
"ParentHandshakeId": "HandshakeId"
}
},
"HandshakeId": {
"type": "string"
},
"HandshakeNotes": {
"type": "string"
},
"HandshakeParty": {
"type": "structure",
"members": {
"Id": "HandshakePartyId",
"Type": "HandshakePartyType"
}
},
"HandshakePartyId": {
"type": "string"
},
"HandshakePartyType": {
"type": "string"
},
"IAMUserAccessToBilling": {
"type": "string"
},
"InviteAccountToOrganizationRequest": {
"type": "structure",
"members": {
"Target": "HandshakeParty",
"Notes": "HandshakeNotes",
"Tags": "Tags"
}
},
"InviteOrganizationToTransferResponsibilityRequest": {
"type": "structure",
"members": {
"Type": "ResponsibilityTransferType",
"Target": "HandshakeParty",
"Notes": "HandshakeNotes",
"StartTimestamp": "Timestamp",
"SourceName": "ResponsibilityTransferName",
"Tags": "Tags"
}
},
"ListAWSServiceAccessForOrganizationRequest": {
"type": "structure",
"members": {
"NextToken": "NextToken",
"MaxResults": "MaxResults"
}
},
"ListAccountsForParentRequest": {
"type": "structure",
"members": {
"ParentId": "ParentId",
"NextToken": "NextToken",
"MaxResults": "MaxResults"
}
},
"ListAccountsRequest": {
"type": "structure",
"members": {
"NextToken": "NextToken",
"MaxResults": "MaxResults"
}
},
"ListAccountsWithInvalidEffectivePolicyRequest": {
"type": "structure",
"members": {
"PolicyType": "EffectivePolicyType",
"NextToken": "NextToken",
"MaxResults": "MaxResults"
}
},
"ListChildrenRequest": {
"type": "structure",
"members": {
"ParentId": "ParentId",
"ChildType": "ChildType",
"NextToken": "NextToken",
"MaxResults": "MaxResults"
}
},
"ListCreateAccountStatusRequest": {
"type": "structure",
"members": {
"States": "CreateAccountStates",
"NextToken": "NextToken",
"MaxResults": "MaxResults"
}
},
"ListDelegatedAdministratorsRequest": {
"type": "structure",
"members": {
"ServicePrincipal": "ServicePrincipal",
"NextToken": "NextToken",
"MaxResults": "MaxResults"
}
},
"ListDelegatedServicesForAccountRequest": {
"type": "structure",
"members": {
"AccountId": "AccountId",
"NextToken": "NextToken",
"MaxResults": "MaxResults"
}
},
"ListEffectivePolicyValidationErrorsRequest": {
"type": "structure",
"members": {
"AccountId": "AccountId",
"PolicyType": "EffectivePolicyType",
"NextToken": "NextToken",
"MaxResults": "MaxResults"
}
},
"ListHandshakesForAccountRequest": {
"type": "structure",
"members": {
"Filter": "HandshakeFilter",
"NextToken": "NextToken",
"MaxResults": "MaxResults"
}
},
"ListHandshakesForOrganizationRequest": {
"type": "structure",
"members": {
"Filter": "HandshakeFilter",
"NextToken": "NextToken",
"MaxResults": "MaxResults"
}
},
"ListInboundResponsibilityTransfersRequest": {
"type": "structure",
"members": {
"Type": "ResponsibilityTransferType",
"Id": "ResponsibilityTransferId",
"NextToken": "NextToken",
"MaxResults": "MaxResults"
}
},
"ListOrganizationalUnitsForParentRequest": {
"type": "structure",
"members": {
"ParentId": "ParentId",
"NextToken": "NextToken",
"MaxResults": "MaxResults"
}
},
"ListOutboundResponsibilityTransfersRequest": {
"type": "structure",
"members": {
"Type": "ResponsibilityTransferType",
"NextToken": "NextToken",
"MaxResults": "MaxResults"
}
},
"ListParentsRequest": {
"type": "structure",
"members": {
"ChildId": "ChildId",
"NextToken": "NextToken",
"MaxResults": "MaxResults"
}
},
"ListPoliciesForTargetRequest": {
"type": "structure",
"members": {
"TargetId": "PolicyTargetId",
"Filter": "PolicyType",
"NextToken": "NextToken",
"MaxResults": "MaxResults"
}
},
"ListPoliciesRequest": {
"type": "structure",
"members": {
"Filter": "PolicyType",
"NextToken": "NextToken",
"MaxResults": "MaxResults"
}
},
"ListRootsRequest": {
"type": "structure",
"members": {
"NextToken": "NextToken",
"MaxResults": "MaxResults"
}
},
"ListTagsForResourceRequest": {
"type": "structure",
"members": {
"ResourceId": "TaggableResourceId",
"NextToken": "NextToken"
}
},
"ListTargetsForPolicyRequest": {
"type": "structure",
"members": {
"PolicyId": "PolicyId",
"NextToken": "NextToken",
"MaxResults": "MaxResults"
}
},
"MaxResults": {
"type": "integer"
},
"MoveAccountRequest": {
"type": "structure",
"members": {
"AccountId": "AccountId",
"SourceParentId": "ParentId",
"DestinationParentId": "ParentId"
}
},
"NextToken": {
"type": "string"
},
"OrganizationFeatureSet": {
"type": "string"
},
"OrganizationalUnitId": {
"type": "string"
},
"OrganizationalUnitName": {
"type": "string"
},
"ParentId": {
"type": "string"
},
"PolicyContent": {
"type": "string"
},
"PolicyDescription": {
"type": "string"
},
"PolicyId": {
"type": "string"
},
"PolicyName": {
"type": "string"
},
"PolicyTargetId": {
"type": "string"
},
"PolicyType": {
"type": "string"
},
"PutResourcePolicyRequest": {
"type": "structure",
"members": {
"Content": "ResourcePolicyContent",
"Tags": "Tags"
}
},
"RegisterDelegatedAdministratorRequest": {
"type": "structure",
"members": {
"AccountId": "AccountId",
"ServicePrincipal": "ServicePrincipal"
}
},
"RemoveAccountFromOrganizationRequest": {
"type": "structure",
"members": {
"AccountId": "AccountId"
}
},
"ResourcePolicyContent": {
"type": "string"
},
"ResponsibilityTransferId": {
"type": "string"
},
"ResponsibilityTransferName": {
"type": "string"
},
"ResponsibilityTransferType": {
"type": "string"
},
"RoleName": {
"type": "string"
},
"RootId": {
"type": "string"
},
"ServicePrincipal": {
"type": "string"
},
"Tag": {
"type": "structure",
"members": {
"Key": "TagKey",
"Value": "TagValue"
}
},
"TagKey": {
"type": "string"
},
"TagKeys": {
"type": "list",
"member": "TagKey"
},
"TagResourceRequest": {
"type": "structure",
"members": {
"ResourceId": "TaggableResourceId",
"Tags": "Tags"
}
},
"TagValue": {
"type": "string"
},
"TaggableResourceId": {
"type": "string"
},
"Tags": {
"type": "list",
"member": "Tag"
},
"TerminateResponsibilityTransferRequest": {
"type": "structure",
"members": {
"Id": "ResponsibilityTransferId",
"EndTimestamp": "Timestamp"
}
},
"Timestamp": {
"type": "timestamp"
},
"UntagResourceRequest": {
"type": "structure",
"members": {
"ResourceId": "TaggableResourceId",
"TagKeys": "TagKeys"
}
},
"UpdateOrganizationalUnitRequest": {
"type": "structure",
"members": {
"OrganizationalUnitId": "OrganizationalUnitId",
"Name": "OrganizationalUnitName"
}
},
"UpdatePolicyRequest": {
"type": "structure",
"members": {
"PolicyId": "PolicyId",
"Name": "PolicyName",
"Description": "PolicyDescription",
"Content": "PolicyContent"
}
},
"UpdateResponsibilityTransferRequest": {
"type": "structure",
"members": {
"Id": "ResponsibilityTransferId",
"Name": "ResponsibilityTransferName"
}
}
}
}
@@ -3,17 +3,21 @@ package io.floci.aws.services.organizations;
import com.fasterxml.jackson.databind.JsonNode;
import com.fasterxml.jackson.databind.ObjectMapper;
import io.floci.aws.core.common.AwsErrorResponse;
import io.floci.aws.core.common.AwsException;
import io.floci.aws.core.common.RegionResolver;
import io.floci.aws.core.storage.AccountAwareStorageBackend;
import jakarta.ws.rs.core.Response;
import org.junit.jupiter.api.BeforeEach;
import org.junit.jupiter.api.Test;
import org.junit.jupiter.params.ParameterizedTest;
import org.junit.jupiter.params.provider.CsvSource;
import org.junit.jupiter.params.provider.ValueSource;
import java.util.List;
import java.util.Map;
import static org.junit.jupiter.api.Assertions.assertEquals;
import static org.junit.jupiter.api.Assertions.assertThrows;
class OrganizationsJsonHandlerTest {
@@ -95,6 +99,75 @@ class OrganizationsJsonHandlerTest {
assertEquals(Map.of(), service.listTagsForResource(OWNER, root));
}
@ParameterizedTest
@CsvSource(delimiter = '|', value = {
"\"team=red\"|Unexpected field type",
"{\"Key\":\"team\",\"Value\":\"red\"}|Start of structure or map found where not expected"})
void tagsThatAreNotAListFailEveryTaggedOperation(String tags, String message) throws Exception {
service.enablePolicyType(OWNER, root, "SERVICE_CONTROL_POLICY");
Map<String, String> requests = Map.of(
"CreateOrganizationalUnit", "\"ParentId\":\"" + root + "\",\"Name\":\"Unit\"",
"CreateAccount", "\"Email\":\"tagged@example.test\",\"AccountName\":\"Tagged\"",
"CreateGovCloudAccount", "\"Email\":\"gov@example.test\",\"AccountName\":\"Gov\"",
"CreatePolicy", "\"Content\":\"{}\",\"Name\":\"Policy\",\"Type\":\"SERVICE_CONTROL_POLICY\"",
"TagResource", "\"ResourceId\":\"" + root + "\"",
"PutResourcePolicy", "\"Content\":\"{}\"",
"InviteAccountToOrganization", "\"Target\":{\"Id\":\"" + INVITEE + "\",\"Type\":\"ACCOUNT\"}");
for (Map.Entry<String, String> request : requests.entrySet()) {
assertRefused(request.getKey(), "{" + request.getValue() + ",\"Tags\":" + tags + "}", message);
}
assertEquals(List.of(), service.listOrganizationalUnitsForParent(OWNER, root));
assertEquals(List.of(), service.listCreateAccountStatus(OWNER, null));
assertEquals(1, service.listPolicies(OWNER, "SERVICE_CONTROL_POLICY").size());
assertEquals(Map.of(), service.listTagsForResource(OWNER, root));
assertThrows(AwsException.class, () -> service.describeResourcePolicy(OWNER));
assertEquals(List.of(), service.listHandshakesForOrganization(OWNER, null, null));
}
@ParameterizedTest
@CsvSource(delimiter = '|', value = {
"DescribeAccount|{\"AccountId\":100623600101}|NUMBER_VALUE cannot be converted to String",
"UpdateOrganizationalUnit|{\"OrganizationalUnitId\":\"ou-x\",\"Name\":1.5}"
+ "|DECIMAL_VALUE cannot be converted to String",
"ListAccounts|{\"MaxResults\":\"5\"}|STRING_VALUE cannot be converted to Integer",
"InviteAccountToOrganization|{\"Target\":\"100623600109\"}|Unexpected field type",
"ListHandshakesForOrganization|{\"Filter\":[]}|UnknownError",
"CreateAccount|{\"Email\":\"a@example.test\",\"AccountName\":\"A\",\"Tags\":[\"team\"]}"
+ "|Unexpected value type in payload",
"CreateAccount|{\"Email\":\"a@example.test\",\"AccountName\":\"A\","
+ "\"Tags\":[{\"Key\":\"team\",\"Value\":5}]}"
+ "|NUMBER_VALUE cannot be converted to String"})
void aMemberOfTheWrongJsonTypeFailsBeforeTheOperationRuns(String action, String request, String message)
throws Exception {
assertRefused(action, request, message);
assertEquals(List.of(), service.listCreateAccountStatus(OWNER, null));
}
@Test
void requestsOfTheModeledTypesStillReachTheirOperations() throws Exception {
ok("DescribeOrganization", OWNER, "{}");
assertEquals(1, ok("ListAccounts", OWNER, "{\"MaxResults\":1,\"NextToken\":null,\"Unmodeled\":[]}")
.path("Accounts").size());
}
@Test
void aModeledOperationFlociDoesNotServeIsUnknownWhateverItsBody() throws Exception {
try (Response response = handler.handle("ListInboundResponsibilityTransfers",
mapper.readTree("{\"MaxResults\":\"x\"}"), OWNER)) {
assertEquals(404, response.getStatus());
assertEquals("UnknownOperationException", ((AwsErrorResponse) response.getEntity()).type());
}
}
private void assertRefused(String action, String request, String message) throws Exception {
try (Response response = handler.handle(action, mapper.readTree(request), OWNER)) {
assertEquals(400, response.getStatus(), action);
AwsErrorResponse error = (AwsErrorResponse) response.getEntity();
assertEquals("SerializationException", error.type(), action);
assertEquals(message, error.message(), action);
}
}
private JsonNode ok(String action, String caller, String request) throws Exception {
try (Response response = handler.handle(action, mapper.readTree(request), caller)) {
assertEquals(200, response.getStatus(), String.valueOf(response.getEntity()));
+35
View File
@@ -0,0 +1,35 @@
#!/usr/bin/env python3
"""Regenerate src/main/resources/aws/organizations-request-shapes.json from botocore's Organizations model.
`OrganizationsRequestShapes` checks an Organizations request against its operation's input shape
through the shared `RequestShapeCheck` before the operation reads it, so a member of the wrong JSON
type fails the request. That check needs the body shapes, so this script keeps only what it reads:
the input shape of every operation and, for every shape reachable from one, its type and the shapes
of its members, list elements or map values.
The model is botocore's `organizations/2016-11-28/service-2.json` (Apache-2.0,
https://github.com/boto/botocore). It is located, in order, at `--botocore-data`, the
`local/aws/botocore` checkout, then the installed `botocore` package, which `requirements.txt`
pins so CI regenerates the same bytes.
Run from anywhere in the repo:
python3 tools/aws/regen_organizations_shapes.py # rewrite the vendored file in place
python3 tools/aws/regen_organizations_shapes.py --check # exit 1 when the vendored file is stale
"""
from __future__ import annotations
import sys
from pathlib import Path
import request_shapes
OUTPUT = request_shapes.REPO_ROOT / "src/main/resources/aws/organizations-request-shapes.json"
MODEL = Path("organizations/2016-11-28")
def main(argv: list[str] | None = None) -> int:
return request_shapes.main(argv, script=__file__, model=MODEL, output=OUTPUT, description=__doc__)
if __name__ == "__main__":
sys.exit(main())
+3 -3
View File
@@ -1,8 +1,8 @@
"""Shared generator for the vendored request shapes a service's request check reads.
`regen_dynamodb_shapes.py`, `regen_sesv2_shapes.py`, `regen_apigateway_shapes.py` and
`regen_ecs_shapes.py` each name a botocore model and an output file and hand the rest to
`main()`. `regen_resource_groups_shapes.py`, `regen_logs_delivery_shapes.py` and
`regen_dynamodb_shapes.py`, `regen_sesv2_shapes.py`, `regen_apigateway_shapes.py`,
`regen_ecs_shapes.py` and `regen_organizations_shapes.py` each name a botocore model and an output
file and hand the rest to `main()`. `regen_resource_groups_shapes.py`, `regen_logs_delivery_shapes.py` and
`regen_ecr_shapes.py` vendor constraints as well, through `build_constraints()`. The output keeps only what `RequestShapeModel` reads: the input
shape of every operation, reduced to the members carried in the JSON body, and for every shape
reachable from one, its type and the shapes of its members, list elements or map values.
+5 -2
View File
@@ -1,6 +1,6 @@
"""Tests for request_shapes, the generator behind regen_dynamodb_shapes, regen_sesv2_shapes, regen_apigateway_shapes,
regen_ecs_shapes and regen_emr_serverless_shapes, and of the constraints regen_resource_groups_shapes,
regen_ecr_shapes, regen_iam_shapes and regen_sts_shapes vendor.
regen_ecs_shapes, regen_organizations_shapes and regen_emr_serverless_shapes, and of the constraints
regen_resource_groups_shapes, regen_ecr_shapes, regen_iam_shapes and regen_sts_shapes vendor.
Each generator names a model, an output and, for the constraints flavour, its operations, and hands
the rest here, so what any one of them does differently is a constant and what they all do is
@@ -30,6 +30,7 @@ import regen_iam_shapes
import regen_cloudfront_keyvaluestore_shapes
import regen_kinesis_shapes
import regen_lambda_microvm_shapes
import regen_organizations_shapes
import regen_payment_cryptography_data_shapes
import regen_payment_cryptography_shapes
import regen_logs_delivery_shapes
@@ -198,6 +199,7 @@ def test_generator_name_is_the_scripts_path_from_the_repository_root():
assert r.generator_name(regen_sesv2_shapes.__file__) == "tools/aws/regen_sesv2_shapes.py"
assert r.generator_name(regen_apigateway_shapes.__file__) == "tools/aws/regen_apigateway_shapes.py"
assert r.generator_name(regen_ecs_shapes.__file__) == "tools/aws/regen_ecs_shapes.py"
assert r.generator_name(regen_organizations_shapes.__file__) == "tools/aws/regen_organizations_shapes.py"
def test_generator_name_outside_the_repository_is_the_file_name(tmp_path):
@@ -223,6 +225,7 @@ def test_load_model_without_a_service_model_exits(tmp_path):
(regen_sesv2_shapes, "sesv2/2019-09-27", "sesv2-request-shapes.json", {}),
(regen_apigateway_shapes, "apigateway/2015-07-09", "apigateway-request-shapes.json", {}),
(regen_ecs_shapes, "ecs/2014-11-13", "ecs-request-shapes.json", {}),
(regen_organizations_shapes, "organizations/2016-11-28", "organizations-request-shapes.json", {}),
])
def test_each_script_runs_the_shared_main_with_its_model_and_output(script, model, output, options, monkeypatch):
calls = []