-
Notifications
You must be signed in to change notification settings - Fork 1.1k
feat(replication): allow non-tls connections between replica and master #1419 #1490
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
Changes from all commits
7f07249
af2d393
8cbe4e3
eb45bb4
d7e3295
2ccf1fe
7645bdc
28a49b7
895427f
2e7868d
deb6e69
872e69c
ae65b0a
ce1d404
4e9ed9b
dcf35b6
5b32759
File filter
Filter by extension
Conversations
Jump to
Diff view
Diff view
There are no files selected for viewing
Original file line number | Diff line number | Diff line change |
---|---|---|
|
@@ -2,6 +2,7 @@ | |
import time | ||
import subprocess | ||
import aiohttp | ||
import os | ||
from prometheus_client.parser import text_string_to_metric_families | ||
from redis.asyncio import Redis as RedisClient | ||
|
||
|
@@ -159,6 +160,10 @@ def stop_all(self): | |
def __str__(self): | ||
return f"Factory({self.args})" | ||
|
||
@property | ||
def dfly_path(self): | ||
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. Maybe use |
||
return str(os.path.dirname(self.params.path)) | ||
|
||
|
||
def dfly_args(*args): | ||
""" Used to define a singular set of arguments for dragonfly test """ | ||
|
Original file line number | Diff line number | Diff line change |
---|---|---|
|
@@ -12,6 +12,7 @@ | |
import redis | ||
import pymemcache | ||
import random | ||
import subprocess | ||
|
||
from pathlib import Path | ||
from tempfile import TemporaryDirectory | ||
|
@@ -225,3 +226,45 @@ def port_picker(): | |
@pytest.fixture(scope="class") | ||
def memcached_connection(df_server: DflyInstance): | ||
return pymemcache.Client(f"localhost:{df_server.mc_port}") | ||
|
||
|
||
@pytest.fixture(scope="session") | ||
def gen_tls_cert(df_factory: DflyInstanceFactory): | ||
tls_server_key_file_name = "df-key.pem" | ||
tls_server_cert_file_name = "df-cert.pem" | ||
dfly_path = df_factory.dfly_path | ||
# We first need to generate the tls certificates to be used by the server | ||
|
||
# Step 1 | ||
# Generate CA (certificate authority) key and self-signed certificate | ||
# In production, CA should be generated by a third party authority | ||
# Expires in one day and is not encrtypted (-nodes) | ||
# X.509 format for the key | ||
ca_key = dfly_path + "ca-key.pem" | ||
ca_cert = dfly_path + "ca-cert.pem" | ||
step1 = rf'openssl req -x509 -newkey rsa:4096 -days 1 -nodes -keyout {ca_key} -out {ca_cert} -subj "/C=GR/ST=SKG/L=Thessaloniki/O=KK/OU=AcmeStudios/CN=Gr/[email protected]"' | ||
subprocess.run(step1, shell=True) | ||
|
||
# Step 2 | ||
# Generate Dragonfly's private key and certificate signing request (CSR) | ||
tls_server_key = dfly_path + tls_server_key_file_name | ||
tls_server_req = dfly_path + "df-req.pem" | ||
step2 = rf'openssl req -newkey rsa:4096 -nodes -keyout {tls_server_key} -out {tls_server_req} -subj "/C=GR/ST=SKG/L=Thessaloniki/O=KK/OU=Comp/CN=Gr/[email protected]"' | ||
subprocess.run(step2, shell=True) | ||
|
||
# Step 3 | ||
# Use CA's private key to sign dragonfly's CSR and get back the signed certificate | ||
tls_server_cert = dfly_path + tls_server_cert_file_name | ||
step3 = fr'openssl x509 -req -in {tls_server_req} -days 1 -CA {ca_cert} -CAkey {ca_key} -CAcreateserial -out {tls_server_cert}' | ||
subprocess.run(step3, shell=True) | ||
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. gen_tls_cert can return the path of key and certificate file names and instead of defining tls_server_cert_file_name and tls_server_key_file_name set the filenames to constant var |
||
return tls_server_key_file_name, tls_server_cert_file_name | ||
|
||
|
||
@pytest.fixture(scope="session") | ||
def with_tls_args(df_factory: DflyInstanceFactory, gen_tls_cert): | ||
tls_server_key_file_name, tls_server_cert_file_name = gen_tls_cert | ||
args = {"tls": "", | ||
"tls_key_file": df_factory.dfly_path + tls_server_key_file_name, | ||
"tls_cert_file": df_factory.dfly_path + tls_server_cert_file_name, | ||
"no_tls_on_admin_port": "true"} | ||
return args |
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.
why was this removed?
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.
Because I simplified it a little bit, it gets initialized at the top :)
Uh oh!
There was an error while loading. Please reload this page.
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.
Maybe I am missing something but in the old flow tls_sock is assigned to peer if tls_sock not null. I dont that you update peer with tls_sock in the new flow
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.
how is it working?
I would expect the test you wrote to fail.
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.
Indeed I messed this up on refactoring and HUGE thumps up for catching this. It works, because we only test the admin port and not the TLS connection itself -- we have 0 tests for that (although my other PR addresses this and it would have been caught there).