Skip to content
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

Support for Traefik routing with SNI #3340

Open
dfroger opened this issue Jul 31, 2024 · 3 comments
Open

Support for Traefik routing with SNI #3340

dfroger opened this issue Jul 31, 2024 · 3 comments

Comments

@dfroger
Copy link

dfroger commented Jul 31, 2024

Hi,

I'm trying to proxy with Traefik multiple Redis instances, that run in different Docker Swarm stacks.

Traefik provide HostSNI rule to route a TCP connection to the corresponding Docker container.

So my goal would be to establish with redis-py a Redis connection with SSL providing the Server Name Identification.

This seems to be possible with ssl.SSLContext.wrap_socket:

On client connections, the optional parameter server_hostname specifies the hostname of the service which we are connecting to. This allows a single server to host multiple SSL-based services with distinct certificates, quite similarly to HTTP virtual hosts. Specifying server_hostname will raise a ValueError if server_side is true.

Then redis-py documents examples on how to pass an SSLContext with the ssl_ocsp_context=ctx argument, so it seems feasible to achieve.

Does it sound good? May in the future a ssl_server_name argument be added to redis.Redis()to simplify the usage?

I should provide feedback of my experiment on this soon.

Thanks for reading!

@dfroger
Copy link
Author

dfroger commented Jul 31, 2024

So redis-py actually use pyopenssl (not Python ssl stdlib module). Seems I need to call OpenSSL.SSL.Connection.set_tlsext_host_name(name).

Edit: it uses both.

@dfroger
Copy link
Author

dfroger commented Jul 31, 2024

Just found that: #1087

@dfroger
Copy link
Author

dfroger commented Jul 31, 2024

In redis/connection.py:SSLConnection._wrap_socket_with_ssl:

  • sslsock = context.wrap_socket(sock, server_hostname=self.host)
  • then con.connect((self.host, self.port))

I would have expected the SNI passed in wrap_socket to be possibly different of the TCP host we connect to.

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

No branches or pull requests

1 participant