File tree Expand file tree Collapse file tree 3 files changed +38
-2
lines changed
Expand file tree Collapse file tree 3 files changed +38
-2
lines changed Original file line number Diff line number Diff line change @@ -174,6 +174,9 @@ type Configuration struct {
174174 // Password string to use when making a connection.
175175 Password string `yaml:"password,omitempty"`
176176
177+ // Username string to use when making a connection.
178+ Username string `yaml:"username,omitempty"`
179+
177180 // DB specifies the database to connect to on the redis instance.
178181 DB int `yaml:"db,omitempty"`
179182
Original file line number Diff line number Diff line change @@ -18,6 +18,7 @@ import (
1818 "time"
1919
2020 "github.com/FZambia/sentinel"
21+ "github.com/distribution/distribution/v3/configuration"
2122 "github.com/distribution/reference"
2223 "github.com/docker/distribution"
2324 "github.com/docker/distribution/configuration"
@@ -582,8 +583,15 @@ func (app *App) configureRedis(configuration *configuration.Configuration) {
582583 }
583584
584585 // authorize the connection
585- if configuration .Redis .Password != "" {
586- if _ , err = conn .Do ("AUTH" , configuration .Redis .Password ); err != nil {
586+ username := configuration .Redis .Username
587+ password := configuration .Redis .Password
588+ if password != "" {
589+ authArgs := make ([]interface {}, 0 , 2 )
590+ if username != "" {
591+ authArgs = append (authArgs , username )
592+ }
593+ authArgs = append (authArgs , password )
594+ if _ , err = conn .Do ("AUTH" , authArgs ... ); err != nil {
587595 defer conn .Close ()
588596 done (err )
589597 return nil , err
Original file line number Diff line number Diff line change @@ -235,6 +235,31 @@ func TestNewAppWithRedisTLSSentinelCluster(t *testing.T) {
235235 runAppWithConfig (t , config )
236236}
237237
238+ func TestNewAppWithRedisSentinelACL (t * testing.T ) {
239+ config := configuration.Configuration {
240+ Storage : configuration.Storage {
241+ "testdriver" : nil ,
242+ "maintenance" : configuration.Parameters {"uploadpurging" : map [interface {}]interface {}{
243+ "enabled" : false ,
244+ }},
245+ },
246+ Auth : configuration.Auth {
247+ // For now, we simply test that new auth results in a viable
248+ // application.
249+ "silly" : {
250+ "realm" : "realm-test" ,
251+ "service" : "service-test" ,
252+ },
253+ },
254+ }
255+ config .Redis .Addr = "192.168.0.11:30013,192.168.0.12:30014,192.168.0.12:30015"
256+ config .Redis .DB = 0
257+ config .Redis .SentinelMasterSet = "mymaster"
258+ config .Redis .Username = "foo"
259+ config .Redis .Password = "mypwd"
260+ runAppWithConfig (t , config )
261+ }
262+
238263func runAppWithConfig (t * testing.T , config configuration.Configuration ) {
239264 ctx := context .Background ()
240265 // Mostly, with this test, given a sane configuration, we are simply
You can’t perform that action at this time.
0 commit comments