Skip to content

Commit

Permalink
Handle CS.cfg file missing in DogtagCertsConfigCheck
Browse files Browse the repository at this point in the history
This should never happen but if that file disappears things have
gone really, really badly. Throw a CRITICAL error.

Fixes: #327

Signed-off-by: Rob Crittenden <rcritten@redhat.com>
  • Loading branch information
rcritten committed Mar 18, 2024
1 parent e0c09f9 commit ba7e4c0
Show file tree
Hide file tree
Showing 2 changed files with 17 additions and 2 deletions.
10 changes: 10 additions & 0 deletions src/ipahealthcheck/dogtag/ca.py
Original file line number Diff line number Diff line change
Expand Up @@ -3,6 +3,7 @@
#

import logging
import os

from ipahealthcheck.dogtag.plugin import DogtagPlugin, registry
from ipahealthcheck.core.plugin import Result
Expand Down Expand Up @@ -32,6 +33,15 @@ def check(self):
logger.debug("No CA configured, skipping dogtag config check")
return

if not os.path.exists(paths.CA_CS_CFG_PATH):
yield Result(
self, constants.CRITICAL,
key=f'{paths.CA_CS_CFG_PATH}_missing',
configfile=paths.CA_CS_CFG_PATH,
msg=f'Configuration file {paths.CA_CS_CFG_PATH} is missing'
)
return

pki_version = pki.util.Version(pki.specification_version())
if pki_version >= pki.util.Version("11.5.0"):
logger.debug(
Expand Down
9 changes: 7 additions & 2 deletions tests/test_dogtag_ca.py
Original file line number Diff line number Diff line change
Expand Up @@ -50,9 +50,10 @@ class TestCACerts(BaseTest):
@pytest.mark.skipif(
pki_version >= pki.util.Version("11.5.0"),
reason='Does not apply to PKI 11.5.0+')
@patch('os.path.exists')
@patch('ipahealthcheck.dogtag.ca.get_directive')
@patch('ipaserver.install.certs.CertDB')
def test_ca_certs_ok(self, mock_certdb, mock_directive):
def test_ca_certs_ok(self, mock_certdb, mock_directive, mock_exists):
"""Test what should be the standard case"""
trust = {
'ocspSigningCert cert-pki-ca': 'u,u,u',
Expand All @@ -62,6 +63,7 @@ def test_ca_certs_ok(self, mock_certdb, mock_directive):
'caSigningCert cert-pki-ca': 'CT,C,C',
'transportCert cert-pki-kra': 'u,u,u',
}
mock_exists.return_value = True
mock_certdb.return_value = mock_CertDB(trust)
mock_directive.side_effect = [name for name, nsstrust in trust.items()]

Expand All @@ -81,9 +83,11 @@ def test_ca_certs_ok(self, mock_certdb, mock_directive):
@pytest.mark.skipif(
pki_version >= pki.util.Version("11.5.0"),
reason='Does not apply to PKI 11.5.0+')
@patch('os.path.exists')
@patch('ipahealthcheck.dogtag.ca.get_directive')
@patch('ipaserver.install.certs.CertDB')
def test_cert_missing_from_file(self, mock_certdb, mock_directive):
def test_cert_missing_from_file(self, mock_certdb, mock_directive,
mock_exists):
"""Test a missing certificate.
Note that if it is missing from the database then this check
Expand All @@ -103,6 +107,7 @@ def test_cert_missing_from_file(self, mock_certdb, mock_directive):
location = nicknames.index('auditSigningCert cert-pki-ca')
nicknames[location] = 'NOT auditSigningCert cert-pki-ca'

mock_exists.return_value = True
mock_certdb.return_value = mock_CertDB(trust)
mock_directive.side_effect = nicknames

Expand Down

0 comments on commit ba7e4c0

Please sign in to comment.