Skip to content

Add possibility to use different passwords for Sentinel and Redis host (#1698) - #3140

Open
doosterkamp wants to merge 9 commits into
StackExchange:mainfrom
doosterkamp:main
Open

Add possibility to use different passwords for Sentinel and Redis host (#1698)#3140
doosterkamp wants to merge 9 commits into
StackExchange:mainfrom
doosterkamp:main

Conversation

@doosterkamp

@doosterkamp doosterkamp commented Jul 29, 2026

Copy link
Copy Markdown

Adding the possibility to use different passwords for Sentinel and Redis host.
Fixing the long standing issue #1698

Checklist

  • I fully and freely contribute this code in accordance with the project license (and am legally able to do so)
  • I take responsibility for this contribution's quality and correctness, including any portions produced with AI assistance (see CONTRIBUTING.md).

Comment thread src/StackExchange.Redis/ConfigurationOptions.cs
Comment thread src/StackExchange.Redis/ConfigurationOptions.cs Outdated
Append(sb, OptionKeys.User, user);
Append(sb, OptionKeys.SentinelUser, sentinelUser);
Append(sb, OptionKeys.Password, (includePassword || string.IsNullOrEmpty(password)) ? password : "*****");
Append(sb, OptionKeys.SentinelPassword, (includePassword || string.IsNullOrEmpty(SentinelPassword)) ? sentinelPassword : "*****");

Copy link
Copy Markdown
Collaborator

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

this should be checking the field, not the property; i.e. if I assign just .Password, I do not expect it to start showing in the config-string as the SentinelPassword=... value

@mgravell mgravell Jul 29, 2026

Copy link
Copy Markdown
Collaborator

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

(actually, this is only used for the empty check, but the point remains - the check should be consistent in the IsNullOrEmpty and value part)

Copy link
Copy Markdown
Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Again, wanted to go to fast ... sorry.
Has been corrected.

By the way; is there a reason you use IsNullOrEmpty and not IsNullOrWhitespace?
I always liked IsNullOrWhitpace a little more, as it also checks for (unwanted?) spaces, tabs, etc.

{
var sentinelConnection = SentinelConnect(configuration, log);
// Use separate sentinel credentials when provided on the configuration
var sentinelConfig = configuration.Clone();

@mgravell mgravell Jul 29, 2026

Copy link
Copy Markdown
Collaborator

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

this feels ... weird; I wonder whether what we should be doing is making sure that ConnectionMultiplexer stores the serverType (which is already passed in), or (preferable) just a private readonly bool _isSentinel, and using that during handshake to read from the appropriate fields properties of the non-mutated options; thoughts?

Copy link
Copy Markdown
Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I like the thought of private readonly bool _isSentinel!
It makes the intend more clear and it should make it more robust and threadsafe, avoiding issues with the handshake.

It looked like a small change, so I took the liberty to apply this (I've put it in a separate commit, so it's an easy roll-back if you don't like it)

Also, I have rolled back the cloning part and took a better look at how and where the connection was set up.
It turns out to be a small change also, so I moved the assignment of the (Sentinel) user/pw to the HandshakeAsync method.

@mgravell mgravell left a comment

Copy link
Copy Markdown
Collaborator

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Concept is great, +1; a few nits in the ConfigurationOptions piece just because that type is super weird (not your fault), and I'm not a huge fan of the clone usage - I welcome your thoughts there.

@doosterkamp

Copy link
Copy Markdown
Author

Concept is great, +1; a few nits in the ConfigurationOptions piece just because that type is super weird (not your fault), and I'm not a huge fan of the clone usage - I welcome your thoughts there.

Thanks!
I will try to fix the 'nits' today! We really need this fix and are testing with these changes as we speak.
I'm not a huge fan of the clone usage either, but it does the job for now, without a 'big' rewrite of the under-laying code ( I started trying to change that, but it got a lot bigger, very fast, so I stepped back for a moment).

@doosterkamp

doosterkamp commented Jul 29, 2026

Copy link
Copy Markdown
Author

@mgravell is there a nice/correct way to clear the CodeQL security failure or do I need to add an inline suppression message?

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

2 participants