2013-10-16 03:51:06 -05:00
|
|
|
# Authors:
|
|
|
|
# Jan Cholasta <jcholast@redhat.com>
|
|
|
|
#
|
|
|
|
# Copyright (C) 2014 Red Hat
|
|
|
|
# see file 'COPYING' for use and warranty information
|
|
|
|
#
|
|
|
|
# This program is free software; you can redistribute it and/or modify
|
|
|
|
# it under the terms of the GNU General Public License as published by
|
|
|
|
# the Free Software Foundation, either version 3 of the License, or
|
|
|
|
# (at your option) any later version.
|
|
|
|
#
|
|
|
|
# This program is distributed in the hope that it will be useful,
|
|
|
|
# but WITHOUT ANY WARRANTY; without even the implied warranty of
|
|
|
|
# MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
|
|
|
|
# GNU General Public License for more details.
|
|
|
|
#
|
|
|
|
# You should have received a copy of the GNU General Public License
|
|
|
|
# along with this program. If not, see <http://www.gnu.org/licenses/>.
|
|
|
|
|
2017-05-23 11:35:57 -05:00
|
|
|
import logging
|
|
|
|
|
2016-12-13 09:32:32 -06:00
|
|
|
from ipaserver.install import installutils, cainstance
|
2013-10-16 03:51:06 -05:00
|
|
|
from ipalib import errors
|
2015-03-18 09:46:00 -05:00
|
|
|
from ipalib import Updater
|
2016-11-23 08:04:40 -06:00
|
|
|
from ipalib.install import certmonger
|
2013-10-16 03:51:06 -05:00
|
|
|
from ipalib.plugable import Registry
|
2014-05-29 07:47:17 -05:00
|
|
|
from ipaplatform.paths import paths
|
2013-10-16 03:51:06 -05:00
|
|
|
from ipapython.dn import DN
|
|
|
|
|
2017-05-23 11:35:57 -05:00
|
|
|
logger = logging.getLogger(__name__)
|
|
|
|
|
2013-10-16 03:51:06 -05:00
|
|
|
register = Registry()
|
|
|
|
|
|
|
|
@register()
|
2015-03-18 09:46:00 -05:00
|
|
|
class update_ca_renewal_master(Updater):
|
2013-10-16 03:51:06 -05:00
|
|
|
"""
|
|
|
|
Set CA renewal master in LDAP.
|
|
|
|
"""
|
|
|
|
|
|
|
|
def execute(self, **options):
|
2016-12-13 09:32:32 -06:00
|
|
|
ca = cainstance.CAInstance(self.api.env.realm)
|
2014-04-02 03:28:00 -05:00
|
|
|
if not ca.is_configured():
|
2017-05-23 11:35:57 -05:00
|
|
|
logger.debug("CA is not configured on this host")
|
2015-03-17 11:56:34 -05:00
|
|
|
return False, []
|
2014-04-02 03:28:00 -05:00
|
|
|
|
2015-03-18 09:46:00 -05:00
|
|
|
ldap = self.api.Backend.ldap2
|
2013-10-16 03:51:06 -05:00
|
|
|
base_dn = DN(('cn', 'masters'), ('cn', 'ipa'), ('cn', 'etc'),
|
|
|
|
self.api.env.basedn)
|
2016-05-23 09:18:02 -05:00
|
|
|
dn = DN(('cn', 'CA'), ('cn', self.api.env.host), base_dn)
|
2013-10-16 03:51:06 -05:00
|
|
|
filter = '(&(cn=CA)(ipaConfigString=caRenewalMaster))'
|
|
|
|
try:
|
|
|
|
entries = ldap.get_entries(base_dn=base_dn, filter=filter,
|
|
|
|
attrs_list=[])
|
|
|
|
except errors.NotFound:
|
|
|
|
pass
|
|
|
|
else:
|
2017-05-23 11:35:57 -05:00
|
|
|
logger.debug("found CA renewal master %s", entries[0].dn[1].value)
|
2016-05-23 09:18:02 -05:00
|
|
|
|
|
|
|
master = False
|
|
|
|
updates = []
|
|
|
|
|
|
|
|
for entry in entries:
|
|
|
|
if entry.dn == dn:
|
|
|
|
master = True
|
|
|
|
continue
|
|
|
|
|
|
|
|
updates.append({
|
|
|
|
'dn': entry.dn,
|
|
|
|
'updates': [
|
|
|
|
dict(action='remove', attr='ipaConfigString',
|
|
|
|
value='caRenewalMaster')
|
|
|
|
],
|
|
|
|
})
|
|
|
|
|
|
|
|
if master:
|
|
|
|
return False, updates
|
|
|
|
else:
|
|
|
|
return False, []
|
2013-10-16 03:51:06 -05:00
|
|
|
|
2014-09-03 02:07:16 -05:00
|
|
|
criteria = {
|
2017-01-13 02:08:42 -06:00
|
|
|
'cert-file': paths.RA_AGENT_PEM,
|
2014-09-03 02:07:16 -05:00
|
|
|
}
|
2013-10-16 03:51:06 -05:00
|
|
|
request_id = certmonger.get_request_id(criteria)
|
2014-04-02 03:28:00 -05:00
|
|
|
if request_id is not None:
|
2017-05-23 11:35:57 -05:00
|
|
|
logger.debug("found certmonger request for RA cert")
|
2013-10-16 03:51:06 -05:00
|
|
|
|
2014-09-17 08:22:19 -05:00
|
|
|
ca_name = certmonger.get_request_value(request_id, 'ca-name')
|
2014-04-02 03:28:00 -05:00
|
|
|
if ca_name is None:
|
2017-05-23 11:35:57 -05:00
|
|
|
logger.warning(
|
2017-01-13 02:08:42 -06:00
|
|
|
"certmonger request for RA cert is missing ca_name, "
|
2014-04-02 03:28:00 -05:00
|
|
|
"assuming local CA is renewal slave")
|
2015-03-17 11:56:34 -05:00
|
|
|
return False, []
|
2014-04-02 03:28:00 -05:00
|
|
|
ca_name = ca_name.strip()
|
|
|
|
|
|
|
|
if ca_name == 'dogtag-ipa-renew-agent':
|
|
|
|
pass
|
|
|
|
elif ca_name == 'dogtag-ipa-retrieve-agent-submit':
|
2015-03-17 11:56:34 -05:00
|
|
|
return False, []
|
2014-04-02 03:28:00 -05:00
|
|
|
elif ca_name == 'dogtag-ipa-ca-renew-agent':
|
2015-03-17 11:56:34 -05:00
|
|
|
return False, []
|
2014-04-02 03:28:00 -05:00
|
|
|
else:
|
2017-05-23 11:35:57 -05:00
|
|
|
logger.warning(
|
2017-01-13 02:08:42 -06:00
|
|
|
"certmonger request for RA cert has unknown ca_name '%s', "
|
2014-04-02 03:28:00 -05:00
|
|
|
"assuming local CA is renewal slave", ca_name)
|
2015-03-17 11:56:34 -05:00
|
|
|
return False, []
|
2013-10-16 03:51:06 -05:00
|
|
|
else:
|
2017-05-23 11:35:57 -05:00
|
|
|
logger.debug("certmonger request for RA cert not found")
|
2014-04-02 03:28:00 -05:00
|
|
|
|
|
|
|
config = installutils.get_directive(
|
2015-11-09 11:28:47 -06:00
|
|
|
paths.CA_CS_CFG_PATH, 'subsystem.select', '=')
|
2014-04-02 03:28:00 -05:00
|
|
|
|
|
|
|
if config == 'New':
|
|
|
|
pass
|
|
|
|
elif config == 'Clone':
|
2015-03-17 11:56:34 -05:00
|
|
|
return False, []
|
2014-04-02 03:28:00 -05:00
|
|
|
else:
|
2017-05-23 11:35:57 -05:00
|
|
|
logger.warning(
|
2014-04-02 03:28:00 -05:00
|
|
|
"CS.cfg has unknown subsystem.select value '%s', "
|
|
|
|
"assuming local CA is renewal slave", config)
|
|
|
|
return (False, False, [])
|
|
|
|
|
|
|
|
update = {
|
|
|
|
'dn': dn,
|
2015-05-05 08:12:12 -05:00
|
|
|
'updates': [
|
|
|
|
dict(action='add', attr='ipaConfigString',
|
|
|
|
value='caRenewalMaster')
|
|
|
|
],
|
2014-04-02 03:28:00 -05:00
|
|
|
}
|
|
|
|
|
2015-03-17 11:56:34 -05:00
|
|
|
return False, [update]
|