Description
Version: redis-py: 4.2.0, Redis: 6.2.6
Platform: Python 3.8.3 on Ubuntu 20.04
Description:
I have deployed Redis to my Kubernetes cluster using Helm and Bitnami's repository, with an autogenerated certificate. Specifically: helm install redis-test bitnami/redis --set image.debug=true --set tls.enabled=true --set tls.autoGenerated=true --set architecture=standalone
The redis server itself is in standalone mode and works fine and has a password and certificate, that's not the problem.
The problem is in the redis-py client which cannot connect to my Redis server using the self-signed certificate.
Here is a minimum reproducible example:
import redis
r = redis.StrictRedis(
host='redactedentry.io', # <redacted>
port=1234, # <redacted>
password='<redacted>',
ssl_cert_reqs=u'none',
ssl=True)
r.info()
The ssl_cert_reqs
is there to avoid [the SSL_CERTIFICE_VERIFY_FAILED] error in #1080.
Instead, I get another stack trace after executing r.info()
:
Traceback (most recent call last):
File "/home/zenulabidin/.local/lib/python3.8/site-packages/redis/connection.py", line 821, in read_response
response = self._parser.read_response(disable_decoding=disable_decoding)
File "/home/zenulabidin/.local/lib/python3.8/site-packages/redis/connection.py", line 320, in read_response
raw = self._buffer.readline()
File "/home/zenulabidin/.local/lib/python3.8/site-packages/redis/connection.py", line 251, in readline
self._read_from_socket()
File "/home/zenulabidin/.local/lib/python3.8/site-packages/redis/connection.py", line 194, in _read_from_socket
data = self._sock.recv(socket_read_size)
File "/home/zenulabidin/anaconda3/lib/python3.8/ssl.py", line 1226, in recv
return self.read(buflen)
File "/home/zenulabidin/anaconda3/lib/python3.8/ssl.py", line 1101, in read
return self._sslobj.read(len)
ssl.SSLError: [SSL: TLSV13_ALERT_CERTIFICATE_REQUIRED] tlsv13 alert certificate required (_ssl.c:2607)
During handling of the above exception, another exception occurred:
Traceback (most recent call last):
File "<stdin>", line 1, in <module>
File "/home/zenulabidin/.local/lib/python3.8/site-packages/redis/commands/core.py", line 900, in info
return self.execute_command("INFO", **kwargs)
File "/home/zenulabidin/.local/lib/python3.8/site-packages/redis/client.py", line 1192, in execute_command
conn = self.connection or pool.get_connection(command_name, **options)
File "/home/zenulabidin/.local/lib/python3.8/site-packages/redis/connection.py", line 1386, in get_connection
connection.connect()
File "/home/zenulabidin/.local/lib/python3.8/site-packages/redis/connection.py", line 626, in connect
self.on_connect()
File "/home/zenulabidin/.local/lib/python3.8/site-packages/redis/connection.py", line 716, in on_connect
auth_response = self.read_response()
File "/home/zenulabidin/.local/lib/python3.8/site-packages/redis/connection.py", line 827, in read_response
raise ConnectionError(f"Error while reading from {hosterr}" f" : {e.args}")
redis.exceptions.ConnectionError: Error while reading from redactedentry.io:1234 : (1, '[SSL: TLSV13_ALERT_CERTIFICATE_REQUIRED] tlsv13 alert certificate required (_ssl.c:2607)')
Here are the server logs as this exception is thrown:
08:00:12.991 # oO0OoO0OoO0Oo Redis is starting oO0OoO0OoO0Oo
1:C 27 Mar 2022 08:00:12.991 # Redis version=6.2.6, bits=64, commit=00000000, modified=0, pid=1, just started
1:C 27 Mar 2022 08:00:12.991 # Configuration loaded
1:M 27 Mar 2022 08:00:12.991 * monotonic clock: POSIX clock_gettime
1:M 27 Mar 2022 08:00:12.992 * Running mode=standalone, port=6379.
1:M 27 Mar 2022 08:00:12.992 # WARNING: The TCP backlog setting of 511 cannot be enforced because /proc/sys/net/core/somaxconn is set to the lower value of 128.
1:M 27 Mar 2022 08:00:12.992 # Server initialized
1:M 27 Mar 2022 08:00:12.992 * Ready to accept connections
1:M 27 Mar 2022 08:04:12.657 # Error accepting a client connection: error:1417C0C7:SSL routines:tls_process_client_certificate:peer did not return a certificate
# The last line repeats itself every time I attempt to make a Redis call
Barring extracting the certificate from the Kubernetes container (difficult but doable) to place inside the client, how can I bypass this exception?