-
Notifications
You must be signed in to change notification settings - Fork 2.6k
Fix RedisCluster ssl_check_hostname not set to connections. For SSL verification with ssl_cert_reqs="none", check_hostname is set to False. #3637
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
Merged
petyaslavova
merged 9 commits into
redis:master
from
omerfeyzioglu:fix-ssl-verification
May 12, 2025
Merged
Changes from all commits
Commits
Show all changes
9 commits
Select commit
Hold shift + click to select a range
ec8c093
Fix SSL verification with ssl_cert_reqs=none and ssl_check_hostname=True
omerfeyzioglu ee988fd
issue number fixed
omerfeyzioglu 22c18bd
Merge branch 'master' into fix-ssl-verification
petyaslavova 042599c
Add ssl_check_hostname to REDIS_ALLOWED_KEYS and fix default value in…
omerfeyzioglu ce80c42
Merge remote changes
omerfeyzioglu 63dd464
Merge branch 'master' into fix-ssl-verification
omerfeyzioglu 0fe87e6
Applying review comments.
petyaslavova a7f307e
Merge branch 'master' into fix-ssl-verification
petyaslavova f6c68ce
Fixing linters
petyaslavova File filter
Filter by extension
Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
There are no files selected for viewing
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,56 @@ | ||
from urllib.parse import urlparse | ||
import pytest | ||
import pytest_asyncio | ||
import redis.asyncio as redis | ||
|
||
# Skip test or not based on cryptography installation | ||
try: | ||
import cryptography # noqa | ||
|
||
skip_if_cryptography = pytest.mark.skipif(False, reason="") | ||
skip_if_nocryptography = pytest.mark.skipif(False, reason="") | ||
except ImportError: | ||
skip_if_cryptography = pytest.mark.skipif(True, reason="cryptography not installed") | ||
skip_if_nocryptography = pytest.mark.skipif( | ||
True, reason="cryptography not installed" | ||
) | ||
|
||
|
||
@pytest.mark.ssl | ||
class TestSSL: | ||
"""Tests for SSL connections in asyncio.""" | ||
|
||
@pytest_asyncio.fixture() | ||
async def _get_client(self, request): | ||
ssl_url = request.config.option.redis_ssl_url | ||
p = urlparse(ssl_url)[1].split(":") | ||
client = redis.Redis(host=p[0], port=p[1], ssl=True) | ||
petyaslavova marked this conversation as resolved.
Show resolved
Hide resolved
|
||
yield client | ||
await client.aclose() | ||
|
||
async def test_ssl_with_invalid_cert(self, _get_client): | ||
"""Test SSL connection with invalid certificate.""" | ||
pass | ||
|
||
async def test_cert_reqs_none_with_check_hostname(self, request): | ||
"""Test that when ssl_cert_reqs=none is used with ssl_check_hostname=True, | ||
the connection is created successfully with check_hostname internally set to False""" | ||
ssl_url = request.config.option.redis_ssl_url | ||
parsed_url = urlparse(ssl_url) | ||
r = redis.Redis( | ||
host=parsed_url.hostname, | ||
port=parsed_url.port, | ||
ssl=True, | ||
ssl_cert_reqs="none", | ||
# Check that ssl_check_hostname is ignored, when ssl_cert_reqs=none | ||
ssl_check_hostname=True, | ||
) | ||
try: | ||
# Connection should be successful | ||
assert await r.ping() | ||
# check_hostname should have been automatically set to False | ||
assert r.connection_pool.connection_class == redis.SSLConnection | ||
conn = r.connection_pool.make_connection() | ||
assert conn.check_hostname is False | ||
finally: | ||
await r.aclose() |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Oops, something went wrong.
Add this suggestion to a batch that can be applied as a single commit.
This suggestion is invalid because no changes were made to the code.
Suggestions cannot be applied while the pull request is closed.
Suggestions cannot be applied while viewing a subset of changes.
Only one suggestion per line can be applied in a batch.
Add this suggestion to a batch that can be applied as a single commit.
Applying suggestions on deleted lines is not supported.
You must change the existing code in this line in order to create a valid suggestion.
Outdated suggestions cannot be applied.
This suggestion has been applied or marked resolved.
Suggestions cannot be applied from pending reviews.
Suggestions cannot be applied on multi-line comments.
Suggestions cannot be applied while the pull request is queued to merge.
Suggestion cannot be applied right now. Please check back later.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
This change in defaults bit us this week ;)