fix(elasticache): honor SecurityGroupIds on ModifyReplicationGroup (#6467)

* fix(elasticache): honor SecurityGroupIds on ModifyReplicationGroup

A modify that names SecurityGroupIds now replaces the whole stored list
on the replication group, so DescribeCacheClusters reports the new
groups on every member with Status=active; a modify that names none
leaves the memberships untouched, which the Query protocol cannot
distinguish from an empty list anyway.

Closes #6463

Signed-off-by: Matheus Oliveira <matheus.6148@gmail.com>

* fix(elasticache): read the modify security groups through the shared parse

optionalSecurityGroupIds walked the two Query spellings a second time;
it now reuses parseSecurityGroupIds with the same isEmpty-to-null check
the user group lists use, and the new compatibility test declares its
responses with explicit types.

Signed-off-by: Matheus Oliveira <matheus.6148@gmail.com>

---------

Signed-off-by: Matheus Oliveira <matheus.6148@gmail.com>
This commit is contained in:
Matheus Oliveira authored and GitHub committed 2026-10-25 16:55:00 -04:00
1 parent 796f203b76
commit f4cd3110e7
7 files changed
+154 -13

No files matched your search

@@ -250,7 +250,8 @@ public class ElastiCacheQueryHandler {
userGroupIdsToRemove.isEmpty() ? null : userGroupIdsToRemove,
Boolean.parseBoolean(params.getFirst("RemoveUserGroups")),
"DELETE".equals(params.getFirst("AuthTokenUpdateStrategy")),
settings);
settings,
optionalSecurityGroupIds(params));
String result = replicationGroupXml(group);
return Response.ok(AwsQueryResponse.envelope("ModifyReplicationGroup", AwsNamespaces.EC, result)).build();
} catch (AwsException e) {
@@ -684,6 +685,15 @@ public class ElastiCacheQueryHandler {
return securityGroupIds;
}
/**
* A modify that names no SecurityGroupIds leaves the memberships untouched, so the absent
* list must read as null, never as the empty list a replace would mean.
*/
private static List<String> optionalSecurityGroupIds(MultivaluedMap<String, String> params) {
List<String> securityGroupIds = parseSecurityGroupIds(params);
return securityGroupIds.isEmpty() ? null : securityGroupIds;
}
private Response handleCreateCacheParameterGroup(MultivaluedMap<String, String> params) {
try {
CacheParameterGroup group = service.createCacheParameterGroup(
@@ -1754,7 +1754,7 @@ public class ElastiCacheService implements ResourceProvider {
public ReplicationGroup modifyReplicationGroup(String groupId, List<String> userGroupIdsToAdd,
List<String> userGroupIdsToRemove,
ReplicationGroupSettings settings) {
return modifyReplicationGroup(groupId, userGroupIdsToAdd, userGroupIdsToRemove, false, false, settings);
return modifyReplicationGroup(groupId, userGroupIdsToAdd, userGroupIdsToRemove, false, false, settings, null);
}
/**
@@ -1762,11 +1762,14 @@ public class ElastiCacheService implements ResourceProvider {
* {@code deleteAuthToken} is AuthTokenUpdateStrategy DELETE, which AWS allows only when the
* cache moves to user groups. A cache whose last user group goes has no access control, as
* on AWS, unless it kept an auth token by joining user groups without the DELETE.
* {@code securityGroupIds} replaces the whole stored list; a null leaves the memberships
* untouched, which is what a request that names none means.
*/
public ReplicationGroup modifyReplicationGroup(String groupId, List<String> userGroupIdsToAdd,
List<String> userGroupIdsToRemove,
boolean removeUserGroups, boolean deleteAuthToken,
ReplicationGroupSettings settings) {
ReplicationGroupSettings settings,
List<String> securityGroupIds) {
settings.validate();
synchronized (lockFor("rg:" + groupId)) {
ReplicationGroup group = getReplicationGroup(groupId);
@@ -1836,6 +1839,9 @@ public class ElastiCacheService implements ResourceProvider {
if (deleteAuthToken) {
group.setAuthToken(null);
}
if (securityGroupIds != null) {
group.setSecurityGroupIds(securityGroupIds);
}
if (hadUserGroups && nextUserGroupIds.isEmpty()) {
group.setTransitEncryptionEnabled(group.isEncryptedInTransit());
group.setAuthMode(group.getAuthToken() != null ? AuthMode.PASSWORD : AuthMode.NO_AUTH);