mirror of
https://github.com/floci-io/floci.git
synced 2026-12-01 01:12:48 -05:00
fix(elasticache): provision the built-in default user per account (#7136)
This commit is contained in:
1 parent
08d45041d5
commit
28b9dc6048
6 files changed
+247
-10
No files matched your search
+26
@@ -189,6 +189,32 @@ class ElastiCacheCfnIntegrationTest {
|
||||
CfnStackWaits.awaitStackDeleted(stack);
|
||||
}
|
||||
|
||||
@Test
|
||||
void updatingAUserToTheBuiltInDefaultIdRollsBackAndLeavesTheDefaultUserAlone() {
|
||||
String stack = "elasticache-cfn-builtin-default-it";
|
||||
String template = """
|
||||
{"Resources": {"User": {"Type": "AWS::ElastiCache::User",
|
||||
"Properties": {"UserId": "@@ID@@", "UserName": "default", "Engine": "redis",
|
||||
"AccessString": "off -@all", "NoPasswordRequired": true}}}}
|
||||
""";
|
||||
cloudFormation(stack, "CreateStack", template.replace("@@ID@@", "cfn-it-named-default"));
|
||||
describeStacks(stack, "CREATE_COMPLETE");
|
||||
|
||||
// a new UserId replaces the user, and the built-in default already holds that id
|
||||
cloudFormation(stack, "UpdateStack", template.replace("@@ID@@", "default"));
|
||||
describeStacks(stack, "UPDATE_ROLLBACK_COMPLETE");
|
||||
|
||||
try (ElastiCacheClient client = client()) {
|
||||
assertEquals("on ~* +@all", client.describeUsers(r -> r.userId("default")).users().getFirst()
|
||||
.accessString());
|
||||
assertEquals("off -@all", client.describeUsers(r -> r.userId("cfn-it-named-default")).users()
|
||||
.getFirst().accessString());
|
||||
}
|
||||
|
||||
cloudFormation(stack, "DeleteStack", null);
|
||||
CfnStackWaits.awaitStackDeleted(stack);
|
||||
}
|
||||
|
||||
@Test
|
||||
void cacheClusterExposesEndpoints() throws Exception {
|
||||
Assumptions.assumeTrue(DockerAvailability.isAvailable(), "Docker is required for the cache data plane");
|
||||
|
||||
+4
-3
@@ -260,8 +260,8 @@ class ElastiCacheIntegrationTest {
|
||||
.post("/")
|
||||
.then()
|
||||
.statusCode(200)
|
||||
.body("DescribeUsersResponse.DescribeUsersResult.Users.member.UserId", equalTo(USER_ID))
|
||||
.body("DescribeUsersResponse.DescribeUsersResult.Users.member.UserName", equalTo(USER_NAME));
|
||||
.body("DescribeUsersResponse.DescribeUsersResult.Users.member.findAll { it.UserId == '" + USER_ID
|
||||
+ "' && it.UserName == '" + USER_NAME + "' }.size()", equalTo(1));
|
||||
}
|
||||
|
||||
@Test
|
||||
@@ -380,7 +380,8 @@ class ElastiCacheIntegrationTest {
|
||||
.post("/")
|
||||
.then()
|
||||
.statusCode(200)
|
||||
.body("DescribeUsersResponse.DescribeUsersResult.Users.member.UserId", not(equalTo(USER_ID)));
|
||||
.body("DescribeUsersResponse.DescribeUsersResult.Users.member.findAll { it.UserId == '" + USER_ID
|
||||
+ "' }.size()", equalTo(0));
|
||||
}
|
||||
|
||||
@Test
|
||||
|
||||
+82
@@ -51,11 +51,14 @@ import java.util.concurrent.Executors;
|
||||
import java.util.concurrent.Future;
|
||||
import java.util.concurrent.TimeUnit;
|
||||
import java.util.concurrent.atomic.AtomicReference;
|
||||
import java.util.stream.Collectors;
|
||||
|
||||
import static org.awaitility.Awaitility.await;
|
||||
import static org.junit.jupiter.api.Assertions.assertEquals;
|
||||
import static org.junit.jupiter.api.Assertions.assertFalse;
|
||||
import static org.junit.jupiter.api.Assertions.assertNotSame;
|
||||
import static org.junit.jupiter.api.Assertions.assertNull;
|
||||
import static org.junit.jupiter.api.Assertions.assertSame;
|
||||
import static org.junit.jupiter.api.Assertions.assertThrows;
|
||||
import static org.junit.jupiter.api.Assertions.assertTrue;
|
||||
import static org.mockito.ArgumentMatchers.any;
|
||||
@@ -660,6 +663,85 @@ class ElastiCacheServiceTest {
|
||||
assertEquals("UserNotFound", assertThrows(AwsException.class, () -> service.deleteUser("absent")).getErrorCode());
|
||||
}
|
||||
|
||||
@Test
|
||||
void everyAccountHasTheBuiltInDefaultUser() {
|
||||
ElastiCacheUser user = service.getUser("default");
|
||||
assertEquals("default", user.getUserName());
|
||||
assertEquals("redis", user.getEngine());
|
||||
assertEquals("active", user.getStatus());
|
||||
assertEquals("on ~* +@all", user.getAccessString());
|
||||
assertEquals(AuthMode.NO_AUTH, user.getAuthMode());
|
||||
assertEquals("arn:aws:elasticache:us-east-1:000000000000:user:default", user.getArn());
|
||||
assertTrue(service.listUsers(null, null).stream().anyMatch(u -> "default".equals(u.getUserId())));
|
||||
assertEquals(1, service.listUsers("default", null).size());
|
||||
assertTrue(service.listUsers(null, "redis").stream().anyMatch(u -> "default".equals(u.getUserId())));
|
||||
assertEquals("UserAlreadyExists", assertThrows(AwsException.class, () -> service.createUser(
|
||||
"default", "default", AuthMode.NO_AUTH, List.of(), "on ~* +@all", "redis")).getErrorCode());
|
||||
}
|
||||
|
||||
@Test
|
||||
void theBuiltInDefaultUserJoinsARedisUserGroupAndCannotBeDeleted() {
|
||||
service.createUser("app-user", "app", AuthMode.PASSWORD, List.of("pw"), "on ~* +@all", "redis");
|
||||
service.createUserGroup("with-default", "redis", List.of("default", "app-user"), "us-east-1");
|
||||
assertEquals(Set.of("default", "app-user"), service.getUserGroup("with-default").getUserIds());
|
||||
|
||||
AwsException ex = assertThrows(AwsException.class, () -> service.deleteUser("default"));
|
||||
assertEquals("InvalidParameterValue", ex.getErrorCode());
|
||||
assertEquals(400, ex.getHttpStatus());
|
||||
assertEquals("default", service.getUser("default").getUserId());
|
||||
assertTrue(service.getUserGroup("with-default").getUserIds().contains("default"));
|
||||
|
||||
// a custom user named default still replaces the built-in one in a group
|
||||
service.createUser("my-default", "default", AuthMode.PASSWORD, List.of("pw"), "on ~* +@all", "redis");
|
||||
service.createUserGroup("custom-default", "redis", List.of("my-default"), "us-east-1");
|
||||
assertEquals("DuplicateUserName", assertThrows(AwsException.class, () -> service.createUserGroup(
|
||||
"both-defaults", "redis", List.of("default", "my-default"), "us-east-1")).getErrorCode());
|
||||
}
|
||||
|
||||
@Test
|
||||
void theBuiltInDefaultUserIsSeparatePerAccount() {
|
||||
AtomicReference<String> account = new AtomicReference<>("111111111111");
|
||||
ElastiCacheService svc = serviceWith(storageFollowing(account), containerManager, proxyManager,
|
||||
clusterFormation);
|
||||
svc.createUser("app-user", "app", AuthMode.PASSWORD, List.of("pw"), "on ~* +@all", "redis");
|
||||
ElastiCacheUser first = svc.getUser("default");
|
||||
|
||||
account.set("222222222222");
|
||||
// each account holds its own record, seeded on its own first touch
|
||||
assertNotSame(first, svc.getUser("default"));
|
||||
assertEquals(List.of("default"), svc.listUsers(null, null).stream().map(ElastiCacheUser::getUserId).toList());
|
||||
|
||||
account.set("111111111111");
|
||||
assertSame(first, svc.getUser("default"));
|
||||
assertEquals(Set.of("default", "app-user"), svc.listUsers(null, null).stream()
|
||||
.map(ElastiCacheUser::getUserId).collect(Collectors.toSet()));
|
||||
}
|
||||
|
||||
@Test
|
||||
void createUserAsAnAccountsFirstCallFindsTheBuiltInDefaultUser() {
|
||||
ElastiCacheService svc = serviceWith(storageFollowing(new AtomicReference<>("333333333333")),
|
||||
containerManager, proxyManager, clusterFormation);
|
||||
assertEquals("UserAlreadyExists", assertThrows(AwsException.class, () -> svc.createUser(
|
||||
"default", "default", AuthMode.PASSWORD, List.of("pw"), "off -@all", "redis")).getErrorCode());
|
||||
assertEquals("on ~* +@all", svc.getUser("default").getAccessString());
|
||||
}
|
||||
|
||||
@Test
|
||||
void theBuiltInDefaultUserCannotBeModified() {
|
||||
AwsException ex = assertThrows(AwsException.class, () -> service.modifyUser(
|
||||
"default", AuthMode.PASSWORD, List.of("secret"), "off -@all", null, null));
|
||||
assertEquals("InvalidParameterValue", ex.getErrorCode());
|
||||
assertEquals(400, ex.getHttpStatus());
|
||||
ElastiCacheUser user = service.getUser("default");
|
||||
assertEquals(AuthMode.NO_AUTH, user.getAuthMode());
|
||||
assertEquals("on ~* +@all", user.getAccessString());
|
||||
|
||||
// a custom user named default is an ordinary user
|
||||
service.createUser("my-default", "default", AuthMode.PASSWORD, List.of("pw"), "on ~* +@all", "redis");
|
||||
assertEquals("off -@all", service.modifyUser("my-default", null, null, "off -@all", null, null)
|
||||
.getAccessString());
|
||||
}
|
||||
|
||||
@Test
|
||||
void singleArgAuthFallsBackToGroupAuthToken() {
|
||||
service.createReplicationGroup("grp", "test", AuthMode.PASSWORD, "group-token", "us-east-1");
|
||||
|
||||
+88
-1
@@ -8,9 +8,12 @@ import org.junit.jupiter.api.Test;
|
||||
import org.junit.jupiter.api.TestMethodOrder;
|
||||
|
||||
import static io.restassured.RestAssured.given;
|
||||
import static org.hamcrest.Matchers.allOf;
|
||||
import static org.hamcrest.Matchers.containsString;
|
||||
import static org.hamcrest.Matchers.endsWith;
|
||||
import static org.hamcrest.Matchers.equalTo;
|
||||
import static org.hamcrest.Matchers.hasItems;
|
||||
import static org.hamcrest.Matchers.startsWith;
|
||||
|
||||
/**
|
||||
* Control-plane coverage for CreateUserGroup, DescribeUserGroups, ModifyUserGroup and
|
||||
@@ -30,9 +33,13 @@ class ElastiCacheUserGroupIntegrationTest {
|
||||
private static final String DESCRIBE = "DescribeUserGroupsResponse.DescribeUserGroupsResult.UserGroups.member.";
|
||||
|
||||
private static RequestSpecification request(String action) {
|
||||
return request(action, AUTH_HEADER);
|
||||
}
|
||||
|
||||
private static RequestSpecification request(String action, String authorization) {
|
||||
return given()
|
||||
.formParam("Action", action)
|
||||
.header("Authorization", AUTH_HEADER);
|
||||
.header("Authorization", authorization);
|
||||
}
|
||||
|
||||
private static void createUser(String userId, String userName) {
|
||||
@@ -218,4 +225,84 @@ class ElastiCacheUserGroupIntegrationTest {
|
||||
.then()
|
||||
.statusCode(200);
|
||||
}
|
||||
|
||||
@Test
|
||||
@Order(10)
|
||||
void theBuiltInDefaultUserExistsAndJoinsAUserGroup() {
|
||||
request("DescribeUsers")
|
||||
.formParam("UserId", "default")
|
||||
.when()
|
||||
.post("/")
|
||||
.then()
|
||||
.statusCode(200)
|
||||
.body("DescribeUsersResponse.DescribeUsersResult.Users.member.UserId", equalTo("default"))
|
||||
.body("DescribeUsersResponse.DescribeUsersResult.Users.member.UserName", equalTo("default"))
|
||||
.body("DescribeUsersResponse.DescribeUsersResult.Users.member.Status", equalTo("active"))
|
||||
.body("DescribeUsersResponse.DescribeUsersResult.Users.member.Engine", equalTo("redis"))
|
||||
.body("DescribeUsersResponse.DescribeUsersResult.Users.member.AccessString", equalTo("on ~* +@all"))
|
||||
.body("DescribeUsersResponse.DescribeUsersResult.Users.member.MinimumEngineVersion", equalTo("6.0"))
|
||||
// users are stored per account, not per region, so the ARN keeps the first region that read it
|
||||
.body("DescribeUsersResponse.DescribeUsersResult.Users.member.ARN",
|
||||
allOf(startsWith("arn:aws:elasticache:"), endsWith(":000000000000:user:default")));
|
||||
|
||||
request("DescribeUsers")
|
||||
.when()
|
||||
.post("/")
|
||||
.then()
|
||||
.statusCode(200)
|
||||
.body("DescribeUsersResponse.DescribeUsersResult.Users.member.findAll { it.UserId == 'default' }.size()",
|
||||
equalTo(1));
|
||||
|
||||
request("CreateUserGroup")
|
||||
.formParam("UserGroupId", "ug-it-builtin-default")
|
||||
.formParam("Engine", "redis")
|
||||
.formParam("UserIds.member.1", "default")
|
||||
.when()
|
||||
.post("/")
|
||||
.then()
|
||||
.statusCode(200)
|
||||
.body(CREATE + "UserIds.member", equalTo("default"));
|
||||
|
||||
request("DeleteUser")
|
||||
.formParam("UserId", "default")
|
||||
.when()
|
||||
.post("/")
|
||||
.then()
|
||||
.statusCode(400)
|
||||
.body("ErrorResponse.Error.Code", equalTo("InvalidParameterValue"));
|
||||
|
||||
request("ModifyUser")
|
||||
.formParam("UserId", "default")
|
||||
.formParam("AccessString", "off -@all")
|
||||
.when()
|
||||
.post("/")
|
||||
.then()
|
||||
.statusCode(400)
|
||||
.body("ErrorResponse.Error.Code", equalTo("InvalidParameterValue"));
|
||||
|
||||
request("DescribeUsers")
|
||||
.formParam("UserId", "default")
|
||||
.when()
|
||||
.post("/")
|
||||
.then()
|
||||
.statusCode(200)
|
||||
.body("DescribeUsersResponse.DescribeUsersResult.Users.member.AccessString", equalTo("on ~* +@all"));
|
||||
|
||||
// another account has its own default user
|
||||
request("DescribeUsers", "AWS4-HMAC-SHA256 Credential=111111111111/20260412/us-east-1/elasticache/aws4_request")
|
||||
.formParam("UserId", "default")
|
||||
.when()
|
||||
.post("/")
|
||||
.then()
|
||||
.statusCode(200)
|
||||
.body("DescribeUsersResponse.DescribeUsersResult.Users.member.ARN",
|
||||
endsWith(":111111111111:user:default"));
|
||||
|
||||
request("DeleteUserGroup")
|
||||
.formParam("UserGroupId", "ug-it-builtin-default")
|
||||
.when()
|
||||
.post("/")
|
||||
.then()
|
||||
.statusCode(200);
|
||||
}
|
||||
}
|
||||
Reference in new issue
Block a user