mirror of
https://github.com/floci-io/floci.git
synced 2026-11-23 22:11:36 -05:00
fix(elasticache): scope single-arg AUTH to default user per Redis ACL spec (#390)
Redis 6+ ACL spec defines that AUTH <password> (single-arg form) only authenticates the "default" user. The previous implementation matched any PASSWORD user associated with the group, allowing a non-default user's password to authenticate without specifying a username. - Filter single-arg AUTH fallback to only match users with userName "default" within the group's associated user set - Add ElastiCacheServiceTest with 3 unit tests covering single-arg default-only matching, two-arg named user matching, and group auth token fallback
This commit is contained in:
2 files changed
+106
-5
No files matched your search
+8
-5
@@ -194,9 +194,10 @@ public class ElastiCacheService {
|
||||
|
||||
/**
|
||||
* Validates a Redis AUTH password for the given group.
|
||||
* Checks the group-level authToken first, then falls back to users associated
|
||||
* with the group. Only users explicitly added via ModifyReplicationGroup are
|
||||
* checked, preventing cross-group credential leakage.
|
||||
* Checks the group-level authToken first, then falls back to the "default" user
|
||||
* associated with the group (per Redis 6+ ACL spec, single-arg AUTH only
|
||||
* authenticates the default user). Only users explicitly added via
|
||||
* ModifyReplicationGroup are checked, preventing cross-group credential leakage.
|
||||
*/
|
||||
public boolean validatePassword(String groupId, String username, String password) {
|
||||
ReplicationGroup group = groups.get(groupId).orElse(null);
|
||||
@@ -209,11 +210,13 @@ public class ElastiCacheService {
|
||||
if (group.getAuthToken() != null && password.equals(group.getAuthToken())) {
|
||||
return true;
|
||||
}
|
||||
// Fall back to PASSWORD users associated with this group
|
||||
// Fall back to the "default" PASSWORD user associated with this group
|
||||
Set<String> groupUserIds = group.getAssociatedUserIds();
|
||||
return groupUserIds.stream()
|
||||
.map(id -> users.get(id).orElse(null))
|
||||
.filter(u -> u != null && u.getAuthMode() == AuthMode.PASSWORD)
|
||||
.filter(u -> u != null
|
||||
&& "default".equals(u.getUserName())
|
||||
&& u.getAuthMode() == AuthMode.PASSWORD)
|
||||
.anyMatch(u -> u.getPasswords() != null && u.getPasswords().contains(password));
|
||||
}
|
||||
// AUTH username password form: find user by userName, scoped to group
|
||||
|
||||
Reference in new issue
Block a user