2014-03-18 10:23:30 -05:00
|
|
|
# Authors: Ade Lee <alee@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/>.
|
|
|
|
#
|
|
|
|
|
2018-04-05 02:21:16 -05:00
|
|
|
from __future__ import print_function, absolute_import
|
2015-08-12 06:44:11 -05:00
|
|
|
|
2017-05-23 11:35:57 -05:00
|
|
|
import logging
|
2017-10-20 04:10:20 -05:00
|
|
|
import os
|
2017-03-08 09:38:12 -06:00
|
|
|
import sys
|
2015-08-25 14:42:25 -05:00
|
|
|
import tempfile
|
2017-03-15 02:47:46 -05:00
|
|
|
from optparse import SUPPRESS_HELP # pylint: disable=deprecated-module
|
2015-08-25 14:42:25 -05:00
|
|
|
|
2014-03-18 10:23:30 -05:00
|
|
|
from textwrap import dedent
|
|
|
|
from ipalib import api
|
2015-10-26 11:56:57 -05:00
|
|
|
from ipalib.constants import DOMAIN_LEVEL_0
|
2014-03-18 10:23:30 -05:00
|
|
|
from ipaplatform.paths import paths
|
|
|
|
from ipapython import admintool
|
2015-08-25 14:42:25 -05:00
|
|
|
from ipaserver.install import service
|
2015-10-23 07:15:00 -05:00
|
|
|
from ipaserver.install import cainstance
|
2018-04-26 05:06:36 -05:00
|
|
|
from ipaserver.install import custodiainstance
|
2015-06-10 03:50:42 -05:00
|
|
|
from ipaserver.install import krainstance
|
2015-08-25 14:42:25 -05:00
|
|
|
from ipaserver.install import dsinstance
|
2014-03-18 10:23:30 -05:00
|
|
|
from ipaserver.install import installutils
|
2015-05-15 12:02:22 -05:00
|
|
|
from ipaserver.install.installutils import create_replica_config
|
|
|
|
from ipaserver.install import dogtaginstance
|
|
|
|
from ipaserver.install import kra
|
2015-08-25 14:42:25 -05:00
|
|
|
from ipaserver.install.installutils import ReplicaConfig
|
2014-03-18 10:23:30 -05:00
|
|
|
|
2017-05-23 11:35:57 -05:00
|
|
|
logger = logging.getLogger(__name__)
|
|
|
|
|
2014-03-18 10:23:30 -05:00
|
|
|
|
|
|
|
class KRAInstall(admintool.AdminTool):
|
|
|
|
|
|
|
|
command_name = 'ipa-kra-install'
|
|
|
|
|
2018-08-07 04:17:23 -05:00
|
|
|
usage = "%prog [options]"
|
2014-03-18 10:23:30 -05:00
|
|
|
|
|
|
|
description = "Install a master or replica KRA."
|
|
|
|
|
|
|
|
@classmethod
|
|
|
|
def add_options(cls, parser, debug_option=True):
|
|
|
|
super(KRAInstall, cls).add_options(parser, debug_option=True)
|
|
|
|
|
2014-09-01 21:49:54 -05:00
|
|
|
parser.add_option(
|
|
|
|
"--no-host-dns", dest="no_host_dns", action="store_true",
|
|
|
|
default=False,
|
|
|
|
help="Do not use DNS for hostname lookup during installation")
|
|
|
|
|
2014-03-18 10:23:30 -05:00
|
|
|
parser.add_option(
|
|
|
|
"-p", "--password",
|
|
|
|
dest="password", sensitive=True,
|
|
|
|
help="Directory Manager (existing master) password")
|
|
|
|
|
|
|
|
parser.add_option(
|
|
|
|
"-U", "--unattended",
|
|
|
|
dest="unattended", action="store_true", default=False,
|
|
|
|
help="unattended installation never prompts the user")
|
|
|
|
|
|
|
|
parser.add_option(
|
|
|
|
"--uninstall",
|
|
|
|
dest="uninstall", action="store_true", default=False,
|
2017-03-08 09:38:12 -06:00
|
|
|
help=SUPPRESS_HELP)
|
2014-03-18 10:23:30 -05:00
|
|
|
|
|
|
|
def validate_options(self, needs_root=True):
|
|
|
|
super(KRAInstall, self).validate_options(needs_root=True)
|
|
|
|
|
|
|
|
installutils.check_server_configuration()
|
|
|
|
|
2016-12-02 02:10:41 -06:00
|
|
|
api.bootstrap(in_server=True, confdir=paths.ETC_IPA)
|
2014-03-18 10:23:30 -05:00
|
|
|
api.finalize()
|
|
|
|
|
|
|
|
@classmethod
|
|
|
|
def get_command_class(cls, options, args):
|
|
|
|
if options.uninstall:
|
2017-03-08 09:38:12 -06:00
|
|
|
sys.exit(
|
|
|
|
'ERROR: Standalone KRA uninstallation was removed in '
|
|
|
|
'FreeIPA 4.5 as it had never worked properly and only caused '
|
|
|
|
'issues.')
|
2014-03-18 10:23:30 -05:00
|
|
|
else:
|
|
|
|
return KRAInstaller
|
|
|
|
|
|
|
|
|
|
|
|
class KRAInstaller(KRAInstall):
|
2015-06-10 03:50:42 -05:00
|
|
|
log_file_name = paths.IPASERVER_KRA_INSTALL_LOG
|
2014-03-18 10:23:30 -05:00
|
|
|
|
|
|
|
INSTALLER_START_MESSAGE = '''
|
|
|
|
===================================================================
|
|
|
|
This program will setup Dogtag KRA for the FreeIPA Server.
|
|
|
|
|
|
|
|
'''
|
|
|
|
|
|
|
|
FAIL_MESSAGE = '''
|
|
|
|
Your system may be partly configured.
|
2017-05-03 08:29:55 -05:00
|
|
|
If you run into issues, you may have to re-install IPA on this server.
|
2014-03-18 10:23:30 -05:00
|
|
|
'''
|
|
|
|
|
|
|
|
def validate_options(self, needs_root=True):
|
|
|
|
super(KRAInstaller, self).validate_options(needs_root=True)
|
|
|
|
|
2015-05-19 06:01:27 -05:00
|
|
|
if self.options.unattended and self.options.password is None:
|
|
|
|
self.option_parser.error(
|
|
|
|
"Directory Manager password must be specified using -p"
|
|
|
|
" in unattended mode"
|
|
|
|
)
|
|
|
|
|
2015-10-23 07:15:00 -05:00
|
|
|
if len(self.args) > 1:
|
|
|
|
self.option_parser.error("Too many arguments provided")
|
|
|
|
elif len(self.args) == 1:
|
2018-08-07 04:17:23 -05:00
|
|
|
# Domain level 0 is not supported anymore
|
|
|
|
self.option_parser.error("Domain level 0 is not supported anymore")
|
2014-03-18 10:23:30 -05:00
|
|
|
self.replica_file = self.args[0]
|
2017-10-20 04:10:20 -05:00
|
|
|
if not os.path.isfile(self.replica_file):
|
2014-03-18 10:23:30 -05:00
|
|
|
self.option_parser.error(
|
|
|
|
"Replica file %s does not exist" % self.replica_file)
|
|
|
|
|
2015-05-19 06:01:27 -05:00
|
|
|
def ask_for_options(self):
|
|
|
|
super(KRAInstaller, self).ask_for_options()
|
|
|
|
|
|
|
|
if not self.options.unattended and self.options.password is None:
|
|
|
|
self.options.password = installutils.read_password(
|
|
|
|
"Directory Manager", confirm=False,
|
|
|
|
validate=False, retry=False)
|
|
|
|
if self.options.password is None:
|
|
|
|
raise admintool.ScriptError(
|
|
|
|
"Directory Manager password required")
|
|
|
|
|
2015-11-23 06:38:11 -06:00
|
|
|
def run(self):
|
2014-03-18 10:23:30 -05:00
|
|
|
super(KRAInstaller, self).run()
|
2015-10-23 07:15:00 -05:00
|
|
|
|
2017-05-03 03:16:13 -05:00
|
|
|
# Verify DM password. This has to be called after ask_for_options(),
|
|
|
|
# so it can't be placed in validate_options().
|
|
|
|
try:
|
|
|
|
installutils.validate_dm_password_ldap(self.options.password)
|
|
|
|
except ValueError:
|
|
|
|
raise admintool.ScriptError(
|
|
|
|
"Directory Manager password is invalid")
|
|
|
|
|
2015-10-23 07:15:00 -05:00
|
|
|
if not cainstance.is_ca_installed_locally():
|
|
|
|
raise RuntimeError("Dogtag CA is not installed. "
|
2017-10-17 05:29:43 -05:00
|
|
|
"Please install a CA first with the "
|
|
|
|
"`ipa-ca-install` command.")
|
2015-10-23 07:15:00 -05:00
|
|
|
|
2016-05-17 03:35:42 -05:00
|
|
|
# check if KRA is not already installed
|
|
|
|
_kra = krainstance.KRAInstance(api)
|
|
|
|
if _kra.is_installed():
|
|
|
|
raise admintool.ScriptError("KRA already installed")
|
|
|
|
|
2015-10-23 07:15:00 -05:00
|
|
|
# this check can be done only when CA is installed
|
|
|
|
self.installing_replica = dogtaginstance.is_installing_replica("KRA")
|
|
|
|
self.options.promote = False
|
|
|
|
|
|
|
|
if self.installing_replica:
|
|
|
|
domain_level = dsinstance.get_domain_level(api)
|
|
|
|
if domain_level > DOMAIN_LEVEL_0:
|
|
|
|
self.options.promote = True
|
|
|
|
elif not self.args:
|
|
|
|
raise RuntimeError("A replica file is required.")
|
2015-11-27 06:56:09 -06:00
|
|
|
|
|
|
|
if self.args and (not self.installing_replica or self.options.promote):
|
|
|
|
raise RuntimeError("Too many parameters provided. "
|
|
|
|
"No replica file is required.")
|
2015-10-23 07:15:00 -05:00
|
|
|
|
2015-06-10 03:50:42 -05:00
|
|
|
self.options.dm_password = self.options.password
|
2015-05-15 12:02:22 -05:00
|
|
|
self.options.setup_ca = False
|
2016-12-20 07:51:40 -06:00
|
|
|
self.options.setup_kra = True
|
2014-03-18 10:23:30 -05:00
|
|
|
|
2016-10-27 03:31:45 -05:00
|
|
|
api.Backend.ldap2.connect()
|
2015-08-25 14:42:25 -05:00
|
|
|
|
|
|
|
if self.installing_replica:
|
2018-08-07 08:44:56 -05:00
|
|
|
if not self.options.promote:
|
|
|
|
# Domain level 0 is not supported anymore
|
|
|
|
raise admintool.ScriptError(
|
|
|
|
"Domain level 0 is not supported anymore")
|
|
|
|
|
2015-08-25 14:42:25 -05:00
|
|
|
if self.options.promote:
|
|
|
|
config = ReplicaConfig()
|
2016-10-24 06:17:26 -05:00
|
|
|
config.kra_host_name = None
|
2015-08-25 14:42:25 -05:00
|
|
|
config.realm_name = api.env.realm
|
|
|
|
config.host_name = api.env.host
|
|
|
|
config.domain_name = api.env.domain
|
|
|
|
config.dirman_password = self.options.password
|
2015-11-09 11:28:47 -06:00
|
|
|
config.ca_ds_port = 389
|
2015-08-25 14:42:25 -05:00
|
|
|
config.top_dir = tempfile.mkdtemp("ipa")
|
|
|
|
config.dir = config.top_dir
|
|
|
|
else:
|
|
|
|
config = create_replica_config(
|
|
|
|
self.options.password,
|
|
|
|
self.replica_file,
|
|
|
|
self.options)
|
2016-10-24 06:17:26 -05:00
|
|
|
config.kra_host_name = config.master_host_name
|
2015-08-25 14:42:25 -05:00
|
|
|
|
2016-10-26 08:28:53 -05:00
|
|
|
config.setup_kra = True
|
2018-04-26 05:06:36 -05:00
|
|
|
config.promote = self.options.promote
|
2016-10-26 08:28:53 -05:00
|
|
|
|
2015-08-25 14:42:25 -05:00
|
|
|
if config.subject_base is None:
|
2016-10-27 03:31:45 -05:00
|
|
|
attrs = api.Backend.ldap2.get_ipa_config()
|
2015-08-25 14:42:25 -05:00
|
|
|
config.subject_base = attrs.get('ipacertificatesubjectbase')[0]
|
|
|
|
|
2016-10-24 06:17:26 -05:00
|
|
|
if config.kra_host_name is None:
|
2016-10-27 03:31:45 -05:00
|
|
|
config.kra_host_name = service.find_providing_server(
|
|
|
|
'KRA', api.Backend.ldap2, api.env.ca_host)
|
2018-04-26 05:06:36 -05:00
|
|
|
custodia = custodiainstance.get_custodia_instance(
|
|
|
|
config, custodiainstance.CustodiaModes.KRA_PEER)
|
|
|
|
else:
|
|
|
|
config = None
|
|
|
|
custodia = None
|
2015-06-10 03:50:42 -05:00
|
|
|
|
2015-05-15 12:02:22 -05:00
|
|
|
try:
|
2015-08-25 14:42:25 -05:00
|
|
|
kra.install_check(api, config, self.options)
|
2015-05-15 12:02:22 -05:00
|
|
|
except RuntimeError as e:
|
|
|
|
raise admintool.ScriptError(str(e))
|
2014-03-18 10:23:30 -05:00
|
|
|
|
2015-11-23 06:38:11 -06:00
|
|
|
print(dedent(self.INSTALLER_START_MESSAGE))
|
2014-03-18 10:23:30 -05:00
|
|
|
|
|
|
|
try:
|
2018-04-26 05:06:36 -05:00
|
|
|
kra.install(api, config, self.options, custodia=custodia)
|
2014-03-18 10:23:30 -05:00
|
|
|
except:
|
2017-05-23 11:35:57 -05:00
|
|
|
logger.error('%s', dedent(self.FAIL_MESSAGE))
|
2014-03-18 10:23:30 -05:00
|
|
|
raise
|
2016-10-27 03:31:45 -05:00
|
|
|
|
2018-07-05 17:04:39 -05:00
|
|
|
# pki-spawn restarts 389-DS, reconnect
|
|
|
|
api.Backend.ldap2.close()
|
|
|
|
api.Backend.ldap2.connect()
|
|
|
|
|
|
|
|
# Enable configured services and update DNS SRV records
|
|
|
|
service.enable_services(api.env.host)
|
|
|
|
api.Command.dns_update_system_records()
|
2016-10-27 03:31:45 -05:00
|
|
|
api.Backend.ldap2.disconnect()
|