mirror of
https://salsa.debian.org/freeipa-team/freeipa.git
synced 2025-02-25 18:55:28 -06:00
* Convert every string specifying a DN into a DN object
* Every place a dn was manipulated in some fashion it was replaced by
the use of DN operators
* Add new DNParam parameter type for parameters which are DN's
* DN objects are used 100% of the time throughout the entire data
pipeline whenever something is logically a dn.
* Many classes now enforce DN usage for their attributes which are
dn's. This is implmented via ipautil.dn_attribute_property(). The
only permitted types for a class attribute specified to be a DN are
either None or a DN object.
* Require that every place a dn is used it must be a DN object.
This translates into lot of::
assert isinstance(dn, DN)
sprinkled through out the code. Maintaining these asserts is
valuable to preserve DN type enforcement. The asserts can be
disabled in production.
The goal of 100% DN usage 100% of the time has been realized, these
asserts are meant to preserve that.
The asserts also proved valuable in detecting functions which did
not obey their function signatures, such as the baseldap pre and
post callbacks.
* Moved ipalib.dn to ipapython.dn because DN class is shared with all
components, not just the server which uses ipalib.
* All API's now accept DN's natively, no need to convert to str (or
unicode).
* Removed ipalib.encoder and encode/decode decorators. Type conversion
is now explicitly performed in each IPASimpleLDAPObject method which
emulates a ldap.SimpleLDAPObject method.
* Entity & Entry classes now utilize DN's
* Removed __getattr__ in Entity & Entity clases. There were two
problems with it. It presented synthetic Python object attributes
based on the current LDAP data it contained. There is no way to
validate synthetic attributes using code checkers, you can't search
the code to find LDAP attribute accesses (because synthetic
attriutes look like Python attributes instead of LDAP data) and
error handling is circumscribed. Secondly __getattr__ was hiding
Python internal methods which broke class semantics.
* Replace use of methods inherited from ldap.SimpleLDAPObject via
IPAdmin class with IPAdmin methods. Directly using inherited methods
was causing us to bypass IPA logic. Mostly this meant replacing the
use of search_s() with getEntry() or getList(). Similarly direct
access of the LDAP data in classes using IPAdmin were replaced with
calls to getValue() or getValues().
* Objects returned by ldap2.find_entries() are now compatible with
either the python-ldap access methodology or the Entity/Entry access
methodology.
* All ldap operations now funnel through the common
IPASimpleLDAPObject giving us a single location where we interface
to python-ldap and perform conversions.
* The above 4 modifications means we've greatly reduced the
proliferation of multiple inconsistent ways to perform LDAP
operations. We are well on the way to having a single API in IPA for
doing LDAP (a long range goal).
* All certificate subject bases are now DN's
* DN objects were enhanced thusly:
- find, rfind, index, rindex, replace and insert methods were added
- AVA, RDN and DN classes were refactored in immutable and mutable
variants, the mutable variants are EditableAVA, EditableRDN and
EditableDN. By default we use the immutable variants preserving
important semantics. To edit a DN cast it to an EditableDN and
cast it back to DN when done editing. These issues are fully
described in other documentation.
- first_key_match was removed
- DN equalty comparison permits comparison to a basestring
* Fixed ldapupdate to work with DN's. This work included:
- Enhance test_updates.py to do more checking after applying
update. Add test for update_from_dict(). Convert code to use
unittest classes.
- Consolidated duplicate code.
- Moved code which should have been in the class into the class.
- Fix the handling of the 'deleteentry' update action. It's no longer
necessary to supply fake attributes to make it work. Detect case
where subsequent update applies a change to entry previously marked
for deletetion. General clean-up and simplification of the
'deleteentry' logic.
- Rewrote a couple of functions to be clearer and more Pythonic.
- Added documentation on the data structure being used.
- Simplfy the use of update_from_dict()
* Removed all usage of get_schema() which was being called prior to
accessing the .schema attribute of an object. If a class is using
internal lazy loading as an optimization it's not right to require
users of the interface to be aware of internal
optimization's. schema is now a property and when the schema
property is accessed it calls a private internal method to perform
the lazy loading.
* Added SchemaCache class to cache the schema's from individual
servers. This was done because of the observation we talk to
different LDAP servers, each of which may have it's own
schema. Previously we globally cached the schema from the first
server we connected to and returned that schema in all contexts. The
cache includes controls to invalidate it thus forcing a schema
refresh.
* Schema caching is now senstive to the run time context. During
install and upgrade the schema can change leading to errors due to
out-of-date cached schema. The schema cache is refreshed in these
contexts.
* We are aware of the LDAP syntax of all LDAP attributes. Every
attribute returned from an LDAP operation is passed through a
central table look-up based on it's LDAP syntax. The table key is
the LDAP syntax it's value is a Python callable that returns a
Python object matching the LDAP syntax. There are a handful of LDAP
attributes whose syntax is historically incorrect
(e.g. DistguishedNames that are defined as DirectoryStrings). The
table driven conversion mechanism is augmented with a table of
hard coded exceptions.
Currently only the following conversions occur via the table:
- dn's are converted to DN objects
- binary objects are converted to Python str objects (IPA
convention).
- everything else is converted to unicode using UTF-8 decoding (IPA
convention).
However, now that the table driven conversion mechanism is in place
it would be trivial to do things such as converting attributes
which have LDAP integer syntax into a Python integer, etc.
* Expected values in the unit tests which are a DN no longer need to
use lambda expressions to promote the returned value to a DN for
equality comparison. The return value is automatically promoted to
a DN. The lambda expressions have been removed making the code much
simpler and easier to read.
* Add class level logging to a number of classes which did not support
logging, less need for use of root_logger.
* Remove ipaserver/conn.py, it was unused.
* Consolidated duplicate code wherever it was found.
* Fixed many places that used string concatenation to form a new
string rather than string formatting operators. This is necessary
because string formatting converts it's arguments to a string prior
to building the result string. You can't concatenate a string and a
non-string.
* Simplify logic in rename_managed plugin. Use DN operators to edit
dn's.
* The live version of ipa-ldap-updater did not generate a log file.
The offline version did, now both do.
https://fedorahosted.org/freeipa/ticket/1670
https://fedorahosted.org/freeipa/ticket/1671
https://fedorahosted.org/freeipa/ticket/1672
https://fedorahosted.org/freeipa/ticket/1673
https://fedorahosted.org/freeipa/ticket/1674
https://fedorahosted.org/freeipa/ticket/1392
https://fedorahosted.org/freeipa/ticket/2872
529 lines
22 KiB
Python
Executable File
529 lines
22 KiB
Python
Executable File
#! /usr/bin/python -E
|
|
# Authors: Karl MacMillan <kmacmillan@mentalrootkit.com>
|
|
#
|
|
# Copyright (C) 2007 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
|
|
import socket
|
|
|
|
import os, pwd, shutil
|
|
import grp
|
|
from optparse import OptionGroup
|
|
|
|
from ipapython import ipautil
|
|
|
|
from ipaserver.install import dsinstance, installutils, krbinstance, service
|
|
from ipaserver.install import bindinstance, httpinstance, ntpinstance, certs
|
|
from ipaserver.install import memcacheinstance
|
|
from ipaserver.install.replication import replica_conn_check, ReplicationManager
|
|
from ipaserver.install.installutils import HostnameLocalhost, resolve_host
|
|
from ipaserver.install.installutils import ReplicaConfig, expand_replica_info, read_replica_info
|
|
from ipaserver.install.installutils import get_host_name, BadHostError
|
|
from ipaserver.plugins.ldap2 import ldap2
|
|
from ipaserver.install import cainstance
|
|
from ipalib import api, errors, util
|
|
from ipapython import version
|
|
from ipapython.config import IPAOptionParser
|
|
from ipapython import sysrestore
|
|
from ipapython import services as ipaservices
|
|
from ipapython.ipa_log_manager import *
|
|
from ipapython.dn import DN
|
|
|
|
log_file_name = "/var/log/ipareplica-install.log"
|
|
CACERT = "/etc/ipa/ca.crt"
|
|
REPLICA_INFO_TOP_DIR = None
|
|
|
|
def parse_options():
|
|
usage = "%prog [options] REPLICA_FILE"
|
|
parser = IPAOptionParser(usage=usage, version=version.VERSION)
|
|
|
|
basic_group = OptionGroup(parser, "basic options")
|
|
basic_group.add_option("--setup-ca", dest="setup_ca", action="store_true",
|
|
default=False, help="configure a dogtag CA")
|
|
basic_group.add_option("--ip-address", dest="ip_address",
|
|
type="ip", ip_local=True,
|
|
help="Replica server IP Address")
|
|
basic_group.add_option("-p", "--password", dest="password", sensitive=True,
|
|
help="Directory Manager (existing master) password")
|
|
basic_group.add_option("-w", "--admin-password", dest="admin_password", sensitive=True,
|
|
help="Admin user Kerberos password used for connection check")
|
|
basic_group.add_option("-N", "--no-ntp", dest="conf_ntp", action="store_false",
|
|
help="do not configure ntp", default=True)
|
|
basic_group.add_option("--no-ui-redirect", dest="ui_redirect", action="store_false",
|
|
default=True, help="Do not automatically redirect to the Web UI")
|
|
basic_group.add_option("--ssh-trust-dns", dest="trust_sshfp", default=False, action="store_true",
|
|
help="configure OpenSSH client to trust DNS SSHFP records")
|
|
basic_group.add_option("--no-sshd", dest="conf_sshd", default=True, action="store_false",
|
|
help="do not configure OpenSSH server")
|
|
basic_group.add_option("--skip-conncheck", dest="skip_conncheck", action="store_true",
|
|
default=False, help="skip connection check to remote master")
|
|
basic_group.add_option("-d", "--debug", dest="debug", action="store_true",
|
|
default=False, help="gather extra debugging information")
|
|
basic_group.add_option("-U", "--unattended", dest="unattended", action="store_true",
|
|
default=False, help="unattended installation never prompts the user")
|
|
parser.add_option_group(basic_group)
|
|
|
|
cert_group = OptionGroup(parser, "certificate system options")
|
|
cert_group.add_option("--no-pkinit", dest="setup_pkinit", action="store_false",
|
|
default=True, help="disables pkinit setup steps")
|
|
parser.add_option_group(cert_group)
|
|
|
|
dns_group = OptionGroup(parser, "DNS options")
|
|
dns_group.add_option("--setup-dns", dest="setup_dns", action="store_true",
|
|
default=False, help="configure bind with our zone")
|
|
dns_group.add_option("--forwarder", dest="forwarders", action="append",
|
|
type="ip", help="Add a DNS forwarder")
|
|
dns_group.add_option("--no-forwarders", dest="no_forwarders", action="store_true",
|
|
default=False, help="Do not add any DNS forwarders, use root servers instead")
|
|
dns_group.add_option("--reverse-zone", dest="reverse_zone", help="The reverse DNS zone to use")
|
|
dns_group.add_option("--no-reverse", dest="no_reverse", action="store_true",
|
|
default=False, help="Do not create new reverse DNS zone")
|
|
dns_group.add_option("--no-host-dns", dest="no_host_dns", action="store_true",
|
|
default=False,
|
|
help="Do not use DNS for hostname lookup during installation")
|
|
dns_group.add_option("--no-dns-sshfp", dest="create_sshfp", default=True, action="store_false",
|
|
help="do not automatically create DNS SSHFP records")
|
|
parser.add_option_group(dns_group)
|
|
|
|
options, args = parser.parse_args()
|
|
safe_options = parser.get_safe_opts(options)
|
|
|
|
if len(args) != 1:
|
|
parser.error("you must provide a file generated by ipa-replica-prepare")
|
|
|
|
if not options.setup_dns:
|
|
if options.forwarders:
|
|
parser.error("You cannot specify a --forwarder option without the --setup-dns option")
|
|
if options.no_forwarders:
|
|
parser.error("You cannot specify a --no-forwarders option without the --setup-dns option")
|
|
if options.reverse_zone:
|
|
parser.error("You cannot specify a --reverse-zone option without the --setup-dns option")
|
|
if options.no_reverse:
|
|
parser.error("You cannot specify a --no-reverse option without the --setup-dns option")
|
|
elif options.forwarders and options.no_forwarders:
|
|
parser.error("You cannot specify a --forwarder option together with --no-forwarders")
|
|
elif not options.forwarders and not options.no_forwarders:
|
|
parser.error("You must specify at least one --forwarder option or --no-forwarders option")
|
|
elif options.reverse_zone and options.no_reverse:
|
|
parser.error("You cannot specify a --reverse-zone option together with --no-reverse")
|
|
|
|
return safe_options, options, args[0]
|
|
|
|
def get_dirman_password():
|
|
return installutils.read_password("Directory Manager (existing master)", confirm=False, validate=False)
|
|
|
|
def set_owner(config, dir):
|
|
pw = pwd.getpwnam(dsinstance.DS_USER)
|
|
os.chown(dir, pw.pw_uid, pw.pw_gid)
|
|
|
|
def install_replica_ds(config):
|
|
dsinstance.check_ports()
|
|
|
|
# if we have a pkcs12 file, create the cert db from
|
|
# that. Otherwise the ds setup will create the CA
|
|
# cert
|
|
pkcs12_info = None
|
|
if ipautil.file_exists(config.dir + "/dscert.p12"):
|
|
pkcs12_info = (config.dir + "/dscert.p12",
|
|
config.dir + "/dirsrv_pin.txt")
|
|
|
|
ds = dsinstance.DsInstance()
|
|
ds.create_replica(config.realm_name,
|
|
config.master_host_name, config.host_name,
|
|
config.domain_name, config.dirman_password,
|
|
pkcs12_info)
|
|
|
|
return ds
|
|
|
|
def install_krb(config, setup_pkinit=False):
|
|
krb = krbinstance.KrbInstance()
|
|
|
|
#pkinit files
|
|
pkcs12_info = None
|
|
if ipautil.file_exists(config.dir + "/pkinitcert.p12"):
|
|
pkcs12_info = (config.dir + "/pkinitcert.p12",
|
|
config.dir + "/pkinit_pin.txt")
|
|
|
|
krb.create_replica(config.realm_name,
|
|
config.master_host_name, config.host_name,
|
|
config.domain_name, config.dirman_password,
|
|
setup_pkinit, pkcs12_info)
|
|
|
|
return krb
|
|
|
|
def install_ca_cert(config):
|
|
cafile = config.dir + "/ca.crt"
|
|
if not ipautil.file_exists(cafile):
|
|
raise RuntimeError("Ca cert file is not available")
|
|
|
|
try:
|
|
shutil.copy(cafile, CACERT)
|
|
os.chmod(CACERT, 0444)
|
|
except Exception, e:
|
|
print "error copying files: " + str(e)
|
|
sys.exit(1)
|
|
|
|
def install_http(config, auto_redirect):
|
|
# if we have a pkcs12 file, create the cert db from
|
|
# that. Otherwise the ds setup will create the CA
|
|
# cert
|
|
pkcs12_info = None
|
|
if ipautil.file_exists(config.dir + "/httpcert.p12"):
|
|
pkcs12_info = (config.dir + "/httpcert.p12",
|
|
config.dir + "/http_pin.txt")
|
|
|
|
memcache = memcacheinstance.MemcacheInstance()
|
|
memcache.create_instance('MEMCACHE', config.host_name, config.dirman_password, ipautil.realm_to_suffix(config.realm_name))
|
|
|
|
http = httpinstance.HTTPInstance()
|
|
http.create_instance(config.realm_name, config.host_name, config.domain_name, config.dirman_password, False, pkcs12_info, self_signed_ca=True, auto_redirect=auto_redirect)
|
|
|
|
# Now copy the autoconfiguration files
|
|
if ipautil.file_exists(config.dir + "/preferences.html"):
|
|
try:
|
|
shutil.copy(config.dir + "/preferences.html", "/usr/share/ipa/html/preferences.html")
|
|
shutil.copy(config.dir + "/configure.jar", "/usr/share/ipa/html/configure.jar")
|
|
except Exception, e:
|
|
print "error copying files: " + str(e)
|
|
sys.exit(1)
|
|
|
|
return http
|
|
|
|
def install_bind(config, options):
|
|
api.Backend.ldap2.connect(bind_dn=DN(('cn', 'Directory Manager')),
|
|
bind_pw=config.dirman_password)
|
|
if options.forwarders:
|
|
forwarders = options.forwarders
|
|
else:
|
|
forwarders = ()
|
|
bind = bindinstance.BindInstance(dm_password=config.dirman_password)
|
|
|
|
if options.reverse_zone:
|
|
if not bindinstance.verify_reverse_zone(options.reverse_zone, config.ip):
|
|
sys.exit(1)
|
|
reverse_zone = bindinstance.normalize_zone(options.reverse_zone)
|
|
else:
|
|
reverse_zone = bindinstance.find_reverse_zone(config.ip)
|
|
if reverse_zone is None and not options.no_reverse:
|
|
reverse_zone = bindinstance.get_reverse_zone_default(config.ip)
|
|
if not options.unattended and bindinstance.create_reverse():
|
|
reverse_zone = bindinstance.read_reverse_zone(reverse_zone, config.ip)
|
|
|
|
if reverse_zone is not None:
|
|
print "Using reverse zone %s" % reverse_zone
|
|
|
|
bind.setup(config.host_name, config.ip_address, config.realm_name,
|
|
config.domain_name, forwarders, options.conf_ntp, reverse_zone)
|
|
bind.create_instance()
|
|
|
|
print ""
|
|
bind.check_global_configuration()
|
|
print ""
|
|
|
|
def install_dns_records(config, options):
|
|
|
|
if not bindinstance.dns_container_exists(config.master_host_name,
|
|
ipautil.realm_to_suffix(config.realm_name),
|
|
dm_password=config.dirman_password):
|
|
return
|
|
|
|
# We have to force to connect to the remote master because we do this step
|
|
# before our DS server is installed.
|
|
cur_uri = api.Backend.ldap2.ldap_uri
|
|
object.__setattr__(api.Backend.ldap2, 'ldap_uri',
|
|
'ldaps://%s' % ipautil.format_netloc(config.master_host_name))
|
|
api.Backend.ldap2.connect(bind_dn=DN(('cn', 'Directory Manager')),
|
|
bind_pw=config.dirman_password,
|
|
tls_cacertfile=CACERT)
|
|
bind = bindinstance.BindInstance(dm_password=config.dirman_password)
|
|
reverse_zone = bindinstance.find_reverse_zone(config.ip)
|
|
|
|
bind.add_master_dns_records(config.host_name, config.ip_address,
|
|
config.realm_name, config.domain_name,
|
|
reverse_zone, options.conf_ntp)
|
|
|
|
#set it back to the default
|
|
api.Backend.ldap2.disconnect()
|
|
object.__setattr__(api.Backend.ldap2, 'ldap_uri', cur_uri)
|
|
|
|
def check_dirsrv():
|
|
(ds_unsecure, ds_secure) = dsinstance.check_ports()
|
|
if not ds_unsecure or not ds_secure:
|
|
print "IPA requires ports 389 and 636 for the Directory Server."
|
|
print "These are currently in use:"
|
|
if not ds_unsecure:
|
|
print "\t389"
|
|
if not ds_secure:
|
|
print "\t636"
|
|
sys.exit(1)
|
|
|
|
def check_bind():
|
|
if not bindinstance.check_inst(unattended=True):
|
|
print "Aborting installation"
|
|
sys.exit(1)
|
|
|
|
def main():
|
|
ipaservices.check_selinux_status()
|
|
safe_options, options, filename = parse_options()
|
|
|
|
if os.geteuid() != 0:
|
|
sys.exit("\nYou must be root to run this script.\n")
|
|
|
|
standard_logging_setup(log_file_name, debug=options.debug)
|
|
root_logger.debug('%s was invoked with argument "%s" and options: %s' % (sys.argv[0], filename, safe_options))
|
|
|
|
if not ipautil.file_exists(filename):
|
|
sys.exit("Replica file %s does not exist" % filename)
|
|
|
|
client_fstore = sysrestore.FileStore('/var/lib/ipa-client/sysrestore')
|
|
if client_fstore.has_files():
|
|
sys.exit("IPA client is already configured on this system.\n"
|
|
+ "Please uninstall it first before configuring the replica.")
|
|
|
|
global sstore
|
|
sstore = sysrestore.StateFile('/var/lib/ipa/sysrestore')
|
|
|
|
global fstore
|
|
fstore = sysrestore.FileStore('/var/lib/ipa/sysrestore')
|
|
|
|
# check the bind is installed
|
|
if options.setup_dns:
|
|
check_bind()
|
|
|
|
check_dirsrv()
|
|
|
|
# get the directory manager password
|
|
dirman_password = options.password
|
|
if not dirman_password:
|
|
try:
|
|
dirman_password = get_dirman_password()
|
|
except KeyboardInterrupt:
|
|
sys.exit(0)
|
|
if dirman_password is None:
|
|
sys.exit("\nDirectory Manager password required")
|
|
|
|
try:
|
|
top_dir, dir = expand_replica_info(filename, dirman_password)
|
|
global REPLICA_INFO_TOP_DIR
|
|
REPLICA_INFO_TOP_DIR = top_dir
|
|
except Exception, e:
|
|
print "ERROR: Failed to decrypt or open the replica file."
|
|
print "Verify you entered the correct Directory Manager password."
|
|
sys.exit(1)
|
|
|
|
config = ReplicaConfig()
|
|
read_replica_info(dir, config)
|
|
config.dirman_password = dirman_password
|
|
try:
|
|
host = get_host_name(options.no_host_dns)
|
|
except BadHostError, e:
|
|
root_logger.error(str(e))
|
|
sys.exit(1)
|
|
if config.host_name != host:
|
|
try:
|
|
print "This replica was created for '%s' but this machine is named '%s'" % (config.host_name, host)
|
|
if not ipautil.user_input("This may cause problems. Continue?", False):
|
|
sys.exit(0)
|
|
config.host_name = host
|
|
print ""
|
|
except KeyboardInterrupt:
|
|
sys.exit(0)
|
|
config.dir = dir
|
|
config.setup_ca = options.setup_ca
|
|
|
|
|
|
# check connection
|
|
if not options.skip_conncheck:
|
|
replica_conn_check(config.master_host_name, config.host_name, config.realm_name, options.setup_ca, options.admin_password)
|
|
|
|
# check replica host IP resolution
|
|
config.ip = installutils.get_server_ip_address(config.host_name, fstore, True, options)
|
|
config.ip_address = str(config.ip)
|
|
|
|
# Create the management framework config file
|
|
# Note: We must do this before bootstraping and finalizing ipalib.api
|
|
old_umask = os.umask(022) # must be readable for httpd
|
|
try:
|
|
fd = open("/etc/ipa/default.conf", "w")
|
|
fd.write("[global]\n")
|
|
fd.write("host=%s\n" % config.host_name)
|
|
fd.write("basedn=%s\n" % str(ipautil.realm_to_suffix(config.realm_name)))
|
|
fd.write("realm=%s\n" % config.realm_name)
|
|
fd.write("domain=%s\n" % config.domain_name)
|
|
fd.write("xmlrpc_uri=https://%s/ipa/xml\n" % ipautil.format_netloc(config.host_name))
|
|
fd.write("ldap_uri=ldapi://%%2fvar%%2frun%%2fslapd-%s.socket\n" % dsinstance.realm_to_serverid(config.realm_name))
|
|
if ipautil.file_exists(config.dir + "/cacert.p12"):
|
|
fd.write("enable_ra=True\n")
|
|
fd.write("ra_plugin=dogtag\n")
|
|
fd.write("mode=production\n")
|
|
fd.close()
|
|
finally:
|
|
os.umask(old_umask)
|
|
|
|
api.bootstrap(in_server=True, context='installer')
|
|
api.finalize()
|
|
|
|
# Create DS group if it doesn't exist yet
|
|
try:
|
|
grp.getgrnam(dsinstance.DS_GROUP)
|
|
root_logger.debug("ds group %s exists" % dsinstance.DS_GROUP)
|
|
group_exists = True
|
|
except KeyError:
|
|
group_exists = False
|
|
args = ["/usr/sbin/groupadd", "-r", dsinstance.DS_GROUP]
|
|
try:
|
|
ipautil.run(args)
|
|
root_logger.debug("done adding DS group")
|
|
except ipautil.CalledProcessError, e:
|
|
root_logger.critical("failed to add DS group: %s" % e)
|
|
sstore.backup_state("install", "group_exists", group_exists)
|
|
|
|
#Automatically disable pkinit w/ dogtag until that is supported
|
|
#[certs.ipa_self_signed() must be called only after api.finalize()]
|
|
if not ipautil.file_exists(config.dir + "/pkinitcert.p12") and not certs.ipa_self_signed():
|
|
options.setup_pkinit = False
|
|
|
|
# Install CA cert so that we can do SSL connections with ldap
|
|
install_ca_cert(config)
|
|
|
|
# Try out the password
|
|
ldapuri = 'ldaps://%s' % ipautil.format_netloc(config.master_host_name)
|
|
try:
|
|
conn = ldap2(shared_instance=False, ldap_uri=ldapuri, base_dn='')
|
|
conn.connect(bind_dn=DN(('cn', 'directory manager')),
|
|
bind_pw=config.dirman_password,
|
|
tls_cacertfile=CACERT)
|
|
replman = ReplicationManager(config.realm_name, config.master_host_name,
|
|
config.dirman_password)
|
|
found = False
|
|
try:
|
|
entry = conn.find_entries(u'fqdn=%s' % host, ['dn', 'fqdn'], DN(api.env.container_host, api.env.basedn))
|
|
print "The host %s already exists on the master server.\nYou should remove it before proceeding:" % host
|
|
print " %% ipa host-del %s" % host
|
|
found = True
|
|
except errors.NotFound:
|
|
pass
|
|
try:
|
|
(agreement_cn, agreement_dn) = replman.agreement_dn(host)
|
|
entry = conn.get_entry(agreement_dn, ['*'])
|
|
print "A replication agreement for this host already exists. It needs to be removed. Run this on the master that generated the info file:"
|
|
print " %% ipa-replica-manage del %s --force" % host
|
|
found = True
|
|
except errors.NotFound:
|
|
pass
|
|
if found:
|
|
sys.exit(3)
|
|
except errors.ACIError:
|
|
sys.exit("\nThe password provided is incorrect for LDAP server %s" % config.master_host_name)
|
|
except errors.LDAPError:
|
|
sys.exit("\nUnable to connect to LDAP server %s" % config.master_host_name)
|
|
finally:
|
|
if conn and conn.isconnected():
|
|
conn.disconnect()
|
|
if replman and replman.conn:
|
|
replman.conn.unbind_s()
|
|
|
|
# Configure ntpd
|
|
if options.conf_ntp:
|
|
ntp = ntpinstance.NTPInstance()
|
|
ntp.create_instance()
|
|
|
|
# Configure the CA if necessary
|
|
(CA, cs) = cainstance.install_replica_ca(config)
|
|
|
|
# Always try to install DNS records
|
|
install_dns_records(config, options)
|
|
|
|
# Configure dirsrv
|
|
ds = install_replica_ds(config)
|
|
|
|
# We need to ldap_enable the CA now that DS is up and running
|
|
if CA and config.setup_ca:
|
|
CA.ldap_enable('CA', config.host_name, config.dirman_password,
|
|
ipautil.realm_to_suffix(config.realm_name))
|
|
cs.add_simple_service('dogtagldap/%s@%s' % (config.host_name, config.realm_name))
|
|
cs.add_cert_to_service()
|
|
|
|
krb = install_krb(config, setup_pkinit=options.setup_pkinit)
|
|
http = install_http(config, auto_redirect=options.ui_redirect)
|
|
if CA:
|
|
CA.configure_certmonger_renewal()
|
|
CA.import_ra_cert(dir + "/ra.p12")
|
|
CA.fix_ra_perms()
|
|
ipaservices.knownservices.httpd.restart()
|
|
|
|
# The DS instance is created before the keytab, add the SSL cert we
|
|
# generated
|
|
ds.add_cert_to_service()
|
|
|
|
# Apply any LDAP updates. Needs to be done after the replica is synced-up
|
|
service.print_msg("Applying LDAP updates")
|
|
ds.apply_updates()
|
|
|
|
# Restart ds and krb after configurations have been changed
|
|
service.print_msg("Restarting the directory server")
|
|
ds.restart()
|
|
|
|
service.print_msg("Restarting the KDC")
|
|
krb.restart()
|
|
|
|
if options.setup_dns:
|
|
install_bind(config, options)
|
|
|
|
# Restart httpd to pick up the new IPA configuration
|
|
service.print_msg("Restarting the web server")
|
|
http.restart()
|
|
|
|
# Call client install script
|
|
try:
|
|
args = ["/usr/sbin/ipa-client-install", "--on-master", "--unattended", "--domain", config.domain_name, "--server", config.host_name, "--realm", config.realm_name]
|
|
if not options.create_sshfp:
|
|
args.append("--no-dns-sshfp")
|
|
if options.trust_sshfp:
|
|
args.append("--ssh-trust-dns")
|
|
if not options.conf_sshd:
|
|
args.append("--no-sshd")
|
|
ipautil.run(args)
|
|
except Exception, e:
|
|
print "Configuration of client side components failed!"
|
|
print "ipa-client-install returned: " + str(e)
|
|
raise RuntimeError("Failed to configure the client")
|
|
|
|
ds.replica_populate()
|
|
|
|
#Everything installed properly, activate ipa service.
|
|
ipaservices.knownservices.ipa.enable()
|
|
|
|
fail_message = '''
|
|
Your system may be partly configured.
|
|
Run /usr/sbin/ipa-server-install --uninstall to clean up.
|
|
'''
|
|
|
|
if __name__ == '__main__':
|
|
try:
|
|
installutils.run_script(main, log_file_name=log_file_name,
|
|
operation_name='ipa-replica-install',
|
|
fail_message=fail_message)
|
|
finally:
|
|
# always try to remove decrypted replica file
|
|
try:
|
|
if REPLICA_INFO_TOP_DIR:
|
|
shutil.rmtree(REPLICA_INFO_TOP_DIR)
|
|
except OSError:
|
|
pass
|