2015-05-15 19:02:22 +02:00
|
|
|
#
|
|
|
|
|
# Copyright (C) 2015 FreeIPA Contributors see COPYING for license
|
|
|
|
|
#
|
|
|
|
|
|
2016-11-09 12:44:22 +01:00
|
|
|
"""
|
|
|
|
|
KRA installer module
|
|
|
|
|
"""
|
|
|
|
|
|
2018-04-05 09:21:16 +02:00
|
|
|
from __future__ import absolute_import
|
|
|
|
|
|
2021-01-25 11:40:22 -05:00
|
|
|
import logging
|
2015-08-25 15:42:25 -04:00
|
|
|
import os
|
|
|
|
|
|
2017-03-08 16:38:12 +01:00
|
|
|
from ipalib import api
|
2017-06-14 15:39:58 +02:00
|
|
|
from ipalib.install.kinit import kinit_keytab
|
2015-08-25 15:42:25 -04:00
|
|
|
from ipaplatform import services
|
2015-11-09 18:28:47 +01:00
|
|
|
from ipaplatform.paths import paths
|
2015-07-01 14:02:24 +02:00
|
|
|
from ipapython import ipautil
|
2017-03-08 08:03:13 +00:00
|
|
|
from ipapython.install.core import group
|
2019-10-04 13:30:37 +10:00
|
|
|
from ipaserver.install import ca, cainstance
|
2015-05-15 19:02:22 +02:00
|
|
|
from ipaserver.install import krainstance
|
|
|
|
|
from ipaserver.install import dsinstance
|
2016-11-09 12:44:22 +01:00
|
|
|
from ipaserver.install import service as _service
|
|
|
|
|
|
|
|
|
|
from . import dogtag
|
2015-05-15 19:02:22 +02:00
|
|
|
|
2021-01-25 11:40:22 -05:00
|
|
|
logger = logging.getLogger(__name__)
|
|
|
|
|
|
2015-05-15 19:02:22 +02:00
|
|
|
|
2015-06-10 08:50:42 +00:00
|
|
|
def install_check(api, replica_config, options):
|
2016-10-26 15:28:53 +02:00
|
|
|
if replica_config is not None and not replica_config.setup_kra:
|
|
|
|
|
return
|
|
|
|
|
|
2015-11-09 18:28:47 +01:00
|
|
|
kra = krainstance.KRAInstance(api.env.realm)
|
2015-06-10 08:50:42 +00:00
|
|
|
if kra.is_installed():
|
2015-05-15 19:02:22 +02:00
|
|
|
raise RuntimeError("KRA is already installed.")
|
|
|
|
|
|
|
|
|
|
if not options.setup_ca:
|
|
|
|
|
if cainstance.is_ca_installed_locally():
|
2015-06-10 08:50:42 +00:00
|
|
|
if api.env.dogtag_version >= 10:
|
2015-05-15 19:02:22 +02:00
|
|
|
# correct dogtag version of CA installed
|
|
|
|
|
pass
|
|
|
|
|
else:
|
|
|
|
|
raise RuntimeError(
|
|
|
|
|
"Dogtag must be version 10.2 or above to install KRA")
|
|
|
|
|
else:
|
|
|
|
|
raise RuntimeError(
|
|
|
|
|
"Dogtag CA is not installed. Please install the CA first")
|
|
|
|
|
|
|
|
|
|
if replica_config is not None:
|
2015-06-10 08:50:42 +00:00
|
|
|
if not api.Command.kra_is_enabled()['result']:
|
2015-11-30 18:18:38 +01:00
|
|
|
raise RuntimeError(
|
|
|
|
|
"KRA is not installed on the master system. Please use "
|
|
|
|
|
"'ipa-kra-install' command to install the first instance.")
|
2015-05-15 19:02:22 +02:00
|
|
|
|
|
|
|
|
|
2018-04-26 12:06:36 +02:00
|
|
|
def install(api, replica_config, options, custodia):
|
2015-05-15 19:02:22 +02:00
|
|
|
if replica_config is None:
|
2017-01-04 08:41:26 +01:00
|
|
|
if not options.setup_kra:
|
|
|
|
|
return
|
2016-10-26 09:44:49 +02:00
|
|
|
realm_name = api.env.realm
|
|
|
|
|
dm_password = options.dm_password
|
|
|
|
|
host_name = api.env.host
|
|
|
|
|
subject_base = dsinstance.DsInstance().find_subject_base()
|
|
|
|
|
|
|
|
|
|
pkcs12_info = None
|
|
|
|
|
master_host = None
|
|
|
|
|
promote = False
|
2015-05-15 19:02:22 +02:00
|
|
|
else:
|
2017-01-04 08:41:26 +01:00
|
|
|
if not replica_config.setup_kra:
|
|
|
|
|
return
|
2016-10-26 09:44:49 +02:00
|
|
|
krafile = os.path.join(replica_config.dir, 'kracert.p12')
|
2018-09-10 15:07:55 +02:00
|
|
|
with ipautil.private_ccache():
|
|
|
|
|
ccache = os.environ['KRB5CCNAME']
|
|
|
|
|
kinit_keytab(
|
|
|
|
|
'host/{env.host}@{env.realm}'.format(env=api.env),
|
|
|
|
|
paths.KRB5_KEYTAB,
|
|
|
|
|
ccache)
|
|
|
|
|
custodia.get_kra_keys(
|
|
|
|
|
krafile,
|
|
|
|
|
replica_config.dirman_password)
|
2016-10-26 09:44:49 +02:00
|
|
|
|
|
|
|
|
realm_name = replica_config.realm_name
|
|
|
|
|
dm_password = replica_config.dirman_password
|
|
|
|
|
host_name = replica_config.host_name
|
|
|
|
|
subject_base = replica_config.subject_base
|
|
|
|
|
|
|
|
|
|
pkcs12_info = (krafile,)
|
|
|
|
|
master_host = replica_config.kra_host_name
|
2018-09-10 15:07:55 +02:00
|
|
|
promote = True
|
2016-10-26 09:44:49 +02:00
|
|
|
|
2019-10-04 13:30:37 +10:00
|
|
|
ca_subject = ca.lookup_ca_subject(api, subject_base)
|
|
|
|
|
|
2016-10-26 09:44:49 +02:00
|
|
|
kra = krainstance.KRAInstance(realm_name)
|
2018-09-03 12:45:30 +02:00
|
|
|
kra.configure_instance(
|
|
|
|
|
realm_name, host_name, dm_password, dm_password,
|
|
|
|
|
subject_base=subject_base,
|
2019-10-04 13:30:37 +10:00
|
|
|
ca_subject=ca_subject,
|
2018-09-03 12:45:30 +02:00
|
|
|
pkcs12_info=pkcs12_info,
|
|
|
|
|
master_host=master_host,
|
|
|
|
|
promote=promote,
|
|
|
|
|
pki_config_override=options.pki_config_override,
|
|
|
|
|
)
|
2015-05-15 19:02:22 +02:00
|
|
|
|
2016-11-09 12:44:22 +01:00
|
|
|
_service.print_msg("Restarting the directory server")
|
2015-05-15 19:02:22 +02:00
|
|
|
ds = dsinstance.DsInstance()
|
|
|
|
|
ds.restart()
|
2017-11-08 13:21:22 -05:00
|
|
|
kra.enable_client_auth_to_db()
|
2015-05-15 19:02:22 +02:00
|
|
|
|
2017-01-04 08:41:26 +01:00
|
|
|
# Restart apache for new proxy config file
|
|
|
|
|
services.knownservices.httpd.restart(capture_output=True)
|
2019-09-30 16:47:08 +03:00
|
|
|
# Restarted named to restore bind-dyndb-ldap operation, see
|
2018-02-05 15:27:44 +01:00
|
|
|
# https://pagure.io/freeipa/issue/5813
|
2019-09-30 16:47:08 +03:00
|
|
|
named = services.knownservices.named # alias for current named
|
2018-02-05 15:27:44 +01:00
|
|
|
if named.is_running():
|
|
|
|
|
named.restart(capture_output=True)
|
2015-08-25 15:42:25 -04:00
|
|
|
|
2015-05-15 19:02:22 +02:00
|
|
|
|
2021-01-25 11:40:22 -05:00
|
|
|
def uninstall_check(options):
|
|
|
|
|
"""IPA needs to be running so pkidestroy can unregister KRA"""
|
|
|
|
|
kra = krainstance.KRAInstance(api.env.realm)
|
|
|
|
|
if not kra.is_installed():
|
|
|
|
|
return
|
|
|
|
|
|
|
|
|
|
result = ipautil.run([paths.IPACTL, 'status'],
|
|
|
|
|
raiseonerr=False)
|
|
|
|
|
|
|
|
|
|
if result.returncode not in [0, 4]:
|
|
|
|
|
try:
|
|
|
|
|
ipautil.run([paths.IPACTL, 'start'])
|
|
|
|
|
except Exception:
|
|
|
|
|
logger.info("Re-starting IPA failed, continuing uninstall")
|
|
|
|
|
|
|
|
|
|
|
2017-03-08 16:38:12 +01:00
|
|
|
def uninstall():
|
2015-11-09 18:28:47 +01:00
|
|
|
kra = krainstance.KRAInstance(api.env.realm)
|
2017-03-08 16:38:12 +01:00
|
|
|
kra.stop_tracking_certificates()
|
2015-06-10 08:50:42 +00:00
|
|
|
if kra.is_installed():
|
|
|
|
|
kra.uninstall()
|
2016-11-09 12:44:22 +01:00
|
|
|
|
|
|
|
|
|
2017-03-08 08:03:13 +00:00
|
|
|
@group
|
2016-11-09 12:44:22 +01:00
|
|
|
class KRAInstallInterface(dogtag.DogtagInstallInterface):
|
|
|
|
|
"""
|
|
|
|
|
Interface of the KRA installer
|
|
|
|
|
|
|
|
|
|
Knobs defined here will be available in:
|
|
|
|
|
* ipa-server-install
|
|
|
|
|
* ipa-replica-prepare
|
|
|
|
|
* ipa-replica-install
|
|
|
|
|
* ipa-kra-install
|
|
|
|
|
"""
|
2017-03-08 08:03:13 +00:00
|
|
|
description = "KRA"
|