2013-11-27 07:53:57 -06:00
|
|
|
#! /usr/bin/python2 -E
|
2011-06-17 15:47:39 -05:00
|
|
|
# Authors: Rob Crittenden <rcritten@redhat.com>
|
|
|
|
#
|
|
|
|
# Copyright (C) 2011 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/>.
|
|
|
|
#
|
|
|
|
|
|
|
|
import sys
|
2014-03-18 10:23:30 -05:00
|
|
|
import os
|
|
|
|
import shutil
|
2011-06-17 15:47:39 -05:00
|
|
|
from ipapython import ipautil
|
|
|
|
|
2014-03-18 10:23:30 -05:00
|
|
|
from ipaserver.install import installutils
|
2011-06-17 15:47:39 -05:00
|
|
|
from ipaserver.install import certs
|
2015-06-08 00:23:56 -05:00
|
|
|
from ipaserver.install.installutils import (private_ccache,
|
|
|
|
create_replica_config)
|
|
|
|
from ipaserver.install import dsinstance, ca
|
2011-06-17 15:47:39 -05:00
|
|
|
from ipapython import version
|
2015-06-08 00:23:56 -05:00
|
|
|
from ipalib import api
|
2012-11-19 09:32:28 -06:00
|
|
|
from ipapython.dn import DN
|
2011-06-17 15:47:39 -05:00
|
|
|
from ipapython.config import IPAOptionParser
|
2011-11-15 13:39:31 -06:00
|
|
|
from ipapython.ipa_log_manager import *
|
2014-06-17 04:45:43 -05:00
|
|
|
from ipaplatform.paths import paths
|
2011-06-17 15:47:39 -05:00
|
|
|
|
2014-06-17 04:45:43 -05:00
|
|
|
log_file_name = paths.IPAREPLICA_CA_INSTALL_LOG
|
2012-05-31 07:34:09 -05:00
|
|
|
REPLICA_INFO_TOP_DIR = None
|
2011-06-17 15:47:39 -05:00
|
|
|
|
|
|
|
def parse_options():
|
|
|
|
usage = "%prog [options] REPLICA_FILE"
|
|
|
|
parser = IPAOptionParser(usage=usage, version=version.VERSION)
|
|
|
|
parser.add_option("-d", "--debug", dest="debug", action="store_true",
|
|
|
|
default=False, help="gather extra debugging information")
|
|
|
|
parser.add_option("-p", "--password", dest="password", sensitive=True,
|
|
|
|
help="Directory Manager (existing master) password")
|
|
|
|
parser.add_option("-w", "--admin-password", dest="admin_password", sensitive=True,
|
|
|
|
help="Admin user Kerberos password used for connection check")
|
|
|
|
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")
|
|
|
|
parser.add_option("--skip-conncheck", dest="skip_conncheck", action="store_true",
|
|
|
|
default=False, help="skip connection check to remote master")
|
Fix schema replication from old masters
The new merged database will replicate with both the IPA and CA trees, so all
DS instances (IPA and CA on the existing master, and the merged one on the
replica) need to have the same schema.
Dogtag does all its schema modifications online. Those are replicated normally.
The basic IPA schema, however, is delivered in ldif files, which are not
replicated. The files are not present on old CA DS instances. Any schema
update that references objects in these files will fail.
The whole 99user.ldif (i.e. changes introduced dynamically over LDAP) is
replicated as a blob. If we updated the old master's CA schema dynamically
during replica install, it would conflict with updates done during the
installation: the one with the lower CSN would get lost.
Dogtag's spawn script recently grew a new flag, 'pki_clone_replicate_schema'.
Turning it off tells Dogtag to create its schema in the clone, where the IPA
modifications are taking place, so that it is not overwritten by the IPA schema
on replication.
The patch solves the problems by:
- In __spawn_instance, turning off the pki_clone_replicate_schema flag.
- Providing a script to copy the IPA schema files to the CA DS instance.
The script needs to be copied to old masters and run there.
- At replica CA install, checking if the schema is updated, and failing if not.
The --skip-schema-check option is added to ipa-{replica,ca}-install to
override the check.
All pre-3.1 CA servers in a domain will have to have the script run on them to
avoid schema replication errors.
https://fedorahosted.org/freeipa/ticket/3213
2012-10-24 03:37:16 -05:00
|
|
|
parser.add_option("--skip-schema-check", dest="skip_schema_check", action="store_true",
|
|
|
|
default=False, help="skip check for updated CA DS schema on the remote master")
|
2011-06-17 15:47:39 -05:00
|
|
|
parser.add_option("-U", "--unattended", dest="unattended", action="store_true",
|
|
|
|
default=False, help="unattended installation never prompts the user")
|
2014-06-16 03:41:57 -05:00
|
|
|
parser.add_option("--external-ca", dest="external_ca", action="store_true",
|
|
|
|
default=False, help="Generate a CSR to be signed by an external CA")
|
2014-10-08 03:51:31 -05:00
|
|
|
parser.add_option("--external-ca-type", dest="external_ca_type",
|
|
|
|
type="choice", choices=("generic", "ms-cs"),
|
|
|
|
help="Type of the external CA")
|
2014-09-24 09:31:39 -05:00
|
|
|
parser.add_option("--external-cert-file", dest="external_cert_files",
|
|
|
|
action="append", metavar="FILE",
|
|
|
|
help="File containing the IPA CA certificate and the external CA certificate chain")
|
2014-10-08 05:18:06 -05:00
|
|
|
parser.add_option("--ca-signing-algorithm", dest="ca_signing_algorithm",
|
|
|
|
type="choice",
|
|
|
|
choices=('SHA1withRSA', 'SHA256withRSA', 'SHA512withRSA'),
|
|
|
|
help="Signing algorithm of the IPA CA certificate")
|
2011-06-17 15:47:39 -05:00
|
|
|
|
|
|
|
options, args = parser.parse_args()
|
|
|
|
safe_options = parser.get_safe_opts(options)
|
|
|
|
|
2014-06-16 03:41:57 -05:00
|
|
|
if args:
|
|
|
|
filename = args[0]
|
2011-06-17 15:47:39 -05:00
|
|
|
|
2014-06-16 03:41:57 -05:00
|
|
|
if len(args) != 1:
|
|
|
|
parser.error("you must provide a file generated by "
|
|
|
|
"ipa-replica-prepare")
|
2015-06-08 00:23:56 -05:00
|
|
|
|
|
|
|
options.external_ca = None
|
|
|
|
options.external_cert_files = None
|
2014-06-16 03:41:57 -05:00
|
|
|
else:
|
|
|
|
filename = None
|
|
|
|
|
|
|
|
if options.external_ca:
|
2014-09-24 09:31:39 -05:00
|
|
|
if options.external_cert_files:
|
|
|
|
parser.error("You cannot specify --external-cert-file "
|
2014-06-16 03:41:57 -05:00
|
|
|
"together with --external-ca")
|
|
|
|
|
2014-10-08 03:51:31 -05:00
|
|
|
if options.external_ca_type and not options.external_ca:
|
|
|
|
parser.error(
|
|
|
|
"You cannot specify --external-ca-type without --external-ca")
|
|
|
|
|
2014-06-16 03:41:57 -05:00
|
|
|
return safe_options, options, filename
|
2011-06-17 15:47:39 -05:00
|
|
|
|
2014-03-18 10:23:30 -05:00
|
|
|
|
2011-06-17 15:47:39 -05:00
|
|
|
def get_dirman_password():
|
2014-03-18 10:23:30 -05:00
|
|
|
return installutils.read_password(
|
|
|
|
"Directory Manager (existing master)", confirm=False, validate=False)
|
|
|
|
|
2011-06-17 15:47:39 -05:00
|
|
|
|
2014-06-16 03:41:57 -05:00
|
|
|
def install_replica(safe_options, options, filename):
|
2012-05-31 07:34:09 -05:00
|
|
|
standard_logging_setup(log_file_name, debug=options.debug)
|
|
|
|
|
2014-03-18 10:23:30 -05:00
|
|
|
root_logger.debug('%s was invoked with argument "%s" and options: %s',
|
|
|
|
sys.argv[0], filename, safe_options)
|
|
|
|
root_logger.debug('IPA version %s', version.VENDOR_VERSION)
|
2011-06-17 15:47:39 -05:00
|
|
|
|
|
|
|
if not ipautil.file_exists(filename):
|
|
|
|
sys.exit("Replica file %s does not exist" % filename)
|
|
|
|
|
|
|
|
if not dsinstance.DsInstance().is_configured():
|
|
|
|
sys.exit("IPA server is not configured on this system.\n")
|
|
|
|
|
2011-09-27 10:44:20 -05:00
|
|
|
api.bootstrap(in_server=True)
|
|
|
|
api.finalize()
|
|
|
|
|
2011-06-17 15:47:39 -05:00
|
|
|
# get the directory manager password
|
|
|
|
dirman_password = options.password
|
|
|
|
if not dirman_password:
|
|
|
|
if options.unattended:
|
|
|
|
sys.exit('Directory Manager password required')
|
|
|
|
try:
|
|
|
|
dirman_password = get_dirman_password()
|
|
|
|
except KeyboardInterrupt:
|
|
|
|
sys.exit(0)
|
2011-10-06 01:22:08 -05:00
|
|
|
if dirman_password is None:
|
2013-07-09 05:29:21 -05:00
|
|
|
sys.exit("Directory Manager password required")
|
2011-06-17 15:47:39 -05:00
|
|
|
|
|
|
|
if not options.admin_password and not options.skip_conncheck and \
|
2014-03-18 10:23:30 -05:00
|
|
|
options.unattended:
|
|
|
|
sys.exit('admin password required')
|
2011-06-17 15:47:39 -05:00
|
|
|
|
2014-03-18 10:23:30 -05:00
|
|
|
config = create_replica_config(dirman_password, filename, options)
|
|
|
|
global REPLICA_INFO_TOP_DIR
|
|
|
|
REPLICA_INFO_TOP_DIR = config.top_dir
|
2011-06-17 15:47:39 -05:00
|
|
|
config.setup_ca = True
|
|
|
|
|
2015-06-08 00:23:56 -05:00
|
|
|
api.Backend.ldap2.connect(bind_dn=DN(('cn', 'Directory Manager')),
|
|
|
|
bind_pw=dirman_password)
|
2012-11-19 09:32:28 -06:00
|
|
|
|
2015-06-08 00:23:56 -05:00
|
|
|
options.realm_name = config.realm_name
|
|
|
|
options.domain_name = config.domain_name
|
|
|
|
options.dm_password = config.dirman_password
|
|
|
|
options.host_name = config.host_name
|
|
|
|
options.subject = config.subject_base
|
2011-08-17 14:36:18 -05:00
|
|
|
|
2015-06-08 00:23:56 -05:00
|
|
|
ca.install_check(True, config, options)
|
|
|
|
ca.install(True, config, options)
|
2012-08-15 21:53:51 -05:00
|
|
|
|
2014-03-18 10:23:30 -05:00
|
|
|
|
2014-06-16 03:41:57 -05:00
|
|
|
def install_master(safe_options, options):
|
|
|
|
standard_logging_setup(paths.IPASERVER_CA_INSTALL_LOG, debug=options.debug)
|
|
|
|
|
|
|
|
root_logger.debug(
|
2014-03-18 10:23:30 -05:00
|
|
|
"%s was invoked with options: %s", sys.argv[0], safe_options)
|
|
|
|
root_logger.debug("IPA version %s", version.VENDOR_VERSION)
|
2014-06-16 03:41:57 -05:00
|
|
|
|
|
|
|
if not dsinstance.DsInstance().is_configured():
|
|
|
|
sys.exit("IPA server is not configured on this system.\n")
|
|
|
|
|
|
|
|
api.bootstrap(in_server=True)
|
|
|
|
api.finalize()
|
|
|
|
|
|
|
|
dm_password = options.password
|
|
|
|
if not dm_password:
|
|
|
|
if options.unattended:
|
|
|
|
sys.exit('Directory Manager password required')
|
|
|
|
try:
|
|
|
|
dm_password = get_dirman_password()
|
|
|
|
except KeyboardInterrupt:
|
|
|
|
sys.exit(0)
|
|
|
|
if dm_password is None:
|
|
|
|
sys.exit("Directory Manager password required")
|
|
|
|
|
|
|
|
api.Backend.ldap2.connect(bind_dn=DN(('cn', 'Directory Manager')),
|
|
|
|
bind_pw=dm_password)
|
|
|
|
|
|
|
|
config = api.Command['config_show']()['result']
|
|
|
|
subject_base = config['ipacertificatesubjectbase'][0]
|
|
|
|
|
2015-06-08 00:23:56 -05:00
|
|
|
options.realm_name = api.env.realm
|
|
|
|
options.domain_name = api.env.domain
|
|
|
|
options.dm_password = dm_password
|
|
|
|
options.host_name = api.env.host
|
|
|
|
options.subject = subject_base
|
|
|
|
|
|
|
|
ca.install_check(True, None, options)
|
|
|
|
ca.install(True, None, options)
|
2014-06-16 03:41:57 -05:00
|
|
|
|
2014-03-18 10:23:30 -05:00
|
|
|
|
2014-06-16 03:41:57 -05:00
|
|
|
def main():
|
|
|
|
safe_options, options, filename = parse_options()
|
|
|
|
|
|
|
|
if os.geteuid() != 0:
|
|
|
|
sys.exit("\nYou must be root to run this script.\n")
|
|
|
|
|
|
|
|
if filename is not None:
|
|
|
|
install_replica(safe_options, options, filename)
|
|
|
|
else:
|
|
|
|
install_master(safe_options, options)
|
|
|
|
|
2012-05-31 07:34:09 -05:00
|
|
|
fail_message = '''
|
|
|
|
Your system may be partly configured.
|
|
|
|
Run /usr/sbin/ipa-server-install --uninstall to clean up.
|
|
|
|
'''
|
2011-06-17 15:47:39 -05:00
|
|
|
|
2012-05-31 07:34:09 -05:00
|
|
|
if __name__ == '__main__':
|
2011-06-17 15:47:39 -05:00
|
|
|
try:
|
2013-06-03 05:06:06 -05:00
|
|
|
with private_ccache():
|
|
|
|
installutils.run_script(main, log_file_name=log_file_name,
|
2014-03-18 10:23:30 -05:00
|
|
|
operation_name='ipa-ca-install',
|
|
|
|
fail_message=fail_message)
|
2012-05-31 07:34:09 -05:00
|
|
|
finally:
|
|
|
|
# always try to remove decrypted replica file
|
|
|
|
try:
|
|
|
|
if REPLICA_INFO_TOP_DIR:
|
|
|
|
shutil.rmtree(REPLICA_INFO_TOP_DIR)
|
|
|
|
except OSError:
|
|
|
|
pass
|