feat: added support for redis username configuration

Redis introduced an Access Control List (ACL) mechanism since version 6.0. This commit implements the necessary changes to support configuring the username for Redis. Users can now define a specific username to authenticate with Redis and enhance security through the ACL feature.

Signed-off-by: chlins <chenyuzh@vmware.com>
This commit is contained in:
chlins
2023-08-04 15:04:43 +08:00
parent 807a836852
commit 32a476b840
3 changed files with 94 additions and 1 deletions

View File

@@ -546,8 +546,16 @@ func (app *App) configureRedis(configuration *configuration.Configuration) {
}
// authorize the connection
authArgs := make([]interface{}, 0, 2)
if configuration.Redis.Username != "" {
authArgs = append(authArgs, configuration.Redis.Username)
}
if configuration.Redis.Password != "" {
if _, err = conn.Do("AUTH", configuration.Redis.Password); err != nil {
authArgs = append(authArgs, configuration.Redis.Password)
}
if len(authArgs) > 0 {
if _, err = conn.Do("AUTH", authArgs...); err != nil {
defer conn.Close()
done(err)
return nil, err