mirror of
https://salsa.debian.org/freeipa-team/freeipa.git
synced 2025-02-25 18:55:28 -06:00
Track lightweight CAs on replica installation
Add Certmonger tracking requests for lightweight CAs on replica installation. As part of this change, extract most of the lightweight CA tracking code out of ipa-certupdate and into cainstance. Fixes: https://fedorahosted.org/freeipa/ticket/6019 Reviewed-By: Martin Babinsky <mbabinsk@redhat.com>
This commit is contained in:
committed by
Martin Babinsky
parent
b36ee723b7
commit
08b7683130
@@ -1383,6 +1383,9 @@ class CAInstance(DogtagInstance):
|
||||
|
||||
self.step("enabling CA instance", self.__enable_instance)
|
||||
|
||||
self.step("configuring certmonger renewal for lightweight CAs",
|
||||
self.__add_lightweight_ca_tracking_requests)
|
||||
|
||||
self.start_creation(runtime=210)
|
||||
|
||||
def setup_lightweight_ca_key_retrieval(self):
|
||||
@@ -1448,6 +1451,22 @@ class CAInstance(DogtagInstance):
|
||||
os.chmod(keyfile, 0o600)
|
||||
os.chown(keyfile, pent.pw_uid, pent.pw_gid)
|
||||
|
||||
def __add_lightweight_ca_tracking_requests(self):
|
||||
if not self.admin_conn:
|
||||
self.ldap_connect()
|
||||
|
||||
try:
|
||||
lwcas = self.admin_conn.get_entries(
|
||||
base_dn=api.env.basedn,
|
||||
filter='(objectclass=ipaca)',
|
||||
attrs_list=['cn', 'ipacaid'],
|
||||
)
|
||||
add_lightweight_ca_tracking_requests(self.log, lwcas)
|
||||
except errors.NotFound:
|
||||
# shouldn't happen, but don't fail if it does
|
||||
root_logger.warning(
|
||||
"Did not find any lightweight CAs; nothing to track")
|
||||
|
||||
|
||||
def replica_ca_install_check(config):
|
||||
if not config.setup_ca:
|
||||
@@ -2070,6 +2089,53 @@ def ensure_default_caacl():
|
||||
api.Backend.ldap2.disconnect()
|
||||
|
||||
|
||||
def add_lightweight_ca_tracking_requests(logger, lwcas):
|
||||
"""Add tracking requests for the given lightweight CAs.
|
||||
|
||||
The entries must have the 'cn' and 'ipacaid' attributes.
|
||||
|
||||
The IPA CA, if present, is skipped.
|
||||
|
||||
"""
|
||||
for entry in lwcas:
|
||||
if ipalib.constants.IPA_CA_CN in entry['cn']:
|
||||
continue
|
||||
|
||||
nickname = "{} {}".format(
|
||||
ipalib.constants.IPA_CA_NICKNAME,
|
||||
entry['ipacaid'][0])
|
||||
criteria = {
|
||||
'cert-database': paths.PKI_TOMCAT_ALIAS_DIR,
|
||||
'cert-nickname': nickname,
|
||||
'ca-name': ipalib.constants.RENEWAL_CA_NAME,
|
||||
}
|
||||
request_id = certmonger.get_request_id(criteria)
|
||||
if request_id is None:
|
||||
try:
|
||||
certmonger.dogtag_start_tracking(
|
||||
secdir=paths.PKI_TOMCAT_ALIAS_DIR,
|
||||
pin=certmonger.get_pin('internal'),
|
||||
pinfile=None,
|
||||
nickname=nickname,
|
||||
ca=ipalib.constants.RENEWAL_CA_NAME,
|
||||
pre_command='stop_pkicad',
|
||||
post_command='renew_ca_cert "%s"' % nickname,
|
||||
)
|
||||
request_id = certmonger.get_request_id(criteria)
|
||||
certmonger.modify(request_id, profile='ipaCACertRenewal')
|
||||
logger.debug(
|
||||
'Lightweight CA renewal: '
|
||||
'added tracking request for "%s"', nickname)
|
||||
except RuntimeError as e:
|
||||
logger.error(
|
||||
'Lightweight CA renewal: Certmonger failed to '
|
||||
'start tracking certificate: %s', e)
|
||||
else:
|
||||
logger.debug(
|
||||
'Lightweight CA renewal: '
|
||||
'already tracking certificate "%s"', nickname)
|
||||
|
||||
|
||||
def update_ipa_conf():
|
||||
"""
|
||||
Update IPA configuration file to ensure that RA plugins are enabled and
|
||||
|
||||
Reference in New Issue
Block a user