mirror of
https://github.com/floci-io/floci.git
synced 2026-12-01 01:12:48 -05:00
fix(core): route a shared Query action name by the Version it declares (#5549)
Without a usable credential scope, a Query request's service came from the action name alone, first match wins. Wherever two services define the same name, the later one was unreachable on that path: an unsigned ElastiCache CreateUser created an IAM user, SQS AddPermission was answered by SNS, and RDS, ElastiCache and CloudWatch ListTagsForResource all reached SNS. The parity test pinned 18 such names as claimed by another service. Every Query client sends its service's API version as the Version form field, and those are distinct per service in botocore's models, so Version now chooses among the services that serve the name, the way isElbClassicRequest already splits the two ELB APIs. SES and Elastic Beanstalk publish the same version and share no action name, so the action settles which one a request is for. A Version naming a service that does not serve the name, or no Version at all, leaves the existing order to decide, so a request that omits the field routes exactly as before. IamEnforcementFilter resolves through the same AwsQueryServiceResolver and reads Version from the form body the way it reads the action, first occurrence, as the controller's getFirst does. A request is therefore authorized under the namespace of the service that runs it, which the new enforcement tests hold in both directions. The if-chain becomes one ordered table of services, each with the API versions its clients declare and the names it serves, which both paths read, so the order and the versions cannot drift apart. SQS gets a set for the first time and is tried last, so by name alone it still takes only what nothing else defines, and its Version wins back the two names SNS shares. The parity test now routes each handler's actions with that service's own Version, and states the versions itself rather than reading them back from the controller. It also routes them without a Version, where a name two services share may go to either, but has to reach one whose handler dispatches it. 16 of the 18 claimed entries leave the gap file. The other 2 are SQS AddPermission and RemovePermission, which without a Version still reach SNS, whose handler does not implement them. The file is down to 173: those 2 and 171 names missing from their own service's set. Refs #5032
This commit is contained in:
1 parent
5ea632cc13
commit
8a87e062c8
9 files changed
+453
-123
No files matched your search
+108
-15
@@ -6,8 +6,10 @@ import java.io.IOException;
|
||||
import java.nio.file.Files;
|
||||
import java.nio.file.Path;
|
||||
import java.util.ArrayList;
|
||||
import java.util.HashMap;
|
||||
import java.util.LinkedHashSet;
|
||||
import java.util.List;
|
||||
import java.util.Map;
|
||||
import java.util.Set;
|
||||
import java.util.TreeSet;
|
||||
import java.util.regex.Matcher;
|
||||
@@ -23,15 +25,22 @@ import static org.junit.jupiter.api.Assertions.assertTrue;
|
||||
* services, which is what this test makes visible and stops growing.
|
||||
*
|
||||
* <p>Routing only decides anything when a request arrives without a usable credential scope,
|
||||
* because otherwise the service comes from the SigV4 scope. On that path the action name is all
|
||||
* there is, and {@code inferServiceFromAction}'s chain ends in {@code return "sqs"}, so a missing
|
||||
* name answers {@code UnsupportedOperation} in the SQS namespace rather than failing visibly.
|
||||
* {@code AwsQueryServiceResolver} backs {@code IamEnforcementFilter} through the same code, so the
|
||||
* same operation is also authorized under the wrong namespace, which is the part worth a test.
|
||||
* because otherwise the service comes from the SigV4 scope. On that path there is the action name
|
||||
* and the {@code Version} the request declares, and {@code inferServiceFromAction} falls back to
|
||||
* SQS, so a missing name answers {@code UnsupportedOperation} in the SQS namespace rather than
|
||||
* failing visibly. {@code AwsQueryServiceResolver} backs {@code IamEnforcementFilter}
|
||||
* through the same code, so the same operation is also authorized under the wrong namespace, which
|
||||
* is the part worth a test.
|
||||
*
|
||||
* <p>Each action is routed with its own service's {@code Version}, as any Query client sends it,
|
||||
* and again without one, as a hand-rolled request may leave it out. Without it a name two services
|
||||
* share goes to whichever is tried first, so that path is only held to reaching a service that
|
||||
* dispatches the name.
|
||||
*
|
||||
* <p>The known gaps live in {@code src/test/resources/query-routing-known-gaps.tsv} rather than
|
||||
* here, so that fixing one is a line removed from a data file. The list is checked both ways: a new
|
||||
* gap fails {@link #everyDispatchedActionRoutesToItsOwnService}, and a gap that has been fixed
|
||||
* gap fails {@link #everyDispatchedActionRoutesToItsOwnService} or
|
||||
* {@link #withoutAVersionEveryActionReachesAServiceThatDispatchesIt}, and a gap that has been fixed
|
||||
* without delisting fails {@link #theKnownGapListHasNoStaleEntries}.
|
||||
*/
|
||||
class AwsQueryActionRoutingParityTest {
|
||||
@@ -76,7 +85,7 @@ class AwsQueryActionRoutingParityTest {
|
||||
* their sets are checked as one and why {@code isElbClassicRequest} exists to split them on
|
||||
* {@code Version} afterwards.
|
||||
*
|
||||
* <p>SQS is listed even though it is the fallback the chain ends in, because being the default
|
||||
* <p>SQS is listed even though it is the fallback routing ends in, because being the default
|
||||
* does not make it safe: a name an earlier service claims never reaches it.
|
||||
*/
|
||||
private static final List<QueryHandler> HANDLERS = List.of(
|
||||
@@ -106,6 +115,28 @@ class AwsQueryActionRoutingParityTest {
|
||||
new QueryHandler("redshift", HANDLERS_ROOT + "redshift/RedshiftQueryHandler.java"),
|
||||
new QueryHandler("sqs", HANDLERS_ROOT + "sqs/SqsQueryHandler.java"));
|
||||
|
||||
/**
|
||||
* The {@code Version} each service's clients send, which is the {@code apiVersion} in its
|
||||
* botocore model. Stated here rather than read back from the controller, so a wrong version
|
||||
* there fails this test instead of agreeing with it. ELBv2's stands for both load balancing
|
||||
* APIs, since they route to one service by either version and are only split afterwards.
|
||||
*/
|
||||
private static final Map<String, String> API_VERSIONS = Map.ofEntries(
|
||||
Map.entry("sts", "2011-06-15"),
|
||||
Map.entry("iam", "2010-05-08"),
|
||||
Map.entry("sns", "2010-03-31"),
|
||||
Map.entry("sqs", "2012-11-05"),
|
||||
Map.entry("elasticache", "2015-02-02"),
|
||||
Map.entry("rds", "2014-10-31"),
|
||||
Map.entry("monitoring", "2010-08-01"),
|
||||
Map.entry("cloudformation", "2010-05-15"),
|
||||
Map.entry("email", "2010-12-01"),
|
||||
Map.entry("ec2", "2016-11-15"),
|
||||
Map.entry("elasticloadbalancing", "2015-12-01"),
|
||||
Map.entry("autoscaling", "2011-01-01"),
|
||||
Map.entry("elasticbeanstalk", "2010-12-01"),
|
||||
Map.entry("redshift", "2012-12-01"));
|
||||
|
||||
private static final Path KNOWN_GAPS = Path.of("src/test/resources/query-routing-known-gaps.tsv");
|
||||
|
||||
/**
|
||||
@@ -130,11 +161,11 @@ class AwsQueryActionRoutingParityTest {
|
||||
|
||||
for (QueryHandler handler : HANDLERS) {
|
||||
for (String action : dispatchedActions(handler)) {
|
||||
String reached = AwsQueryController.inferServiceFromAction(action);
|
||||
String reached = reached(handler, action);
|
||||
if (!handler.service().equals(reached)
|
||||
&& !known.contains(gapKey(handler.service(), action, reached))) {
|
||||
unexpected.add(handler.service() + " dispatches " + action
|
||||
+ " but the name reaches " + reached);
|
||||
+ " but a request for it reaches " + reached);
|
||||
}
|
||||
}
|
||||
}
|
||||
@@ -142,11 +173,40 @@ class AwsQueryActionRoutingParityTest {
|
||||
assertTrue(unexpected.isEmpty(),
|
||||
"An action a handler dispatches has to route to that handler, or a request without "
|
||||
+ "a credential scope answers in the wrong namespace and is authorized "
|
||||
+ "under it too. Add the name to its service's set in AwsQueryController, "
|
||||
+ "having checked that no service earlier in inferServiceFromAction's "
|
||||
+ "chain already claims it. If an earlier service does claim it, the name "
|
||||
+ "needs the Version discriminator instead, and belongs in " + KNOWN_GAPS
|
||||
+ " with that noted. New: " + unexpected);
|
||||
+ "under it too. Add the name to its service's set in AwsQueryController; "
|
||||
+ "a name another service also defines is then told apart by the request's "
|
||||
+ "Version. New: " + unexpected);
|
||||
}
|
||||
|
||||
/**
|
||||
* Without a {@code Version} the name decides alone, and a name two services define goes to the
|
||||
* one tried first, which is right for either of them. What is wrong is reaching a service that
|
||||
* does not dispatch the name at all, and the check above cannot see it, because a
|
||||
* {@code Version} goes straight to the service it names: a set claiming a name its handler
|
||||
* lacks, tried ahead of the service that has it, takes every such request.
|
||||
*/
|
||||
@Test
|
||||
void withoutAVersionEveryActionReachesAServiceThatDispatchesIt() throws IOException {
|
||||
Set<String> known = knownGaps();
|
||||
Map<String, Set<String>> dispatched = dispatchedByService();
|
||||
List<String> unexpected = new ArrayList<>();
|
||||
|
||||
for (QueryHandler handler : HANDLERS) {
|
||||
for (String action : dispatchedActions(handler)) {
|
||||
String reached = reachedWithoutVersion(action);
|
||||
if (!dispatched.getOrDefault(reached, Set.of()).contains(action)
|
||||
&& !known.contains(gapKey(handler.service(), action, reached))) {
|
||||
unexpected.add(handler.service() + " dispatches " + action
|
||||
+ " but without a Version a request for it reaches " + reached);
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
assertTrue(unexpected.isEmpty(),
|
||||
"Without a Version an action has to reach a service that dispatches it, or the "
|
||||
+ "request answers UnsupportedOperation in a namespace it was never for. "
|
||||
+ "A set in AwsQueryController claims a name its handler does not "
|
||||
+ "dispatch, ahead of the service that does: " + unexpected);
|
||||
}
|
||||
|
||||
/**
|
||||
@@ -156,13 +216,18 @@ class AwsQueryActionRoutingParityTest {
|
||||
*/
|
||||
@Test
|
||||
void theKnownGapListHasNoStaleEntries() throws IOException {
|
||||
Map<String, Set<String>> dispatched = dispatchedByService();
|
||||
Set<String> live = new LinkedHashSet<>();
|
||||
for (QueryHandler handler : HANDLERS) {
|
||||
for (String action : dispatchedActions(handler)) {
|
||||
String reached = AwsQueryController.inferServiceFromAction(action);
|
||||
String reached = reached(handler, action);
|
||||
if (!handler.service().equals(reached)) {
|
||||
live.add(gapKey(handler.service(), action, reached));
|
||||
}
|
||||
String reachedWithoutVersion = reachedWithoutVersion(action);
|
||||
if (!dispatched.getOrDefault(reachedWithoutVersion, Set.of()).contains(action)) {
|
||||
live.add(gapKey(handler.service(), action, reachedWithoutVersion));
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
@@ -270,6 +335,34 @@ class AwsQueryActionRoutingParityTest {
|
||||
+ "that counted it, including the total. " + wrong);
|
||||
}
|
||||
|
||||
/**
|
||||
* Where an unsigned request for the action goes, carrying the handler's own {@code Version} the
|
||||
* way every Query client sends it.
|
||||
*/
|
||||
private static String reached(QueryHandler handler, String action) {
|
||||
String version = API_VERSIONS.get(handler.service());
|
||||
assertTrue(version != null, "No API version listed for " + handler.service());
|
||||
return AwsQueryController.inferServiceFromAction(action, version);
|
||||
}
|
||||
|
||||
/** Where an unsigned request for the action goes when it carries no {@code Version} at all. */
|
||||
private static String reachedWithoutVersion(String action) {
|
||||
return AwsQueryController.inferServiceFromAction(action, null);
|
||||
}
|
||||
|
||||
/**
|
||||
* Every name each service dispatches, across all of its handlers. A service with no Query
|
||||
* handler, as Cognito has none, dispatches nothing.
|
||||
*/
|
||||
private static Map<String, Set<String>> dispatchedByService() throws IOException {
|
||||
Map<String, Set<String>> dispatched = new HashMap<>();
|
||||
for (QueryHandler handler : HANDLERS) {
|
||||
dispatched.computeIfAbsent(handler.service(), service -> new TreeSet<>())
|
||||
.addAll(dispatchedActions(handler));
|
||||
}
|
||||
return dispatched;
|
||||
}
|
||||
|
||||
/** One line of the known-gap file: the service, the action, and what it reaches instead. */
|
||||
private static String gapKey(String service, String action, String reached) {
|
||||
return service + "\t" + action + "\t" + reached;
|
||||
|
||||
+98
@@ -1,10 +1,15 @@
|
||||
package io.github.hectorvent.floci.core.common;
|
||||
|
||||
import io.github.hectorvent.floci.testing.PartitionCleanup;
|
||||
import io.quarkus.test.junit.QuarkusTest;
|
||||
import io.restassured.response.ValidatableResponse;
|
||||
import org.junit.jupiter.api.Test;
|
||||
import org.junit.jupiter.api.extension.RegisterExtension;
|
||||
import org.junit.jupiter.params.ParameterizedTest;
|
||||
import org.junit.jupiter.params.provider.ValueSource;
|
||||
|
||||
import java.util.UUID;
|
||||
|
||||
import static io.restassured.RestAssured.given;
|
||||
import static org.hamcrest.Matchers.containsString;
|
||||
import static org.hamcrest.Matchers.equalTo;
|
||||
@@ -14,6 +19,9 @@ import static org.hamcrest.Matchers.not;
|
||||
@QuarkusTest
|
||||
class AwsQueryControllerIntegrationTest {
|
||||
|
||||
@RegisterExtension
|
||||
final PartitionCleanup cleanup = new PartitionCleanup();
|
||||
|
||||
@Test
|
||||
void missingActionParameterReturns400MissingAction() {
|
||||
given()
|
||||
@@ -76,4 +84,94 @@ class AwsQueryControllerIntegrationTest {
|
||||
.contentType("application/xml")
|
||||
.body("DescribeRegionsResponse.regionInfo.item.size()", greaterThan(0));
|
||||
}
|
||||
|
||||
@Test
|
||||
void sharedActionNameReachesTheServiceItsVersionDeclares() {
|
||||
// IAM and ElastiCache both define CreateUser and IAM takes it by name. The Version an
|
||||
// ElastiCache client sends is what brings the request to ElastiCache instead.
|
||||
String userId = "version-routed-" + UUID.randomUUID().toString().substring(0, 8);
|
||||
// Registered first, so the user goes even when an assertion below fails. It asserts
|
||||
// nothing, so it stays quiet once the test has deleted the user itself.
|
||||
cleanup.register(() -> deleteElastiCacheUser(userId));
|
||||
given()
|
||||
.contentType("application/x-www-form-urlencoded")
|
||||
.formParam("Action", "CreateUser")
|
||||
.formParam("Version", "2015-02-02")
|
||||
.formParam("UserId", userId)
|
||||
.formParam("UserName", userId)
|
||||
.formParam("Engine", "redis")
|
||||
.formParam("AccessString", "on ~* +@all")
|
||||
.formParam("AuthenticationMode.Type", "no-password-required")
|
||||
.when()
|
||||
.post("/")
|
||||
.then()
|
||||
.statusCode(200)
|
||||
.body("CreateUserResponse.CreateUserResult.UserId", equalTo(userId));
|
||||
|
||||
// DeleteUser is shared the same way.
|
||||
deleteElastiCacheUser(userId)
|
||||
.statusCode(200)
|
||||
.body("DeleteUserResponse.DeleteUserResult.UserId", equalTo(userId));
|
||||
}
|
||||
|
||||
@Test
|
||||
void sqsPermissionActionReachesSqsUnderItsVersion() {
|
||||
// SNS also defines AddPermission and takes it by name, so it is SQS's Version that brings
|
||||
// this request to the queue rather than to SNS.
|
||||
String queueUrl = given()
|
||||
.contentType("application/x-www-form-urlencoded")
|
||||
.formParam("Action", "CreateQueue")
|
||||
.formParam("Version", "2012-11-05")
|
||||
.formParam("QueueName", "version-routed-" + UUID.randomUUID().toString().substring(0, 8))
|
||||
.when()
|
||||
.post("/")
|
||||
.then()
|
||||
.statusCode(200)
|
||||
.extract().path("CreateQueueResponse.CreateQueueResult.QueueUrl");
|
||||
cleanup.register(() -> given()
|
||||
.contentType("application/x-www-form-urlencoded")
|
||||
.formParam("Action", "DeleteQueue")
|
||||
.formParam("Version", "2012-11-05")
|
||||
.formParam("QueueUrl", queueUrl)
|
||||
.when()
|
||||
.post("/")
|
||||
.then()
|
||||
.statusCode(200));
|
||||
|
||||
given()
|
||||
.contentType("application/x-www-form-urlencoded")
|
||||
.formParam("Action", "AddPermission")
|
||||
.formParam("Version", "2012-11-05")
|
||||
.formParam("QueueUrl", queueUrl)
|
||||
.formParam("Label", "granted-under-sqs-version")
|
||||
.formParam("AWSAccountId.1", "111122223333")
|
||||
.formParam("ActionName.1", "SendMessage")
|
||||
.when()
|
||||
.post("/")
|
||||
.then()
|
||||
.statusCode(200);
|
||||
|
||||
given()
|
||||
.contentType("application/x-www-form-urlencoded")
|
||||
.formParam("Action", "GetQueueAttributes")
|
||||
.formParam("Version", "2012-11-05")
|
||||
.formParam("QueueUrl", queueUrl)
|
||||
.formParam("AttributeName.1", "Policy")
|
||||
.when()
|
||||
.post("/")
|
||||
.then()
|
||||
.statusCode(200)
|
||||
.body(containsString("granted-under-sqs-version"));
|
||||
}
|
||||
|
||||
private static ValidatableResponse deleteElastiCacheUser(String userId) {
|
||||
return given()
|
||||
.contentType("application/x-www-form-urlencoded")
|
||||
.formParam("Action", "DeleteUser")
|
||||
.formParam("Version", "2015-02-02")
|
||||
.formParam("UserId", userId)
|
||||
.when()
|
||||
.post("/")
|
||||
.then();
|
||||
}
|
||||
}
|
||||
+58
-4
@@ -2,6 +2,8 @@ package io.github.hectorvent.floci.core.common;
|
||||
|
||||
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 java.util.Optional;
|
||||
import java.util.Set;
|
||||
@@ -26,7 +28,7 @@ class AwsQueryServiceResolverTest {
|
||||
when(catalog.byCredentialScope("lambda")).thenReturn(Optional.of(
|
||||
descriptor("lambda", ServiceProtocol.REST_JSON)));
|
||||
|
||||
assertEquals("iam", resolver.resolve(authorization("lambda"), "CreateUser"));
|
||||
assertEquals("iam", resolver.resolve(authorization("lambda"), "CreateUser", null));
|
||||
}
|
||||
|
||||
@Test
|
||||
@@ -34,7 +36,7 @@ class AwsQueryServiceResolverTest {
|
||||
when(catalog.byCredentialScope("sqs")).thenReturn(Optional.of(
|
||||
descriptor("sqs", ServiceProtocol.QUERY)));
|
||||
|
||||
assertEquals("sqs", resolver.resolve(authorization("sqs"), "CreateUser"));
|
||||
assertEquals("sqs", resolver.resolve(authorization("sqs"), "CreateUser", null));
|
||||
}
|
||||
|
||||
@Test
|
||||
@@ -42,12 +44,64 @@ class AwsQueryServiceResolverTest {
|
||||
when(catalog.byCredentialScope("iam")).thenReturn(Optional.of(
|
||||
descriptor("iam", ServiceProtocol.QUERY)));
|
||||
|
||||
assertEquals("iam", resolver.resolve(authorization("iam"), "CreateUser"));
|
||||
assertEquals("iam", resolver.resolve(authorization("iam"), "CreateUser", null));
|
||||
}
|
||||
|
||||
@Test
|
||||
void missingAuthorizationKeepsActionFallback() {
|
||||
assertEquals("sqs", resolver.resolve(null, "UnknownQueryAction"));
|
||||
assertEquals("sqs", resolver.resolve(null, "UnknownQueryAction", null));
|
||||
}
|
||||
|
||||
/**
|
||||
* A name two services define goes to the one whose {@code Version} the request declares. With
|
||||
* no version, or one that does not settle it, the routing order decides as it always has.
|
||||
*/
|
||||
@ParameterizedTest
|
||||
@CsvSource(nullValues = "none", value = {
|
||||
"CreateUser, 2015-02-02, elasticache",
|
||||
"CreateUser, 2010-05-08, iam",
|
||||
"CreateUser, none, iam",
|
||||
"AddPermission, 2012-11-05, sqs",
|
||||
"AddPermission, 2010-03-31, sns",
|
||||
"AddPermission, none, sns",
|
||||
"ListTagsForResource, 2014-10-31, rds",
|
||||
"ListTagsForResource, none, sns",
|
||||
"DeleteTags, 2012-12-01, redshift",
|
||||
"DeleteTags, 2011-01-01, autoscaling",
|
||||
"DeleteTags, none, ec2",
|
||||
"DescribeTags, 2012-06-01, elasticloadbalancing",
|
||||
"GetTemplate, 2010-12-01, email",
|
||||
"GetTemplate, none, cloudformation",
|
||||
"DescribeEnvironments, 2010-12-01, elasticbeanstalk",
|
||||
})
|
||||
void versionPicksAmongTheServicesThatShareAName(String action, String version, String expected) {
|
||||
assertEquals(expected, resolver.resolve(null, action, version));
|
||||
}
|
||||
|
||||
@Test
|
||||
void versionOfAServiceWithoutTheActionLeavesTheOrderToDecide() {
|
||||
assertEquals("sns", resolver.resolve(null, "Publish", "2010-05-08"));
|
||||
}
|
||||
|
||||
@Test
|
||||
void unrecognisedVersionLeavesTheOrderToDecide() {
|
||||
assertEquals("iam", resolver.resolve(null, "CreateUser", "2099-01-01"));
|
||||
}
|
||||
|
||||
@Test
|
||||
void queryCapableSignedScopeOutranksVersion() {
|
||||
when(catalog.byCredentialScope("iam")).thenReturn(Optional.of(
|
||||
descriptor("iam", ServiceProtocol.QUERY)));
|
||||
|
||||
assertEquals("iam", resolver.resolve(authorization("iam"), "CreateUser", "2015-02-02"));
|
||||
}
|
||||
|
||||
@Test
|
||||
void unsupportedSignedScopeFallsBackToVersion() {
|
||||
when(catalog.byCredentialScope("lambda")).thenReturn(Optional.of(
|
||||
descriptor("lambda", ServiceProtocol.REST_JSON)));
|
||||
|
||||
assertEquals("elasticache", resolver.resolve(authorization("lambda"), "CreateUser", "2015-02-02"));
|
||||
}
|
||||
|
||||
private static String authorization(String scope) {
|
||||
|
||||
+63
@@ -18,6 +18,7 @@ import java.util.UUID;
|
||||
import static io.github.hectorvent.floci.testing.EnforcementFixtures.auth;
|
||||
import static io.restassured.RestAssured.given;
|
||||
import static org.hamcrest.Matchers.containsString;
|
||||
import static org.hamcrest.Matchers.equalTo;
|
||||
import static org.hamcrest.Matchers.not;
|
||||
|
||||
@QuarkusTest
|
||||
@@ -92,6 +93,40 @@ class IamServingServiceEnforcementIntegrationTest {
|
||||
adminIam("GetUser", Map.of("UserName", attempted)).statusCode(404);
|
||||
}
|
||||
|
||||
@Test
|
||||
void queryVersionMovesAuthorizationWithTheServiceItSelects() {
|
||||
String suffix = UUID.randomUUID().toString().substring(0, 8);
|
||||
String attempted = "version-denied-" + suffix;
|
||||
String accessKeyId = createUserWithPolicy("version-iam-only-" + suffix, "IamCreateUserOnly", """
|
||||
{"Version":"2012-10-17","Statement":[
|
||||
{"Effect":"Allow","Action":"iam:CreateUser","Resource":"*"}
|
||||
]}""");
|
||||
|
||||
elastiCacheCreateUser(accessKeyId, attempted)
|
||||
.statusCode(403)
|
||||
.body(containsString("elasticache:CreateUser"));
|
||||
|
||||
adminIam("GetUser", Map.of("UserName", attempted)).statusCode(404);
|
||||
adminElastiCache("DescribeUsers", Map.of("UserId", attempted)).statusCode(404);
|
||||
}
|
||||
|
||||
@Test
|
||||
void queryVersionReachesTheServiceItsPolicyAllows() {
|
||||
String suffix = UUID.randomUUID().toString().substring(0, 8);
|
||||
String attempted = "version-allowed-" + suffix;
|
||||
String accessKeyId = createUserWithPolicy("version-cache-only-" + suffix, "CacheCreateUserOnly", """
|
||||
{"Version":"2012-10-17","Statement":[
|
||||
{"Effect":"Allow","Action":"elasticache:CreateUser","Resource":"*"}
|
||||
]}""");
|
||||
|
||||
cleanup.register(() -> adminElastiCache("DeleteUser", Map.of("UserId", attempted)).statusCode(200));
|
||||
elastiCacheCreateUser(accessKeyId, attempted)
|
||||
.statusCode(200)
|
||||
.body("CreateUserResponse.CreateUserResult.UserId", equalTo(attempted));
|
||||
|
||||
adminIam("GetUser", Map.of("UserName", attempted)).statusCode(404);
|
||||
}
|
||||
|
||||
@Test
|
||||
void restRequestCannotBypassApiGatewayPolicyWithIamScope() {
|
||||
String suffix = UUID.randomUUID().toString().substring(0, 8);
|
||||
@@ -175,6 +210,34 @@ class IamServingServiceEnforcementIntegrationTest {
|
||||
return iamCall(accessKeyId, scope, "Action", action, params);
|
||||
}
|
||||
|
||||
/**
|
||||
* An ElastiCache {@code CreateUser}, a name IAM also defines and takes by name. Signed under a
|
||||
* scope that is not a Query service, so the scope cannot decide and the {@code Version} has to.
|
||||
*/
|
||||
private static ValidatableResponse elastiCacheCreateUser(String accessKeyId, String userId) {
|
||||
return given()
|
||||
.header("Authorization", auth(accessKeyId, "lambda"))
|
||||
.contentType("application/x-www-form-urlencoded")
|
||||
.formParam("Action", "CreateUser")
|
||||
.formParam("Version", "2015-02-02")
|
||||
.formParam("UserId", userId)
|
||||
.formParam("UserName", userId)
|
||||
.formParam("Engine", "redis")
|
||||
.formParam("AccessString", "on ~* +@all")
|
||||
.formParam("AuthenticationMode.Type", "no-password-required")
|
||||
.when().post("/").then();
|
||||
}
|
||||
|
||||
private static ValidatableResponse adminElastiCache(String action, Map<String, String> params) {
|
||||
RequestSpecification spec = given()
|
||||
.header("Authorization", auth(ACCOUNT_ID, "elasticache"))
|
||||
.contentType("application/x-www-form-urlencoded")
|
||||
.formParam("Action", action)
|
||||
.formParam("Version", "2015-02-02");
|
||||
params.forEach(spec::formParam);
|
||||
return spec.when().post("/").then();
|
||||
}
|
||||
|
||||
private static ValidatableResponse iamOperationCall(String accessKeyId, String scope, String operation,
|
||||
Map<String, String> params) {
|
||||
return iamCall(accessKeyId, scope, "Operation", operation, params);
|
||||
|
||||
Reference in new issue
Block a user