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

CORE-4182: dt/tls: Create chain of CRLs #19865

Merged
merged 1 commit into from
Jun 18, 2024
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
25 changes: 19 additions & 6 deletions tests/rptest/services/tls.py
Original file line number Diff line number Diff line change
Expand Up @@ -461,7 +461,7 @@ def __init__(self,
self._dir = tempfile.TemporaryDirectory()
self.cert_expiry_days = cert_expiry_days
self.ca_expiry_days = ca_expiry_days
self._cas = []
self._cas: list[CertificateAuthority] = []
self._cas.append(
self._create_ca(
'root-ca',
Expand All @@ -477,8 +477,7 @@ def __init__(self,
parent_cfg=self._cas[-1].cfg,
ext='signing_ca_ext',
))
self._cert_chain = self._create_ca_cert_chain(
[ca.crt for ca in self._cas])
self._cert_chain = self._create_ca_cert_chain()
self.certs = {}

@property
Expand Down Expand Up @@ -534,18 +533,32 @@ def _create_ca(self,

return CertificateAuthority(cfg, key, crt, crl)

def _create_ca_cert_chain(self, files: list[str]) -> CertificateAuthority:
def _create_ca_cert_chain(self) -> CertificateAuthority:
# First create the signing ca chain
ca_files = [ca.crt for ca in self._cas]
out = self._with_dir('ca', 'signing-ca-chain.pem')
pathlib.Path(out).touch()
with open(out, 'w') as outfile:
for fname in reversed(files):
for fname in reversed(ca_files):
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

question: I'm curious why reversed is needed here

Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

good question! The ordering does matter, we effectively want a chain of certs that ends with the root cert:

Issuer CA 1 --- signed by ---> Issuer CA 2 --- signed by ---> Root CA

I think RFC5280 deals with this but I can't find the right section to reference

with open(fname, 'r') as infile:
outfile.write(infile.read())

with open(out, 'r') as f:
self._logger.debug(f"CA chain: {f.read()}")

return CertificateAuthority(None, None, out, self._cas[-1].crl)
# Now do the same for the CRLs
crl_files = [ca.crl for ca in self._cas]
crl_out = self._with_dir('ca', 'signing-crl-chain.crl')
pathlib.Path(out).touch()
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

actually, did you mean

Suggested change
pathlib.Path(out).touch()
pathlib.Path(crl_out).touch()

Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

doesn't look like it matters, so I'm not sure what it was doing there previously 🤷

with open(crl_out, 'w') as outfile:
for fname in reversed(crl_files):
with open(fname, 'r') as infile:
outfile.write(infile.read())

with open(crl_out, 'r') as f:
self._logger.debug(f"CRL chain: {f.read()}")

return CertificateAuthority(None, None, out, crl_out)

def create_cert(self,
host: str,
Expand Down
6 changes: 4 additions & 2 deletions tests/rptest/tests/tls_metrics_test.py
Original file line number Diff line number Diff line change
Expand Up @@ -30,14 +30,16 @@
require_client_auth=True,
key_file=RedpandaService.TLS_SERVER_KEY_FILE,
cert_file=RedpandaService.TLS_SERVER_CRT_FILE,
truststore_file=RedpandaService.TLS_CA_CRT_FILE)
truststore_file=RedpandaService.TLS_CA_CRT_FILE,
crl_file=RedpandaService.TLS_CA_CRL_FILE)

ADMIN_TLS_CONFIG = dict(name='iplistener',
enabled=True,
require_client_auth=True,
key_file=RedpandaService.TLS_SERVER_KEY_FILE,
cert_file=RedpandaService.TLS_SERVER_CRT_FILE,
truststore_file=RedpandaService.TLS_CA_CRT_FILE)
truststore_file=RedpandaService.TLS_CA_CRT_FILE,
crl_file=RedpandaService.TLS_CA_CRL_FILE)


class FaketimeTLSProvider(TLSProvider):
Expand Down
Loading