mirror of
https://github.com/floci-io/floci.git
synced 2026-11-22 21:50:46 -05:00
fix(iam): route every dispatched IAM action, and require the parameters the model requires (#5227)
28 operations IamQueryHandler dispatches were missing from AwsQueryController's IAM set. Without a usable credential scope the controller infers the service from the action name alone, and that chain ends in `return "sqs"`, so those answered UnsupportedOperation in the SQS namespace. IamEnforcementFilter resolves the policy namespace through the same code, so they were also authorized as sqs:<Action>, and a policy denying iam:* missed them. The set now matches the handler exactly in both directions: 158 dispatched, 158 routed, nothing routed that is not dispatched. None of the 28 names is defined by another service here, so this adds no ambiguity to the 14 action names that already collide across services. Separately, five operations in the permissions-boundary family read model-required parameters through the nullable accessor, so a missing one reached the service as null and surfaced as InternalFailure from a null map key: UpdateAssumeRolePolicy, PutUserPermissionsBoundary, PutRolePermissionsBoundary and DeleteRolePermissionsBoundary did, DeleteUserPermissionsBoundary happened to fail cleanly. That was already reachable through an IAM credential scope, so it predates this change; routing by action name adds a second way in. All five now answer ValidationError, and the test supplies the name on the three that take a second required parameter, so the check on PolicyDocument and PermissionsBoundary is exercised rather than shadowed by the one on the name. What this does not do is decide whether Version should disambiguate a shared action name. That is a cross-service routing change, it affects 14 names in services this does not otherwise touch, and it is the prerequisite for IAM ChangePassword rather than for these 28. Refs #5032
This commit is contained in:
1 parent
7f5a332620
commit
4495ade6bb
3 files changed
+173
-9
No files matched your search
@@ -128,7 +128,21 @@ public class AwsQueryController {
|
||||
"UploadSSHPublicKey", "GetSSHPublicKey", "ListSSHPublicKeys",
|
||||
"UpdateSSHPublicKey", "DeleteSSHPublicKey",
|
||||
"UploadSigningCertificate", "ListSigningCertificates",
|
||||
"UpdateSigningCertificate", "DeleteSigningCertificate"
|
||||
"UpdateSigningCertificate", "DeleteSigningCertificate",
|
||||
"CreateAccountAlias", "DeleteAccountAlias", "ListAccountAliases",
|
||||
"GetAccountPasswordPolicy", "UpdateAccountPasswordPolicy", "DeleteAccountPasswordPolicy",
|
||||
"GetAccessKeyLastUsed", "UpdateGroup", "UpdateAssumeRolePolicy",
|
||||
"PutUserPermissionsBoundary", "DeleteUserPermissionsBoundary",
|
||||
"PutRolePermissionsBoundary", "DeleteRolePermissionsBoundary",
|
||||
"CreateOpenIDConnectProvider", "GetOpenIDConnectProvider",
|
||||
"ListOpenIDConnectProviders", "DeleteOpenIDConnectProvider",
|
||||
"AddClientIDToOpenIDConnectProvider", "RemoveClientIDFromOpenIDConnectProvider",
|
||||
"UpdateOpenIDConnectProviderThumbprint", "TagOpenIDConnectProvider",
|
||||
"UntagOpenIDConnectProvider", "ListOpenIDConnectProviderTags",
|
||||
"ListOrganizationsFeatures",
|
||||
"EnableOrganizationsRootCredentialsManagement",
|
||||
"DisableOrganizationsRootCredentialsManagement",
|
||||
"EnableOrganizationsRootSessions", "DisableOrganizationsRootSessions"
|
||||
);
|
||||
|
||||
private static final Set<String> AUTOSCALING_ACTIONS = Set.of(
|
||||
|
||||
@@ -1354,8 +1354,8 @@ public class IamQueryHandler {
|
||||
}
|
||||
|
||||
private Response handleUpdateAssumeRolePolicy(MultivaluedMap<String, String> params) {
|
||||
iamService.updateAssumeRolePolicy(getParam(params, "RoleName"),
|
||||
getParam(params, "PolicyDocument"));
|
||||
iamService.updateAssumeRolePolicy(requireParam(params, "RoleName"),
|
||||
requireParam(params, "PolicyDocument"));
|
||||
return Response.ok(AwsQueryResponse.envelopeNoResult("UpdateAssumeRolePolicy", AwsNamespaces.IAM)).build();
|
||||
}
|
||||
|
||||
@@ -2020,27 +2020,27 @@ public class IamQueryHandler {
|
||||
// =========================================================================
|
||||
|
||||
private Response handlePutUserPermissionsBoundary(MultivaluedMap<String, String> params) {
|
||||
String userName = getParam(params, "UserName");
|
||||
String boundaryArn = getParam(params, "PermissionsBoundary");
|
||||
String userName = requireParam(params, "UserName");
|
||||
String boundaryArn = requireParam(params, "PermissionsBoundary");
|
||||
iamService.putUserPermissionsBoundary(userName, boundaryArn);
|
||||
return Response.ok(AwsQueryResponse.envelope("PutUserPermissionsBoundary", AwsNamespaces.IAM, "")).build();
|
||||
}
|
||||
|
||||
private Response handleDeleteUserPermissionsBoundary(MultivaluedMap<String, String> params) {
|
||||
String userName = getParam(params, "UserName");
|
||||
String userName = requireParam(params, "UserName");
|
||||
iamService.deleteUserPermissionsBoundary(userName);
|
||||
return Response.ok(AwsQueryResponse.envelope("DeleteUserPermissionsBoundary", AwsNamespaces.IAM, "")).build();
|
||||
}
|
||||
|
||||
private Response handlePutRolePermissionsBoundary(MultivaluedMap<String, String> params) {
|
||||
String roleName = getParam(params, "RoleName");
|
||||
String boundaryArn = getParam(params, "PermissionsBoundary");
|
||||
String roleName = requireParam(params, "RoleName");
|
||||
String boundaryArn = requireParam(params, "PermissionsBoundary");
|
||||
iamService.putRolePermissionsBoundary(roleName, boundaryArn);
|
||||
return Response.ok(AwsQueryResponse.envelope("PutRolePermissionsBoundary", AwsNamespaces.IAM, "")).build();
|
||||
}
|
||||
|
||||
private Response handleDeleteRolePermissionsBoundary(MultivaluedMap<String, String> params) {
|
||||
String roleName = getParam(params, "RoleName");
|
||||
String roleName = requireParam(params, "RoleName");
|
||||
iamService.deleteRolePermissionsBoundary(roleName);
|
||||
return Response.ok(AwsQueryResponse.envelope("DeleteRolePermissionsBoundary", AwsNamespaces.IAM, "")).build();
|
||||
}
|
||||
|
||||
+150
@@ -0,0 +1,150 @@
|
||||
package io.github.hectorvent.floci.core.common;
|
||||
|
||||
import io.quarkus.test.junit.QuarkusTest;
|
||||
import org.junit.jupiter.api.Test;
|
||||
|
||||
import java.util.LinkedHashMap;
|
||||
import java.util.List;
|
||||
import java.util.Map;
|
||||
|
||||
import static io.restassured.RestAssured.given;
|
||||
import static org.hamcrest.Matchers.containsString;
|
||||
import static org.hamcrest.Matchers.not;
|
||||
|
||||
/**
|
||||
* Every IAM action the Query handler dispatches answers in the IAM namespace when the request
|
||||
* arrives without a usable credential scope.
|
||||
*
|
||||
* <p>Without an {@code Authorization} header the controller infers the service from the action name
|
||||
* alone, and that chain ends in {@code return "sqs"}. A name missing from the IAM set therefore
|
||||
* answers {@code UnsupportedOperation} in the SQS namespace, which looks like a plausible error
|
||||
* rather than a routing failure, and {@code IamEnforcementFilter} resolves the policy namespace
|
||||
* through the same code, so the same operations would be authorized as {@code sqs:<Action>} and a
|
||||
* policy denying {@code iam:*} would miss them.
|
||||
*
|
||||
* <p>One action per family that was unrouted, plus a control that was already routed.
|
||||
*/
|
||||
@QuarkusTest
|
||||
class IamQueryActionRoutingIntegrationTest {
|
||||
|
||||
private static final String IAM_NAMESPACE = "iam.amazonaws.com/doc/2010-05-08";
|
||||
private static final String SQS_NAMESPACE = "sqs.amazonaws.com/doc";
|
||||
|
||||
private static void assertRoutesToIam(String action) {
|
||||
given().contentType("application/x-www-form-urlencoded")
|
||||
.formParam("Action", action)
|
||||
.formParam("Version", "2010-05-08")
|
||||
.when().post("/").then()
|
||||
.body(containsString(IAM_NAMESPACE))
|
||||
.body(not(containsString(SQS_NAMESPACE)));
|
||||
}
|
||||
|
||||
@Test
|
||||
void accountAliasActionsRouteToIam() {
|
||||
for (String action : List.of("CreateAccountAlias", "DeleteAccountAlias",
|
||||
"ListAccountAliases")) {
|
||||
assertRoutesToIam(action);
|
||||
}
|
||||
}
|
||||
|
||||
@Test
|
||||
void accountPasswordPolicyActionsRouteToIam() {
|
||||
for (String action : List.of("GetAccountPasswordPolicy", "UpdateAccountPasswordPolicy",
|
||||
"DeleteAccountPasswordPolicy")) {
|
||||
assertRoutesToIam(action);
|
||||
}
|
||||
}
|
||||
|
||||
@Test
|
||||
void permissionsBoundaryActionsRouteToIam() {
|
||||
for (String action : List.of("PutUserPermissionsBoundary", "DeleteUserPermissionsBoundary",
|
||||
"PutRolePermissionsBoundary", "DeleteRolePermissionsBoundary")) {
|
||||
assertRoutesToIam(action);
|
||||
}
|
||||
}
|
||||
|
||||
@Test
|
||||
void openIdConnectProviderActionsRouteToIam() {
|
||||
for (String action : List.of("CreateOpenIDConnectProvider", "GetOpenIDConnectProvider",
|
||||
"ListOpenIDConnectProviders", "DeleteOpenIDConnectProvider",
|
||||
"AddClientIDToOpenIDConnectProvider", "RemoveClientIDFromOpenIDConnectProvider",
|
||||
"UpdateOpenIDConnectProviderThumbprint", "TagOpenIDConnectProvider",
|
||||
"UntagOpenIDConnectProvider", "ListOpenIDConnectProviderTags")) {
|
||||
assertRoutesToIam(action);
|
||||
}
|
||||
}
|
||||
|
||||
@Test
|
||||
void organizationsFeatureActionsRouteToIam() {
|
||||
for (String action : List.of("ListOrganizationsFeatures",
|
||||
"EnableOrganizationsRootCredentialsManagement",
|
||||
"DisableOrganizationsRootCredentialsManagement",
|
||||
"EnableOrganizationsRootSessions", "DisableOrganizationsRootSessions")) {
|
||||
assertRoutesToIam(action);
|
||||
}
|
||||
}
|
||||
|
||||
@Test
|
||||
void theRemainingSinglesRouteToIam() {
|
||||
for (String action : List.of("GetAccessKeyLastUsed", "UpdateGroup",
|
||||
"UpdateAssumeRolePolicy")) {
|
||||
assertRoutesToIam(action);
|
||||
}
|
||||
}
|
||||
|
||||
/**
|
||||
* Reaching IAM is only half of it: an operation whose required parameters are absent has to
|
||||
* answer {@code ValidationError}, not a 500.
|
||||
*
|
||||
* <p>These five took their model-required parameters through the nullable accessor, so a
|
||||
* missing one reached the service as {@code null} and surfaced as {@code InternalFailure} from
|
||||
* a null map key. That was reachable before this change too, through an IAM credential scope;
|
||||
* routing them by action name alone just adds a second way in.
|
||||
*/
|
||||
@Test
|
||||
void anAbsentRequiredParameterIsAValidationErrorRatherThanA500() {
|
||||
for (String action : List.of("UpdateAssumeRolePolicy", "PutUserPermissionsBoundary",
|
||||
"PutRolePermissionsBoundary", "DeleteRolePermissionsBoundary",
|
||||
"DeleteUserPermissionsBoundary")) {
|
||||
assertValidationError(action, Map.of());
|
||||
}
|
||||
}
|
||||
|
||||
/**
|
||||
* Three of those five take a second required parameter, and omitting everything only ever
|
||||
* exercises the first check: {@code requireParam} on the name throws before the one on the
|
||||
* policy document or the boundary ARN is reached. These cases supply the name, so the second
|
||||
* check is the one under test.
|
||||
*
|
||||
* <p>Both checks run while the arguments to the service call are evaluated, which is why a name
|
||||
* that does not exist still answers {@code ValidationError} rather than {@code NoSuchEntity}.
|
||||
*/
|
||||
@Test
|
||||
void anAbsentSecondRequiredParameterIsAlsoAValidationError() {
|
||||
assertValidationError("UpdateAssumeRolePolicy",
|
||||
Map.of("RoleName", "role-that-need-not-exist"));
|
||||
assertValidationError("PutUserPermissionsBoundary",
|
||||
Map.of("UserName", "user-that-need-not-exist"));
|
||||
assertValidationError("PutRolePermissionsBoundary",
|
||||
Map.of("RoleName", "role-that-need-not-exist"));
|
||||
}
|
||||
|
||||
private static void assertValidationError(String action, Map<String, String> presentParams) {
|
||||
Map<String, String> form = new LinkedHashMap<>(presentParams);
|
||||
form.put("Action", action);
|
||||
form.put("Version", "2010-05-08");
|
||||
given().contentType("application/x-www-form-urlencoded")
|
||||
.formParams(form)
|
||||
.when().post("/").then()
|
||||
.statusCode(400)
|
||||
.body(containsString("ValidationError"))
|
||||
.body(not(containsString("NoSuchEntity")))
|
||||
.body(not(containsString("InternalFailure")));
|
||||
}
|
||||
|
||||
/** The control: an action that was already routed, so a broken assertion shows up here too. */
|
||||
@Test
|
||||
void anAlreadyRoutedActionStillRoutesToIam() {
|
||||
assertRoutesToIam("ListUsers");
|
||||
}
|
||||
}
|
||||
Reference in new issue
Block a user