Skip to content

Commit b56bb3b

Browse files
jalee-cpuclaudeUllaakut
authored
fix: allow rediss:// TLS endpoint with separately-configured password (#2099)
Co-authored-by: Claude Sonnet 4.6 <noreply@anthropic.com> Co-authored-by: Brendan Le Glaunec <brendan@glaulabs.com>
1 parent 2c834f2 commit b56bb3b

2 files changed

Lines changed: 19 additions & 10 deletions

File tree

pkg/stash/with_redis.go

Lines changed: 10 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -39,14 +39,18 @@ func getRedisClientOptions(endpoint, password string) (*redis.Options, error) {
3939
}, nil
4040
}
4141

42-
// Ensure the password is either empty or that it matches the password
43-
// parsed from the url into redis.Options. This ensures that if the
44-
// config supplies the password but a redis url doesn't the behavior
45-
// is clear vs. failing later on at the time of the first connection
46-
// with an 'invalid password' like error.
47-
if password != "" && options.Password != password {
42+
// Ensure the passwords are consistent:
43+
// - If the URL contains a password and a separate password is also provided,
44+
// they must match to avoid silent misconfigurations.
45+
// - If the URL contains no password (e.g. rediss://host:6379) but a separate
46+
// password is provided, apply it to the options so it is used for AUTH.
47+
// This supports TLS endpoints (rediss://) with separately-configured passwords.
48+
if options.Password != "" && password != "" && options.Password != password {
4849
return nil, errPasswordsDoNotMatch
4950
}
51+
if options.Password == "" && password != "" {
52+
options.Password = password
53+
}
5054

5155
return options, nil
5256
}

pkg/stash/with_redis_test.go

Lines changed: 9 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -147,13 +147,18 @@ func Test_getRedisClientOptions(t *testing.T) {
147147
},
148148
{
149149
endpoint: "rediss://username:password@127.0.0.1:6379",
150-
password: "1234", // Ignored because password was parsed
150+
password: "1234", // Mismatched: URL has "password", config has "1234"
151151
err: errors.E("stash.WithRedisLock", errPasswordsDoNotMatch),
152152
},
153153
{
154-
endpoint: "rediss://username:password@127.0.0.1:6379",
155-
password: "1234", // Ignored because password was parsed
156-
err: errors.E("stash.WithRedisLock", errPasswordsDoNotMatch),
154+
// TLS endpoint with no embedded password + separate password:
155+
// should succeed and apply the password to options.
156+
endpoint: "rediss://127.0.0.1:6379",
157+
password: "1234",
158+
options: &redis.Options{
159+
Addr: "127.0.0.1:6379",
160+
Password: "1234",
161+
},
157162
},
158163
}
159164

0 commit comments

Comments
 (0)