-
Notifications
You must be signed in to change notification settings - Fork 2.6k
Sentinel TLS: discover_master is not respect connection type. #3128
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
Comments
I have exactly the same issue! |
I ran into a similar problem, only with authentication. I created a merge request that fixes my issue, and maybe yours also: #3376 |
Don't you fix this by passing the necessary ssl kwargs into the |
Good lord this bug is hard to track down. Thankfully ChatGPT has guided me here so I'm posting my workaround for anyone who also have this issue. First you need this class from redis.connection import SSLConnection
from redis.sentinel import SentinelManagedConnection
class SentinelManagedSSLConnection( SentinelManagedConnection, SSLConnection ):
def __init__( self, *args, **kwargs ):
kwargs.pop( "ssl", None )
super().__init__( *args, **kwargs ) Then you can use it like so s = {
"ssl": True
, "ssl_keyfile": os.path.join( Env.REDIS_CERTS, "key" )
, "ssl_certfile": os.path.join( Env.REDIS_CERTS, "cert" )
, "ssl_ca_certs": os.path.join( Env.REDIS_CERTS, "ca" )
}
sentinelObj.master_for( "mymaster", connection_class=SentinelManagedSSLConnection, **s) Basically |
@tgckpg |
Wait I misread your comment. The ssl_keyfiles, etc are for my k8s deployments. That part is optional, ymmv. |
@tgckpg using SentinelManagedSSLConnection class as you mentioned above, getting this error
Can you please suggest what i may be missing here.
|
If you are using the redis helm chart from bitnami like I did. Cert auth is probably enabled. If that's the case you should put the key and cert files into the kwargs. You can also check by exec into your redis pod and run EDIT: Also you haven't put the connection_class and kwargs args in master_for. So yeah this doesn't work. |
Verified the cli command, it works. Added the key and cert files into the kwargs but still getting error. Please help.
|
Try this. This is my working code. You should modify it to suite your needs.
from django.conf import settings
from redis.sentinel import Sentinel
k = settings.SESSION_REDIS_SENTINEL_KWARGS
s = Sentinel( settings.SESSION_REDIS_SENTINEL_LIST,
socket_timeout=30,
retry_on_timeout=30,
db=getattr(settings, 'SESSION_REDIS_DB', 0),
password=getattr(settings, 'SESSION_REDIS_PASSWORD', None),
sentinel_kwargs=k,
)
from website.injections.redis_sentinel import SentinelManagedSSLConnection
m = s.master_for(settings.SESSION_REDIS_SENTINEL_MASTER_ALIAS, connection_class=SentinelManagedSSLConnection, **k)
m.ping() |
This code worked. Thanks @tgckpg |
In case Sentinel configured with TLS , redis_master call fails with error: "Connection reset by peer", means it is not use TLS during function call.
I've checked all docs which I able to found and for me still not clear is it supported or no?
Version: 5.1.0b3
Platform: Python 3.11 MacOS
Description:
SSL were generated self signed.
My simple code:
In sentinel logs
Error accepting a client connection: error:1408F10B:SSL routines:ssl3_get_record:wrong version number (addr=IP:56828 laddr=IP:26380)
The text was updated successfully, but these errors were encountered: