mirror of
https://github.com/floci-io/floci.git
synced 2026-11-27 07:39:24 -05:00
feat(elasticache): add user groups and associate them with replication groups (#4435)
CreateUserGroup, DescribeUserGroups, ModifyUserGroup and DeleteUserGroup returned UnsupportedOperation, and ModifyReplicationGroup read UserGroupIdsToAdd as user ids, so RBAC could not be set up the way AWS and Terraform (aws_elasticache_user_group, user_group_ids) do it. User groups are now stored resources. CreateReplicationGroup takes UserGroupIds and ModifyReplicationGroup adds and removes user groups; the proxy authenticates the members of a replication group's user groups, read at AUTH time so a ModifyUserGroup applies at once, each by its own authentication mode. A replication group with a user group associated admits only its members, even while the group is empty. An id in UserGroupIdsToAdd that names no user group but names a user still associates that user directly, so existing setups keep working. A cache uses either its AUTH token or user groups, as on AWS: while a user group is attached the token is not accepted and AuthTokenEnabled reads false. ModifyReplicationGroup takes AuthTokenUpdateStrategy DELETE, which removes the token and is only allowed together with a user group, and RemoveUserGroups. Removing the last user group leaves the cache without access control, still encrypted in transit; a token that was never deleted applies again. The proxy reads the cache's auth mode per connection, so these changes take effect without a restart. Validation follows the RBAC rules: a redis user group needs a user named default (DefaultUserRequired), members cannot share a user name (DuplicateUserName), valkey users only join valkey groups, a valkey group cannot hold a no-password user or serve a redis cache, association needs in-transit encryption, and a user group in use cannot be deleted (InvalidUserGroupState). ModifyUser refuses an engine or authentication change that a user group holding the user would reject. Deleting a user removes it from its user groups.
This commit is contained in:
1 parent
da53fc1c05
commit
0848fa6a48
13 files changed
+1256
-88
No files matched your search
@@ -533,7 +533,8 @@ public class AwsQueryController {
|
||||
private static final Set<String> ELASTICACHE_ACTIONS = Set.of(
|
||||
"ValidateIamAuthToken",
|
||||
"CreateReplicationGroup", "DescribeReplicationGroups", "ModifyReplicationGroup", "DeleteReplicationGroup",
|
||||
"CreateUser", "DescribeUsers", "ModifyUser", "DeleteUser"
|
||||
"CreateUser", "DescribeUsers", "ModifyUser", "DeleteUser",
|
||||
"CreateUserGroup", "DescribeUserGroups", "ModifyUserGroup", "DeleteUserGroup"
|
||||
);
|
||||
|
||||
private static final Set<String> CLOUDWATCH_ACTIONS = Set.of(
|
||||
|
||||
+107
-9
@@ -14,6 +14,7 @@ import io.github.hectorvent.floci.services.elasticache.model.CacheParameterGroup
|
||||
import io.github.hectorvent.floci.services.elasticache.model.CacheSubnetGroup;
|
||||
import io.github.hectorvent.floci.services.elasticache.model.ClusterNode;
|
||||
import io.github.hectorvent.floci.services.elasticache.model.ElastiCacheUser;
|
||||
import io.github.hectorvent.floci.services.elasticache.model.ElastiCacheUserGroup;
|
||||
import io.github.hectorvent.floci.services.elasticache.model.Endpoint;
|
||||
import io.github.hectorvent.floci.services.elasticache.model.ReplicationGroup;
|
||||
import io.github.hectorvent.floci.services.elasticache.model.ReplicationGroupSettings;
|
||||
@@ -72,6 +73,10 @@ public class ElastiCacheQueryHandler {
|
||||
case "DescribeUsers" -> handleDescribeUsers(params);
|
||||
case "ModifyUser" -> handleModifyUser(params);
|
||||
case "DeleteUser" -> handleDeleteUser(params);
|
||||
case "CreateUserGroup" -> handleCreateUserGroup(params, region);
|
||||
case "DescribeUserGroups" -> handleDescribeUserGroups(params);
|
||||
case "ModifyUserGroup" -> handleModifyUserGroup(params);
|
||||
case "DeleteUserGroup" -> handleDeleteUserGroup(params);
|
||||
case "CreateCacheCluster" -> handleCreateCacheCluster(params, region);
|
||||
case "DescribeCacheClusters" -> handleDescribeCacheClusters(params);
|
||||
case "DeleteCacheCluster" -> handleDeleteCacheCluster(params);
|
||||
@@ -133,7 +138,8 @@ public class ElastiCacheQueryHandler {
|
||||
boolParam(params, "MultiAZEnabled"),
|
||||
intParam(params, "Port"),
|
||||
replicationGroupSettings(params),
|
||||
parseTags(params)));
|
||||
parseTags(params),
|
||||
extractMemberList(params, "UserGroupIds.member.")));
|
||||
String result = replicationGroupXml(group);
|
||||
return Response.ok(AwsQueryResponse.envelope("CreateReplicationGroup", AwsNamespaces.EC, result)).build();
|
||||
} catch (AwsException e) {
|
||||
@@ -222,15 +228,19 @@ public class ElastiCacheQueryHandler {
|
||||
return AwsQueryResponse.error("InvalidParameterValue",
|
||||
"ReplicationGroupId is required.", AwsNamespaces.EC, 400);
|
||||
}
|
||||
List<String> userIdsToAdd = extractMemberList(params, "UserGroupIdsToAdd.member.");
|
||||
List<String> userIdsToRemove = extractMemberList(params, "UserGroupIdsToRemove.member.");
|
||||
List<String> userGroupIdsToAdd = extractMemberList(params, "UserGroupIdsToAdd.member.");
|
||||
List<String> userGroupIdsToRemove = extractMemberList(params, "UserGroupIdsToRemove.member.");
|
||||
try {
|
||||
// AtRestEncryptionEnabled and KmsKeyId are fixed at create and not in the modify shape
|
||||
ReplicationGroupSettings settings = new ReplicationGroupSettings(null, null,
|
||||
optionalInt(params.getFirst("SnapshotRetentionLimit")), params.getFirst("SnapshotWindow"));
|
||||
// AuthToken with ROTATE or SET is not modelled yet; DELETE moves the cache to user groups
|
||||
ReplicationGroup group = service.modifyReplicationGroup(groupId,
|
||||
userIdsToAdd.isEmpty() ? null : userIdsToAdd,
|
||||
userIdsToRemove.isEmpty() ? null : userIdsToRemove, settings);
|
||||
userGroupIdsToAdd.isEmpty() ? null : userGroupIdsToAdd,
|
||||
userGroupIdsToRemove.isEmpty() ? null : userGroupIdsToRemove,
|
||||
Boolean.parseBoolean(params.getFirst("RemoveUserGroups")),
|
||||
"DELETE".equals(params.getFirst("AuthTokenUpdateStrategy")),
|
||||
settings);
|
||||
String result = replicationGroupXml(group);
|
||||
return Response.ok(AwsQueryResponse.envelope("ModifyReplicationGroup", AwsNamespaces.EC, result)).build();
|
||||
} catch (AwsException e) {
|
||||
@@ -319,6 +329,78 @@ public class ElastiCacheQueryHandler {
|
||||
}
|
||||
}
|
||||
|
||||
// ── User groups ───────────────────────────────────────────────────────────
|
||||
|
||||
private Response handleCreateUserGroup(MultivaluedMap<String, String> params, String region) {
|
||||
try {
|
||||
ElastiCacheUserGroup userGroup = service.createUserGroup(params.getFirst("UserGroupId"),
|
||||
params.getFirst("Engine"), extractMemberList(params, "UserIds.member."), region);
|
||||
return Response.ok(AwsQueryResponse.envelope("CreateUserGroup", AwsNamespaces.EC,
|
||||
userGroupXml(userGroup))).build();
|
||||
} catch (AwsException e) {
|
||||
return AwsQueryResponse.error(e.getErrorCode(), e.getMessage(), AwsNamespaces.EC, e.getHttpStatus());
|
||||
}
|
||||
}
|
||||
|
||||
private Response handleDescribeUserGroups(MultivaluedMap<String, String> params) {
|
||||
try {
|
||||
Collection<ElastiCacheUserGroup> userGroups = service.listUserGroups(params.getFirst("UserGroupId"));
|
||||
XmlBuilder xml = new XmlBuilder().start("UserGroups");
|
||||
for (ElastiCacheUserGroup userGroup : userGroups) {
|
||||
xml.start("member").raw(userGroupXml(userGroup)).end("member");
|
||||
}
|
||||
xml.end("UserGroups");
|
||||
return Response.ok(AwsQueryResponse.envelope("DescribeUserGroups", AwsNamespaces.EC, xml.build())).build();
|
||||
} catch (AwsException e) {
|
||||
return AwsQueryResponse.error(e.getErrorCode(), e.getMessage(), AwsNamespaces.EC, e.getHttpStatus());
|
||||
}
|
||||
}
|
||||
|
||||
private Response handleModifyUserGroup(MultivaluedMap<String, String> params) {
|
||||
try {
|
||||
ElastiCacheUserGroup userGroup = service.modifyUserGroup(params.getFirst("UserGroupId"),
|
||||
extractMemberList(params, "UserIdsToAdd.member."),
|
||||
extractMemberList(params, "UserIdsToRemove.member."),
|
||||
params.getFirst("Engine"));
|
||||
return Response.ok(AwsQueryResponse.envelope("ModifyUserGroup", AwsNamespaces.EC,
|
||||
userGroupXml(userGroup))).build();
|
||||
} catch (AwsException e) {
|
||||
return AwsQueryResponse.error(e.getErrorCode(), e.getMessage(), AwsNamespaces.EC, e.getHttpStatus());
|
||||
}
|
||||
}
|
||||
|
||||
private Response handleDeleteUserGroup(MultivaluedMap<String, String> params) {
|
||||
try {
|
||||
ElastiCacheUserGroup userGroup = service.deleteUserGroup(params.getFirst("UserGroupId"));
|
||||
return Response.ok(AwsQueryResponse.envelope("DeleteUserGroup", AwsNamespaces.EC,
|
||||
userGroupXml(userGroup))).build();
|
||||
} catch (AwsException e) {
|
||||
return AwsQueryResponse.error(e.getErrorCode(), e.getMessage(), AwsNamespaces.EC, e.getHttpStatus());
|
||||
}
|
||||
}
|
||||
|
||||
private String userGroupXml(ElastiCacheUserGroup g) {
|
||||
XmlBuilder xml = new XmlBuilder()
|
||||
.elem("UserGroupId", g.getUserGroupId())
|
||||
.elem("Status", g.getStatus())
|
||||
.elem("Engine", g.getEngine());
|
||||
xml.start("UserIds");
|
||||
for (String userId : g.getUserIds()) {
|
||||
xml.elem("member", userId);
|
||||
}
|
||||
xml.end("UserIds");
|
||||
// MinimumEngineVersion: the only value AWS documents, as on users.
|
||||
xml.elem("MinimumEngineVersion", "6.0");
|
||||
xml.start("ReplicationGroups");
|
||||
for (String replicationGroupId : service.replicationGroupIdsUsing(g.getUserGroupId())) {
|
||||
xml.elem("member", replicationGroupId);
|
||||
}
|
||||
xml.end("ReplicationGroups");
|
||||
xml.start("ServerlessCaches").end("ServerlessCaches");
|
||||
xml.elem("ARN", g.getArn());
|
||||
return xml.build();
|
||||
}
|
||||
|
||||
// ── Cache Clusters (Memcached, and single-node Redis/Valkey) ──────────────
|
||||
|
||||
private Response handleCreateCacheCluster(MultivaluedMap<String, String> params, String region) {
|
||||
@@ -407,7 +489,7 @@ public class ElastiCacheQueryHandler {
|
||||
|
||||
private String memberCacheClusterXml(ElastiCacheService.MemberCacheCluster member, boolean showNodeInfo) {
|
||||
ReplicationGroup g = member.group();
|
||||
boolean authTokenEnabled = g.getAuthMode() == AuthMode.PASSWORD;
|
||||
boolean authTokenEnabled = authTokenEnabled(g);
|
||||
XmlBuilder xml = new XmlBuilder()
|
||||
.start("CacheCluster")
|
||||
.elem("CacheClusterId", member.cacheClusterId())
|
||||
@@ -930,12 +1012,17 @@ private Response handleCreateCacheParameterGroup(MultivaluedMap<String, String>
|
||||
* aws_elasticache_replication_group: it reads transit_encryption_enabled back on every plan.
|
||||
*/
|
||||
private static boolean transitEncryptionEnabled(ReplicationGroup g) {
|
||||
return g.getAuthMode() != AuthMode.NO_AUTH;
|
||||
return g.isEncryptedInTransit();
|
||||
}
|
||||
|
||||
// a cache uses either AUTH or user groups (RBAC), so attaching a user group turns the token off
|
||||
private static boolean authTokenEnabled(ReplicationGroup g) {
|
||||
return g.getAuthMode() == AuthMode.PASSWORD && g.getUserGroupIds().isEmpty();
|
||||
}
|
||||
|
||||
private String replicationGroupXml(ReplicationGroup g) {
|
||||
Endpoint ep = g.getConfigurationEndpoint();
|
||||
boolean authTokenEnabled = g.getAuthMode() == AuthMode.PASSWORD;
|
||||
boolean authTokenEnabled = authTokenEnabled(g);
|
||||
List<ElastiCacheService.MemberCacheCluster> members = service.memberCacheClusters(g);
|
||||
XmlBuilder xml = new XmlBuilder()
|
||||
.start("ReplicationGroup")
|
||||
@@ -964,6 +1051,9 @@ private Response handleCreateCacheParameterGroup(MultivaluedMap<String, String>
|
||||
if (g.getArn() != null) {
|
||||
xml.elem("ARN", g.getArn());
|
||||
}
|
||||
if (!g.getUserGroupIds().isEmpty()) {
|
||||
xml.raw(memberListXml("UserGroupIds", g.getUserGroupIds()));
|
||||
}
|
||||
xml.start("MemberClusters");
|
||||
for (ElastiCacheService.MemberCacheCluster member : members) {
|
||||
xml.elem("ClusterId", member.cacheClusterId());
|
||||
@@ -1058,7 +1148,7 @@ private Response handleCreateCacheParameterGroup(MultivaluedMap<String, String>
|
||||
.elem("Engine", u.getEngine())
|
||||
// MinimumEngineVersion: the only value AWS documents; no valkey-specific one is published.
|
||||
.elem("MinimumEngineVersion", "6.0")
|
||||
.start("UserGroupIds").end("UserGroupIds")
|
||||
.raw(memberListXml("UserGroupIds", service.userGroupIdsContaining(u.getUserId())))
|
||||
.elem("ARN", userArn(u))
|
||||
.build();
|
||||
}
|
||||
@@ -1128,6 +1218,14 @@ private Response handleCreateCacheParameterGroup(MultivaluedMap<String, String>
|
||||
return new AwsException("InvalidParameterCombination", message, 400);
|
||||
}
|
||||
|
||||
private static String memberListXml(String name, Collection<String> values) {
|
||||
XmlBuilder xml = new XmlBuilder().start(name);
|
||||
for (String value : values) {
|
||||
xml.elem("member", value);
|
||||
}
|
||||
return xml.end(name).build();
|
||||
}
|
||||
|
||||
private static List<String> extractMemberList(MultivaluedMap<String, String> params, String prefix) {
|
||||
List<String> values = new ArrayList<>();
|
||||
for (int i = 1; ; i++) {
|
||||
|
||||
+381
-59
@@ -24,6 +24,7 @@ import io.github.hectorvent.floci.services.elasticache.model.CacheParameterGroup
|
||||
import io.github.hectorvent.floci.services.elasticache.model.CacheSubnetGroup;
|
||||
import io.github.hectorvent.floci.services.elasticache.model.ClusterNode;
|
||||
import io.github.hectorvent.floci.services.elasticache.model.ElastiCacheUser;
|
||||
import io.github.hectorvent.floci.services.elasticache.model.ElastiCacheUserGroup;
|
||||
import io.github.hectorvent.floci.services.elasticache.model.Endpoint;
|
||||
import io.github.hectorvent.floci.services.elasticache.model.ReplicationGroup;
|
||||
import io.github.hectorvent.floci.services.elasticache.model.ReplicationGroupSettings;
|
||||
@@ -42,8 +43,10 @@ import java.net.UnknownHostException;
|
||||
import java.time.Instant;
|
||||
import java.util.ArrayList;
|
||||
import java.util.Collection;
|
||||
import java.util.HashMap;
|
||||
import java.util.HashSet;
|
||||
import java.util.LinkedHashMap;
|
||||
import java.util.LinkedHashSet;
|
||||
import java.util.List;
|
||||
import java.util.Locale;
|
||||
import java.util.Map;
|
||||
@@ -72,6 +75,7 @@ public class ElastiCacheService implements ResourceProvider {
|
||||
*/
|
||||
private final StorageBackend<String, CacheCluster> memcachedClusters;
|
||||
private final StorageBackend<String, ElastiCacheUser> users;
|
||||
private final AccountAwareStorageBackend<ElastiCacheUserGroup> userGroups;
|
||||
private final AccountAwareStorageBackend<CacheParameterGroup> parameterGroups;
|
||||
private final StorageBackend<String, CacheSubnetGroup> subnetGroups;
|
||||
private final ElastiCacheContainerManager containerManager;
|
||||
@@ -108,6 +112,19 @@ public class ElastiCacheService implements ResourceProvider {
|
||||
* parameter group that no longer exists.
|
||||
*/
|
||||
private final ConcurrentHashMap<String, Integer> reservedParameterGroups = new ConcurrentHashMap<>();
|
||||
/**
|
||||
* Guards user groups, their members and their association with replication groups, so a
|
||||
* delete, a membership change and an association cannot interleave. Taken inside a
|
||||
* replication group's lock, never around one.
|
||||
*/
|
||||
private final Object userGroupLock = new Object();
|
||||
/**
|
||||
* User groups named by in-flight creates, keyed by account and id (see
|
||||
* {@link #userGroupReservationKey}) with the number of creates holding each: a
|
||||
* replication group is only stored once provisioning finishes, so the stored-groups scan
|
||||
* alone would let DeleteUserGroup remove a group that the new cache is about to use.
|
||||
*/
|
||||
private final Map<String, Integer> reservedUserGroups = new HashMap<>();
|
||||
|
||||
@Inject
|
||||
public ElastiCacheService(ElastiCacheContainerManager containerManager,
|
||||
@@ -135,6 +152,8 @@ public class ElastiCacheService implements ResourceProvider {
|
||||
new TypeReference<Map<String, CacheCluster>>() {});
|
||||
this.users = storageFactory.create("elasticache", "elasticache-users.json",
|
||||
new TypeReference<Map<String, ElastiCacheUser>>() {});
|
||||
this.userGroups = storageFactory.create("elasticache", "elasticache-user-groups.json",
|
||||
new TypeReference<Map<String, ElastiCacheUserGroup>>() {});
|
||||
this.parameterGroups = storageFactory.create("elasticache", "elasticache-parameter-groups.json",
|
||||
new TypeReference<Map<String, CacheParameterGroup>>() {});
|
||||
this.subnetGroups = storageFactory.create("elasticache", "elasticache-subnet-groups.json",
|
||||
@@ -164,7 +183,8 @@ public class ElastiCacheService implements ResourceProvider {
|
||||
Boolean multiAzEnabled,
|
||||
Integer port,
|
||||
ReplicationGroupSettings settings,
|
||||
Map<String, String> tags) {
|
||||
Map<String, String> tags,
|
||||
List<String> userGroupIds) {
|
||||
}
|
||||
|
||||
public ReplicationGroup createReplicationGroup(String groupId, String description,
|
||||
@@ -179,17 +199,59 @@ public class ElastiCacheService implements ResourceProvider {
|
||||
Map<String, String> tags) {
|
||||
return createReplicationGroup(new CreateReplicationGroupRequest(groupId, description,
|
||||
authMode, authToken, region, null, null, null, null, null, null,
|
||||
null, null, null, null, null, null, settings, tags));
|
||||
null, null, null, null, null, null, settings, tags, null));
|
||||
}
|
||||
|
||||
public ReplicationGroup createReplicationGroup(CreateReplicationGroupRequest request) {
|
||||
String groupId = request.replicationGroupId();
|
||||
ReplicationGroupSettings settings = request.settings() != null
|
||||
? request.settings() : ReplicationGroupSettings.defaults();
|
||||
settings.validate();
|
||||
// resolved with the other validations, before a port is taken or a container started
|
||||
ReplicationGroupSettings resolvedSettings =
|
||||
settings.withKmsKeyId(resolveKmsKeyArn(settings.kmsKeyId(), request.region()));
|
||||
List<String> userGroupReservation = reserveUserGroups(request);
|
||||
try {
|
||||
return createReplicationGroupWithSettings(request, resolvedSettings);
|
||||
} finally {
|
||||
releaseUserGroups(userGroupReservation);
|
||||
}
|
||||
}
|
||||
|
||||
/**
|
||||
* Checks the user groups a create names and marks them in use until the create finishes,
|
||||
* under {@link #userGroupLock} so the check and the claim cannot straddle a DeleteUserGroup.
|
||||
*/
|
||||
private List<String> reserveUserGroups(CreateReplicationGroupRequest request) {
|
||||
if (request.userGroupIds() == null || request.userGroupIds().isEmpty()) {
|
||||
return List.of();
|
||||
}
|
||||
String engine = engineFor(request);
|
||||
synchronized (userGroupLock) {
|
||||
List<String> reserved = new ArrayList<>();
|
||||
for (String userGroupId : request.userGroupIds()) {
|
||||
ElastiCacheUserGroup userGroup = getUserGroup(userGroupId);
|
||||
requireAssociable(userGroup, request.authMode() != null && request.authMode() != AuthMode.NO_AUTH, engine);
|
||||
reserved.add(userGroupReservationKey(userGroup.getUserGroupId()));
|
||||
}
|
||||
reserved.forEach(key -> reservedUserGroups.merge(key, 1, Integer::sum));
|
||||
return reserved;
|
||||
}
|
||||
}
|
||||
|
||||
private void releaseUserGroups(List<String> reserved) {
|
||||
synchronized (userGroupLock) {
|
||||
reserved.forEach(key -> reservedUserGroups.computeIfPresent(key, (k, count) -> count > 1 ? count - 1 : null));
|
||||
}
|
||||
}
|
||||
|
||||
// user groups are stored per account, so two accounts can each hold a group of the same id
|
||||
private String userGroupReservationKey(String userGroupId) {
|
||||
return userGroups.accountId() + "/" + userGroupId;
|
||||
}
|
||||
|
||||
private ReplicationGroup createReplicationGroupWithSettings(CreateReplicationGroupRequest request,
|
||||
ReplicationGroupSettings resolvedSettings) {
|
||||
String groupId = request.replicationGroupId();
|
||||
// Held until the group is persisted (or the attempt fails) so a concurrent
|
||||
// DeleteCacheParameterGroup sees the dependency before the stored-groups scan can.
|
||||
String parameterGroupReservation = reserveParameterGroup(request.cacheParameterGroupName());
|
||||
@@ -412,9 +474,10 @@ public class ElastiCacheService implements ResourceProvider {
|
||||
|
||||
private void applyCommonAttributes(ReplicationGroup group, CreateReplicationGroupRequest request,
|
||||
ReplicationGroupSettings resolvedSettings) {
|
||||
group.setEngine(request.engine() != null && !request.engine().isBlank()
|
||||
? normalizeEngine(request.engine())
|
||||
: defaultEngineForImage());
|
||||
group.setEngine(engineFor(request));
|
||||
if (request.userGroupIds() != null) {
|
||||
request.userGroupIds().forEach(id -> group.getUserGroupIds().add(normalizeUserGroupId(id)));
|
||||
}
|
||||
group.setEngineVersion(request.engineVersion() != null && !request.engineVersion().isBlank()
|
||||
? request.engineVersion()
|
||||
: defaultEngineVersion(group.getEngine()));
|
||||
@@ -432,6 +495,12 @@ public class ElastiCacheService implements ResourceProvider {
|
||||
}
|
||||
}
|
||||
|
||||
private String engineFor(CreateReplicationGroupRequest request) {
|
||||
return request.engine() != null && !request.engine().isBlank()
|
||||
? normalizeEngine(request.engine())
|
||||
: defaultEngineForImage();
|
||||
}
|
||||
|
||||
private static String defaultEngineVersion(String engine) {
|
||||
return "valkey".equals(engine) ? "8.1" : "7.1";
|
||||
}
|
||||
@@ -1452,50 +1521,98 @@ public class ElastiCacheService implements ResourceProvider {
|
||||
return members;
|
||||
}
|
||||
|
||||
public ReplicationGroup modifyReplicationGroup(String groupId, List<String> userIdsToAdd,
|
||||
List<String> userIdsToRemove) {
|
||||
return modifyReplicationGroup(groupId, userIdsToAdd, userIdsToRemove,
|
||||
public ReplicationGroup modifyReplicationGroup(String groupId, List<String> userGroupIdsToAdd,
|
||||
List<String> userGroupIdsToRemove) {
|
||||
return modifyReplicationGroup(groupId, userGroupIdsToAdd, userGroupIdsToRemove,
|
||||
ReplicationGroupSettings.unchanged());
|
||||
}
|
||||
|
||||
public ReplicationGroup modifyReplicationGroup(String groupId, List<String> userIdsToAdd,
|
||||
List<String> userIdsToRemove,
|
||||
/**
|
||||
* Each id in {@code userGroupIdsToAdd} names a user group. An id that names no user group but
|
||||
* does name a user associates that user directly, which is how Floci accepted the list before
|
||||
* it modelled user groups; AWS itself only takes user group ids here.
|
||||
*/
|
||||
public ReplicationGroup modifyReplicationGroup(String groupId, List<String> userGroupIdsToAdd,
|
||||
List<String> userGroupIdsToRemove,
|
||||
ReplicationGroupSettings settings) {
|
||||
return modifyReplicationGroup(groupId, userGroupIdsToAdd, userGroupIdsToRemove, false, false, settings);
|
||||
}
|
||||
|
||||
/**
|
||||
* {@code removeUserGroups} drops every user group the cache had before this request, and
|
||||
* {@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.
|
||||
*/
|
||||
public ReplicationGroup modifyReplicationGroup(String groupId, List<String> userGroupIdsToAdd,
|
||||
List<String> userGroupIdsToRemove,
|
||||
boolean removeUserGroups, boolean deleteAuthToken,
|
||||
ReplicationGroupSettings settings) {
|
||||
settings.validate();
|
||||
synchronized (lockFor("rg:" + groupId)) {
|
||||
ReplicationGroup group = getReplicationGroup(groupId);
|
||||
// every check before any change: the store hands out its own object, so a mutation
|
||||
// made before a later refusal would stay visible
|
||||
Set<String> nextUserIds = new HashSet<>(group.getAssociatedUserIds());
|
||||
if (userIdsToRemove != null) {
|
||||
nextUserIds.removeAll(userIdsToRemove);
|
||||
}
|
||||
if (userIdsToAdd != null) {
|
||||
for (String userId : userIdsToAdd) {
|
||||
getUser(userId);
|
||||
synchronized (userGroupLock) {
|
||||
Set<String> userGroupsToAdd = new LinkedHashSet<>();
|
||||
Set<String> directUsersToAdd = new LinkedHashSet<>();
|
||||
if (userGroupIdsToAdd != null) {
|
||||
for (String id : userGroupIdsToAdd) {
|
||||
Optional<ElastiCacheUserGroup> userGroup = userGroups.get(normalizeUserGroupId(id));
|
||||
if (userGroup.isPresent()) {
|
||||
requireAssociable(userGroup.get(), group.isEncryptedInTransit(), group.getEngine());
|
||||
userGroupsToAdd.add(userGroup.get().getUserGroupId());
|
||||
} else if (users.get(id).isPresent()) {
|
||||
directUsersToAdd.add(id);
|
||||
} else {
|
||||
throw userGroupNotFound(id);
|
||||
}
|
||||
}
|
||||
}
|
||||
nextUserIds.addAll(userIdsToAdd);
|
||||
}
|
||||
|
||||
Set<String> seenUserNames = new HashSet<>();
|
||||
for (String userId : nextUserIds) {
|
||||
ElastiCacheUser u = users.get(userId).orElse(null);
|
||||
if (u != null && !seenUserNames.add(u.getUserName())) {
|
||||
throw new AwsException("DuplicateUserNameFault",
|
||||
"Duplicate user name " + u.getUserName() + " in user group.", 400);
|
||||
Set<String> nextUserGroupIds = new LinkedHashSet<>(removeUserGroups ? Set.of() : group.getUserGroupIds());
|
||||
nextUserGroupIds.addAll(userGroupsToAdd);
|
||||
if (userGroupIdsToRemove != null) {
|
||||
userGroupIdsToRemove.forEach(id -> nextUserGroupIds.remove(normalizeUserGroupId(id)));
|
||||
}
|
||||
if (deleteAuthToken && nextUserGroupIds.isEmpty()) {
|
||||
throw new AwsException("InvalidParameterCombination",
|
||||
"AuthTokenUpdateStrategy DELETE is allowed only when transitioning to RBAC: "
|
||||
+ "add a user group in the same request.", 400);
|
||||
}
|
||||
}
|
||||
|
||||
settings.applyTo(group);
|
||||
if (userIdsToAdd != null) {
|
||||
group.getAssociatedUserIds().addAll(userIdsToAdd);
|
||||
}
|
||||
if (userIdsToRemove != null) {
|
||||
group.getAssociatedUserIds().removeAll(userIdsToRemove);
|
||||
}
|
||||
Set<String> nextUserIds = new HashSet<>(group.getAssociatedUserIds());
|
||||
nextUserIds.addAll(directUsersToAdd);
|
||||
if (userGroupIdsToRemove != null) {
|
||||
nextUserIds.removeAll(userGroupIdsToRemove);
|
||||
}
|
||||
Set<String> seenUserNames = new HashSet<>();
|
||||
for (String userId : nextUserIds) {
|
||||
ElastiCacheUser u = users.get(userId).orElse(null);
|
||||
if (u != null && !seenUserNames.add(u.getUserName())) {
|
||||
throw new AwsException("DuplicateUserNameFault",
|
||||
"Duplicate user name " + u.getUserName() + " in user group.", 400);
|
||||
}
|
||||
}
|
||||
|
||||
groups.put(groupId, group);
|
||||
return group;
|
||||
boolean hadUserGroups = !group.getUserGroupIds().isEmpty();
|
||||
settings.applyTo(group);
|
||||
group.setUserGroupIds(nextUserGroupIds);
|
||||
group.getAssociatedUserIds().addAll(directUsersToAdd);
|
||||
if (userGroupIdsToRemove != null) {
|
||||
group.getAssociatedUserIds().removeAll(userGroupIdsToRemove);
|
||||
}
|
||||
if (deleteAuthToken) {
|
||||
group.setAuthToken(null);
|
||||
}
|
||||
if (hadUserGroups && nextUserGroupIds.isEmpty()) {
|
||||
group.setTransitEncryptionEnabled(group.isEncryptedInTransit());
|
||||
group.setAuthMode(group.getAuthToken() != null ? AuthMode.PASSWORD : AuthMode.NO_AUTH);
|
||||
}
|
||||
|
||||
groups.put(groupId, group);
|
||||
return group;
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
@@ -1582,30 +1699,50 @@ public class ElastiCacheService implements ResourceProvider {
|
||||
// Storage backends hand back the live stored object, so validate everything
|
||||
// before the first setter — a rejected request must not leave changes behind.
|
||||
String normalizedEngine = (engine == null || engine.isBlank()) ? null : normalizeEngine(engine);
|
||||
if (authMode != null) {
|
||||
user.setAuthMode(authMode);
|
||||
user.setPasswords(passwords != null ? passwords : List.of());
|
||||
synchronized (userGroupLock) {
|
||||
String nextEngine = normalizedEngine != null ? normalizedEngine : user.getEngine();
|
||||
AuthMode nextAuthMode = authMode != null ? authMode : user.getAuthMode();
|
||||
if (!nextEngine.equals(user.getEngine()) || nextAuthMode != user.getAuthMode()) {
|
||||
// the user must still satisfy every user group that holds it
|
||||
for (ElastiCacheUserGroup userGroup : userGroups.scan(k -> true)) {
|
||||
if (userGroup.getUserIds().contains(userId)) {
|
||||
requireMemberAllowed(userGroup.getEngine(), userId, nextEngine, nextAuthMode);
|
||||
}
|
||||
}
|
||||
}
|
||||
if (authMode != null) {
|
||||
user.setAuthMode(authMode);
|
||||
user.setPasswords(passwords != null ? passwords : List.of());
|
||||
}
|
||||
if (accessString != null) {
|
||||
user.setAccessString(accessString);
|
||||
} else if (appendAccessString != null) {
|
||||
String current = user.getAccessString();
|
||||
user.setAccessString(current == null || current.isBlank()
|
||||
? appendAccessString
|
||||
: current + " " + appendAccessString);
|
||||
}
|
||||
if (normalizedEngine != null) {
|
||||
user.setEngine(normalizedEngine);
|
||||
}
|
||||
users.put(userId, user);
|
||||
return user;
|
||||
}
|
||||
if (accessString != null) {
|
||||
user.setAccessString(accessString);
|
||||
} else if (appendAccessString != null) {
|
||||
String current = user.getAccessString();
|
||||
user.setAccessString(current == null || current.isBlank()
|
||||
? appendAccessString
|
||||
: current + " " + appendAccessString);
|
||||
}
|
||||
if (normalizedEngine != null) {
|
||||
user.setEngine(normalizedEngine);
|
||||
}
|
||||
users.put(userId, user);
|
||||
return user;
|
||||
}
|
||||
|
||||
public void deleteUser(String userId) {
|
||||
if (users.get(userId).isEmpty()) {
|
||||
throw new AwsException("UserNotFoundFault", "User " + userId + " not found.", 404);
|
||||
}
|
||||
users.delete(userId);
|
||||
synchronized (userGroupLock) {
|
||||
users.delete(userId);
|
||||
// AWS removes a deleted user from every user group it belongs to
|
||||
for (ElastiCacheUserGroup userGroup : userGroups.scan(k -> true)) {
|
||||
if (userGroup.getUserIds().remove(userId)) {
|
||||
userGroups.put(userGroup.getUserGroupId(), userGroup);
|
||||
}
|
||||
}
|
||||
}
|
||||
for (ReplicationGroup group : groups.scan(k -> true)) {
|
||||
synchronized (lockFor("rg:" + group.getReplicationGroupId())) {
|
||||
if (group.getAssociatedUserIds().remove(userId)) {
|
||||
@@ -1616,6 +1753,178 @@ public class ElastiCacheService implements ResourceProvider {
|
||||
LOG.infov("ElastiCache user {0} deleted", userId);
|
||||
}
|
||||
|
||||
// ── User groups ───────────────────────────────────────────────────────────
|
||||
|
||||
public ElastiCacheUserGroup createUserGroup(String userGroupId, String engine, List<String> userIds,
|
||||
String region) {
|
||||
String id = normalizeUserGroupId(userGroupId);
|
||||
// Engine is required on AWS; a missing value defaults to redis as CreateUser does.
|
||||
String normalizedEngine = (engine == null || engine.isBlank()) ? "redis" : normalizeEngine(engine);
|
||||
Set<String> members = new LinkedHashSet<>(userIds != null ? userIds : List.of());
|
||||
synchronized (userGroupLock) {
|
||||
validateUserGroupMembers(normalizedEngine, members);
|
||||
if (userGroups.get(id).isPresent()) {
|
||||
throw new AwsException("UserGroupAlreadyExists",
|
||||
"User group " + id + " already exists.", 400);
|
||||
}
|
||||
ElastiCacheUserGroup userGroup = new ElastiCacheUserGroup(
|
||||
id, normalizedEngine, members, "active", Instant.now());
|
||||
userGroup.setArn(regionResolver.buildArn("elasticache", region, "usergroup:" + id));
|
||||
userGroups.put(id, userGroup);
|
||||
LOG.infov("ElastiCache user group {0} created with {1} users", id, members.size());
|
||||
return userGroup;
|
||||
}
|
||||
}
|
||||
|
||||
public ElastiCacheUserGroup getUserGroup(String userGroupId) {
|
||||
return userGroups.get(normalizeUserGroupId(userGroupId)).orElseThrow(() -> userGroupNotFound(userGroupId));
|
||||
}
|
||||
|
||||
public Collection<ElastiCacheUserGroup> listUserGroups(String filterUserGroupId) {
|
||||
if (filterUserGroupId != null && !filterUserGroupId.isBlank()) {
|
||||
return List.of(getUserGroup(filterUserGroupId));
|
||||
}
|
||||
return userGroups.scan(k -> true);
|
||||
}
|
||||
|
||||
public ElastiCacheUserGroup modifyUserGroup(String userGroupId, List<String> userIdsToAdd,
|
||||
List<String> userIdsToRemove, String engine) {
|
||||
String id = normalizeUserGroupId(userGroupId);
|
||||
synchronized (userGroupLock) {
|
||||
ElastiCacheUserGroup userGroup = getUserGroup(id);
|
||||
// Validate the resulting group before changing the stored object.
|
||||
String newEngine = (engine == null || engine.isBlank()) ? userGroup.getEngine() : normalizeEngine(engine);
|
||||
Set<String> members = new LinkedHashSet<>(userGroup.getUserIds());
|
||||
if (userIdsToAdd != null) {
|
||||
members.addAll(userIdsToAdd);
|
||||
}
|
||||
if (userIdsToRemove != null) {
|
||||
members.removeAll(userIdsToRemove);
|
||||
}
|
||||
validateUserGroupMembers(newEngine, members);
|
||||
if (!newEngine.equals(userGroup.getEngine())) {
|
||||
for (ReplicationGroup group : replicationGroupsUsing(id)) {
|
||||
requireEngineCompatible(newEngine, id, group.getEngine());
|
||||
}
|
||||
}
|
||||
userGroup.setEngine(newEngine);
|
||||
userGroup.setUserIds(members);
|
||||
userGroups.put(id, userGroup);
|
||||
return userGroup;
|
||||
}
|
||||
}
|
||||
|
||||
public ElastiCacheUserGroup deleteUserGroup(String userGroupId) {
|
||||
String id = normalizeUserGroupId(userGroupId);
|
||||
synchronized (userGroupLock) {
|
||||
ElastiCacheUserGroup userGroup = getUserGroup(id);
|
||||
List<String> replicationGroupIds = replicationGroupIdsUsing(id);
|
||||
if (!replicationGroupIds.isEmpty() || reservedUserGroups.containsKey(userGroupReservationKey(id))) {
|
||||
throw new AwsException("InvalidUserGroupState",
|
||||
"User group " + id + " is in use by a replication group. Disassociate it before deleting it.", 400);
|
||||
}
|
||||
userGroups.delete(id);
|
||||
userGroup.setStatus("deleting");
|
||||
LOG.infov("ElastiCache user group {0} deleted", id);
|
||||
return userGroup;
|
||||
}
|
||||
}
|
||||
|
||||
public List<String> replicationGroupIdsUsing(String userGroupId) {
|
||||
return replicationGroupsUsing(normalizeUserGroupId(userGroupId)).stream()
|
||||
.map(ReplicationGroup::getReplicationGroupId)
|
||||
.toList();
|
||||
}
|
||||
|
||||
public List<String> userGroupIdsContaining(String userId) {
|
||||
return userGroups.scan(k -> true).stream()
|
||||
.filter(g -> g.getUserIds().contains(userId))
|
||||
.map(ElastiCacheUserGroup::getUserGroupId)
|
||||
.toList();
|
||||
}
|
||||
|
||||
private List<ReplicationGroup> replicationGroupsUsing(String normalizedUserGroupId) {
|
||||
return groups.scan(k -> true).stream()
|
||||
.filter(g -> g.getUserGroupIds().contains(normalizedUserGroupId))
|
||||
.toList();
|
||||
}
|
||||
|
||||
/**
|
||||
* The users that can authenticate against a replication group: the members of its user
|
||||
* groups, read at the time of the check so a ModifyUserGroup applies at once, plus any user
|
||||
* associated with it directly.
|
||||
*/
|
||||
private Set<String> effectiveUserIds(ReplicationGroup group) {
|
||||
Set<String> userIds = new LinkedHashSet<>(group.getAssociatedUserIds());
|
||||
for (String userGroupId : group.getUserGroupIds()) {
|
||||
userGroups.get(userGroupId).ifPresent(g -> userIds.addAll(g.getUserIds()));
|
||||
}
|
||||
return userIds;
|
||||
}
|
||||
|
||||
/**
|
||||
* A redis user group must contain a user named {@code default}; a valkey one need not, but
|
||||
* cannot contain a user without authentication. Valkey users only join valkey user groups,
|
||||
* and two members cannot share a user name.
|
||||
*/
|
||||
private void validateUserGroupMembers(String engine, Set<String> userIds) {
|
||||
Set<String> userNames = new HashSet<>();
|
||||
boolean hasDefaultUser = false;
|
||||
for (String userId : userIds) {
|
||||
ElastiCacheUser user = getUser(userId);
|
||||
requireMemberAllowed(engine, userId, user.getEngine(), user.getAuthMode());
|
||||
if (!userNames.add(user.getUserName())) {
|
||||
throw new AwsException("DuplicateUserName",
|
||||
"More than one user in the user group has the user name " + user.getUserName() + ".", 400);
|
||||
}
|
||||
hasDefaultUser |= "default".equals(user.getUserName());
|
||||
}
|
||||
if ("redis".equals(engine) && !hasDefaultUser) {
|
||||
throw new AwsException("DefaultUserRequired", "You must add default user to a user group.", 400);
|
||||
}
|
||||
}
|
||||
|
||||
private static void requireMemberAllowed(String userGroupEngine, String userId, String userEngine,
|
||||
AuthMode authMode) {
|
||||
if ("redis".equals(userGroupEngine) && "valkey".equals(userEngine)) {
|
||||
throw new AwsException("InvalidParameterValue",
|
||||
"User " + userId + " uses the valkey engine and can only belong to valkey user groups.", 400);
|
||||
}
|
||||
if ("valkey".equals(userGroupEngine) && authMode == AuthMode.NO_AUTH) {
|
||||
throw new AwsException("InvalidParameterValue",
|
||||
"User " + userId + " requires no password and cannot belong to a valkey user group.", 400);
|
||||
}
|
||||
}
|
||||
|
||||
/** RBAC needs in-transit encryption, and a valkey user group only serves valkey caches. */
|
||||
private static void requireAssociable(ElastiCacheUserGroup userGroup, boolean encryptedInTransit, String engine) {
|
||||
if (!encryptedInTransit) {
|
||||
throw new AwsException("InvalidParameterCombination",
|
||||
"User group " + userGroup.getUserGroupId()
|
||||
+ " can only be associated with a replication group that has in-transit encryption enabled.", 400);
|
||||
}
|
||||
requireEngineCompatible(userGroup.getEngine(), userGroup.getUserGroupId(), engine);
|
||||
}
|
||||
|
||||
private static void requireEngineCompatible(String userGroupEngine, String userGroupId, String replicationGroupEngine) {
|
||||
if ("valkey".equals(userGroupEngine) && !"valkey".equals(replicationGroupEngine)) {
|
||||
throw new AwsException("InvalidParameterCombination",
|
||||
"User group " + userGroupId + " uses the valkey engine and can only be associated with a valkey cache.", 400);
|
||||
}
|
||||
}
|
||||
|
||||
private static String normalizeUserGroupId(String userGroupId) {
|
||||
if (userGroupId == null || userGroupId.isBlank()) {
|
||||
throw new AwsException("InvalidParameterValue", "UserGroupId is required.", 400);
|
||||
}
|
||||
// AWS stores the id as a lowercase string
|
||||
return userGroupId.toLowerCase(Locale.ROOT);
|
||||
}
|
||||
|
||||
private static AwsException userGroupNotFound(String userGroupId) {
|
||||
return new AwsException("UserGroupNotFound", "User group " + userGroupId + " not found.", 404);
|
||||
}
|
||||
|
||||
/**
|
||||
* Validates a Redis AUTH password for the given group.
|
||||
* Checks the group-level authToken first, then falls back to the "default" user
|
||||
@@ -1630,12 +1939,13 @@ public class ElastiCacheService implements ResourceProvider {
|
||||
}
|
||||
|
||||
if (username == null || username.isEmpty() || "default".equals(username)) {
|
||||
// AUTH password form: check group-level authToken first
|
||||
if (group.getAuthToken() != null && password.equals(group.getAuthToken())) {
|
||||
// AUTH password form: the group-level authToken first, unless user groups replaced it
|
||||
if (group.getUserGroupIds().isEmpty() && group.getAuthToken() != null
|
||||
&& password.equals(group.getAuthToken())) {
|
||||
return true;
|
||||
}
|
||||
// Fall back to the "default" user associated with this group
|
||||
Set<String> groupUserIds = group.getAssociatedUserIds();
|
||||
// Fall back to the "default" user among this group's members
|
||||
Set<String> groupUserIds = effectiveUserIds(group);
|
||||
ElastiCacheUser defaultUser = groupUserIds.stream()
|
||||
.map(id -> users.get(id).orElse(null))
|
||||
.filter(u -> u != null && "default".equals(u.getUserName()))
|
||||
@@ -1653,7 +1963,7 @@ public class ElastiCacheService implements ResourceProvider {
|
||||
return false;
|
||||
}
|
||||
// AUTH username password form: find user by userName, scoped to group
|
||||
Set<String> groupUserIds = group.getAssociatedUserIds();
|
||||
Set<String> groupUserIds = effectiveUserIds(group);
|
||||
ElastiCacheUser targetUser = groupUserIds.stream()
|
||||
.map(id -> users.get(id).orElse(null))
|
||||
.filter(u -> u != null && username.equals(u.getUserName()))
|
||||
@@ -1671,11 +1981,18 @@ public class ElastiCacheService implements ResourceProvider {
|
||||
return false;
|
||||
}
|
||||
|
||||
/**
|
||||
* Whether the proxy authenticates each user by its own mode. A user group switches that on
|
||||
* even while it has no members, since RBAC then admits nobody rather than every caller.
|
||||
*/
|
||||
public boolean hasMembers(String groupId) {
|
||||
ReplicationGroup group = groups.get(groupId).orElse(null);
|
||||
if (group == null) {
|
||||
return false;
|
||||
}
|
||||
if (!group.getUserGroupIds().isEmpty()) {
|
||||
return true;
|
||||
}
|
||||
return group.getAssociatedUserIds().stream().anyMatch(id -> users.get(id).isPresent());
|
||||
}
|
||||
|
||||
@@ -1685,7 +2002,7 @@ public class ElastiCacheService implements ResourceProvider {
|
||||
return null;
|
||||
}
|
||||
String target = (username == null || username.isEmpty()) ? "default" : username;
|
||||
return group.getAssociatedUserIds().stream()
|
||||
return effectiveUserIds(group).stream()
|
||||
.map(id -> users.get(id).orElse(null))
|
||||
.filter(u -> u != null && target.equals(u.getUserName()) && u.isEnabled())
|
||||
.map(ElastiCacheUser::getAuthMode)
|
||||
@@ -1709,6 +2026,11 @@ public class ElastiCacheService implements ResourceProvider {
|
||||
public AuthMode memberAuthMode(String username) {
|
||||
return ElastiCacheService.this.memberAuthMode(groupId, username);
|
||||
}
|
||||
|
||||
@Override
|
||||
public AuthMode authMode() {
|
||||
return groups.get(groupId).map(ReplicationGroup::getAuthMode).orElse(null);
|
||||
}
|
||||
};
|
||||
}
|
||||
|
||||
|
||||
+50
@@ -0,0 +1,50 @@
|
||||
package io.github.hectorvent.floci.services.elasticache.model;
|
||||
|
||||
import io.quarkus.runtime.annotations.RegisterForReflection;
|
||||
|
||||
import java.time.Instant;
|
||||
import java.util.LinkedHashSet;
|
||||
import java.util.Set;
|
||||
|
||||
@RegisterForReflection
|
||||
public class ElastiCacheUserGroup {
|
||||
|
||||
private String userGroupId;
|
||||
// "redis" or "valkey"
|
||||
private String engine = "redis";
|
||||
private String status;
|
||||
private Set<String> userIds = new LinkedHashSet<>();
|
||||
private Instant createdAt;
|
||||
private String arn;
|
||||
|
||||
public ElastiCacheUserGroup() {}
|
||||
|
||||
public ElastiCacheUserGroup(String userGroupId, String engine, Set<String> userIds,
|
||||
String status, Instant createdAt) {
|
||||
this.userGroupId = userGroupId;
|
||||
this.engine = engine;
|
||||
this.userIds = userIds != null ? userIds : new LinkedHashSet<>();
|
||||
this.status = status;
|
||||
this.createdAt = createdAt;
|
||||
}
|
||||
|
||||
public String getUserGroupId() { return userGroupId; }
|
||||
public void setUserGroupId(String userGroupId) { this.userGroupId = userGroupId; }
|
||||
|
||||
public String getEngine() { return engine; }
|
||||
public void setEngine(String engine) { this.engine = engine; }
|
||||
|
||||
public String getStatus() { return status; }
|
||||
public void setStatus(String status) { this.status = status; }
|
||||
|
||||
public Set<String> getUserIds() { return userIds; }
|
||||
public void setUserIds(Set<String> userIds) {
|
||||
this.userIds = userIds != null ? userIds : new LinkedHashSet<>();
|
||||
}
|
||||
|
||||
public Instant getCreatedAt() { return createdAt; }
|
||||
public void setCreatedAt(Instant createdAt) { this.createdAt = createdAt; }
|
||||
|
||||
public String getArn() { return arn; }
|
||||
public void setArn(String arn) { this.arn = arn; }
|
||||
}
|
||||
+25
@@ -1,11 +1,13 @@
|
||||
package io.github.hectorvent.floci.services.elasticache.model;
|
||||
|
||||
import com.fasterxml.jackson.annotation.JsonIgnore;
|
||||
import io.quarkus.runtime.annotations.RegisterForReflection;
|
||||
|
||||
import java.time.Instant;
|
||||
import java.util.ArrayList;
|
||||
import java.util.HashSet;
|
||||
import java.util.LinkedHashMap;
|
||||
import java.util.LinkedHashSet;
|
||||
import java.util.List;
|
||||
import java.util.Map;
|
||||
import java.util.Set;
|
||||
@@ -21,7 +23,14 @@ public class ReplicationGroup {
|
||||
private Instant createdAt;
|
||||
private int proxyPort;
|
||||
private String authToken; // stored plain-text for PASSWORD auth validation in the proxy
|
||||
/**
|
||||
* Set once the auth mode stops telling: a group whose last user group was removed has no
|
||||
* access control but is still encrypted in transit. Null otherwise, see {@link #isEncryptedInTransit}.
|
||||
*/
|
||||
private Boolean transitEncryptionEnabled;
|
||||
/** Users associated directly by user id, which Floci accepted before it modelled user groups. */
|
||||
private Set<String> associatedUserIds = new HashSet<>();
|
||||
private Set<String> userGroupIds = new LinkedHashSet<>();
|
||||
private String arn;
|
||||
private String region;
|
||||
private boolean atRestEncryptionEnabled;
|
||||
@@ -85,11 +94,27 @@ public class ReplicationGroup {
|
||||
public String getAuthToken() { return authToken; }
|
||||
public void setAuthToken(String authToken) { this.authToken = authToken; }
|
||||
|
||||
public Boolean getTransitEncryptionEnabled() { return transitEncryptionEnabled; }
|
||||
public void setTransitEncryptionEnabled(Boolean transitEncryptionEnabled) {
|
||||
this.transitEncryptionEnabled = transitEncryptionEnabled;
|
||||
}
|
||||
|
||||
/** An auth token or IAM authentication implies encryption in transit, which Floci records as the auth mode. */
|
||||
@JsonIgnore
|
||||
public boolean isEncryptedInTransit() {
|
||||
return transitEncryptionEnabled != null ? transitEncryptionEnabled : authMode != AuthMode.NO_AUTH;
|
||||
}
|
||||
|
||||
public Set<String> getAssociatedUserIds() { return associatedUserIds; }
|
||||
public void setAssociatedUserIds(Set<String> associatedUserIds) {
|
||||
this.associatedUserIds = associatedUserIds != null ? associatedUserIds : new HashSet<>();
|
||||
}
|
||||
|
||||
public Set<String> getUserGroupIds() { return userGroupIds; }
|
||||
public void setUserGroupIds(Set<String> userGroupIds) {
|
||||
this.userGroupIds = userGroupIds != null ? userGroupIds : new LinkedHashSet<>();
|
||||
}
|
||||
|
||||
public String getContainerId() { return containerId; }
|
||||
public void setContainerId(String containerId) { this.containerId = containerId; }
|
||||
|
||||
|
||||
+13
-2
@@ -40,7 +40,7 @@ public class ElastiCacheAuthProxy extends AbstractRedisAuthProxy {
|
||||
}
|
||||
return true;
|
||||
}
|
||||
return authMode != AuthMode.NO_AUTH;
|
||||
return currentAuthMode() != AuthMode.NO_AUTH;
|
||||
}
|
||||
|
||||
@Override
|
||||
@@ -74,13 +74,19 @@ public class ElastiCacheAuthProxy extends AbstractRedisAuthProxy {
|
||||
return false;
|
||||
}
|
||||
|
||||
return switch (authMode) {
|
||||
return switch (currentAuthMode()) {
|
||||
case IAM -> sigV4Validator.validate(password, groupId, effectiveUser);
|
||||
case PASSWORD -> passwordValidator.validatePassword(username, password);
|
||||
case NO_AUTH -> true;
|
||||
};
|
||||
}
|
||||
|
||||
// read per connection: removing a cache's last user group changes it while the proxy runs
|
||||
private AuthMode currentAuthMode() {
|
||||
AuthMode current = passwordValidator.authMode();
|
||||
return current != null ? current : authMode;
|
||||
}
|
||||
|
||||
@Override
|
||||
protected void closeQuietly(Socket s) {
|
||||
try {
|
||||
@@ -111,5 +117,10 @@ public class ElastiCacheAuthProxy extends AbstractRedisAuthProxy {
|
||||
default AuthMode memberAuthMode(String username) {
|
||||
return null;
|
||||
}
|
||||
|
||||
/** The cache's auth mode now, or null to keep the one the proxy started with. */
|
||||
default AuthMode authMode() {
|
||||
return null;
|
||||
}
|
||||
}
|
||||
}
|
||||
Reference in new issue
Block a user