Esempio n. 1
0
def install(filename, options):
    global config

    dogtag_constants = dogtag.install_constants

    # 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(paths.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" %
                 installutils.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("dogtag_version=%s\n" % dogtag_constants.DOGTAG_VERSION)
        else:
            fd.write("enable_ra=False\n")
            fd.write("ra_plugin=none\n")

        fd.write("enable_kra=%s\n" % config.setup_kra)

        fd.write("mode=production\n")
        fd.close()
    finally:
        os.umask(old_umask)

    api.bootstrap(in_server=True, context='installer')
    api.finalize()

    # Create DS user/group if it doesn't exist yet
    dsinstance.create_ds_user()

    cafile = config.dir + "/ca.crt"

    ldapuri = 'ldaps://%s' % ipautil.format_netloc(config.master_host_name)
    remote_api = create_api(mode=None)
    remote_api.bootstrap(in_server=True, context='installer',
                         ldap_uri=ldapuri, basedn=DN())
    remote_api.finalize()
    conn = remote_api.Backend.ldap2
    replman = None
    try:
        try:
            # Try out the password
            conn.connect(bind_dn=DIRMAN_DN, bind_pw=config.dirman_password,
                         tls_cacertfile=cafile)
            replman = ReplicationManager(config.realm_name,
                                         config.master_host_name,
                                         config.dirman_password)

            # Check that we don't already have a replication agreement
            try:
                (agreement_cn, agreement_dn) = replman.agreement_dn(
                    config.host_name)
                entry = conn.get_entry(agreement_dn, ['*'])
            except errors.NotFound:
                pass
            else:
                root_logger.info('Error: A replication agreement for this '
                                 'host already exists.')
                print('A replication agreement for this host already exists. '
                      'It needs to be removed.')
                print "Run this on the master that generated the info file:"
                print("    %% ipa-replica-manage del %s --force" %
                      config.host_name)
                sys.exit(3)

            # Detect the current domain level
            try:
                current = remote_api.Command['domainlevel_get']()['result']
            except errors.NotFound:
                # If we're joining an older master, domain entry is not
                # available
                current = 0

            # Detect if current level is out of supported range
            # for this IPA version
            under_lower_bound = current < constants.MIN_DOMAIN_LEVEL
            above_upper_bound = current > constants.MAX_DOMAIN_LEVEL

            if under_lower_bound or above_upper_bound:
                message = ("This version of FreeIPA does not support "
                           "the Domain Level which is currently set for "
                           "this domain. The Domain Level needs to be "
                           "raised before installing a replica with "
                           "this version is allowed to be installed "
                           "within this domain.")
                root_logger.error(message)
                print(message)
                sys.exit(3)

            # Check pre-existing host entry
            try:
                entry = conn.find_entries(u'fqdn=%s' % config.host_name,
                                          ['fqdn'], DN(api.env.container_host,
                                                       api.env.basedn))
            except errors.NotFound:
                pass
            else:
                root_logger.info('Error: Host %s already exists on the master '
                                 'server.' % config.host_name)
                print('The host %s already exists on the master server.' %
                      config.host_name)
                print "You should remove it before proceeding:"
                print "    %% ipa host-del %s" % config.host_name
                sys.exit(3)

            # Install CA cert so that we can do SSL connections with ldap
            install_ca_cert(conn, api.env.basedn, api.env.realm, cafile)

            dns_masters = remote_api.Object['dnsrecord'].get_dns_masters()
            if dns_masters:
                if not options.no_host_dns:
                    master = config.master_host_name
                    root_logger.debug('Check forward/reverse DNS resolution')
                    resolution_ok = (
                        check_dns_resolution(master, dns_masters) and
                        check_dns_resolution(config.host_name, dns_masters))
                    if not resolution_ok and not options.unattended:
                        if not ipautil.user_input("Continue?", False):
                            sys.exit(0)
            else:
                root_logger.debug('No IPA DNS servers, '
                                  'skipping forward/reverse resolution check')

        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 replman and replman.conn:
                replman.conn.unbind()

        # Configure ntpd
        if options.conf_ntp:
            ipaclient.ntpconf.force_ntpd(sstore)
            ntp = ntpinstance.NTPInstance()
            ntp.create_instance()

        # Configure dirsrv
        ds = install_replica_ds(config)

        # Always try to install DNS records
        install_dns_records(config, options, remote_api)
    finally:
        if conn.isconnected():
            conn.disconnect()

    if config.setup_ca:
        options.realm_name = config.realm_name
        options.domain_name = config.domain_name
        options.dm_password = config.dirman_password
        options.host_name = config.host_name

        ca.install(False, config, options)

    krb = install_krb(config, setup_pkinit=options.setup_pkinit)
    http = install_http(config, auto_redirect=options.ui_redirect)

    otpd = otpdinstance.OtpdInstance()
    otpd.create_instance('OTPD', config.host_name, config.dirman_password,
                         ipautil.realm_to_suffix(config.realm_name))

    # 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()

    if options.setup_kra:
        kra.install(config, options, config.dirman_password)
    else:
        service.print_msg("Restarting the directory server")
        ds.restart()

    service.print_msg("Restarting the KDC")
    krb.restart()

    if config.setup_ca:
        dogtag_service = services.knownservices[dogtag_constants.SERVICE_NAME]
        dogtag_service.restart(dogtag_constants.PKI_INSTANCE_NAME)

    if options.setup_dns:
        api.Backend.ldap2.connect(autobind=True)
        dns.install(False, True, 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 = [paths.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_ssh:
            args.append("--no-ssh")
        if not options.conf_sshd:
            args.append("--no-sshd")
        if options.mkhomedir:
            args.append("--mkhomedir")
        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")
Esempio n. 2
0
def install(installer):
    options = installer
    fstore = installer._fstore
    sstore = installer._sstore
    config = installer._config

    dogtag_constants = dogtag.install_constants

    # Create DS user/group if it doesn't exist yet
    dsinstance.create_ds_user()

    cafile = config.dir + "/ca.crt"

    remote_api = installer._remote_api
    conn = remote_api.Backend.ldap2
    try:
        conn.connect(bind_dn=DIRMAN_DN, bind_pw=config.dirman_password,
                     tls_cacertfile=cafile)

        # Install CA cert so that we can do SSL connections with ldap
        install_ca_cert(conn, api.env.basedn, api.env.realm, cafile)

        # Configure ntpd
        if not options.no_ntp:
            ipaclient.ntpconf.force_ntpd(sstore)
            ntp = ntpinstance.NTPInstance()
            ntp.create_instance()

        # Configure dirsrv
        ds = install_replica_ds(config)

        # Always try to install DNS records
        install_dns_records(config, options, remote_api)
    finally:
        if conn.isconnected():
            conn.disconnect()

    options.dm_password = config.dirman_password

    if config.setup_ca:
        options.realm_name = config.realm_name
        options.domain_name = config.domain_name
        options.host_name = config.host_name

        ca.install(False, config, options)

    krb = install_krb(config, setup_pkinit=not options.no_pkinit)
    http = install_http(config, auto_redirect=not options.no_ui_redirect)

    otpd = otpdinstance.OtpdInstance()
    otpd.create_instance('OTPD', config.host_name, config.dirman_password,
                         ipautil.realm_to_suffix(config.realm_name))

    CA = cainstance.CAInstance(
        config.realm_name, certs.NSS_DIR,
        dogtag_constants=dogtag_constants)
    CA.dm_password = config.dirman_password

    CA.configure_certmonger_renewal()
    CA.import_ra_cert(config.dir + "/ra.p12")
    CA.fix_ra_perms()

    # 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()

    if options.setup_kra:
        kra.install(api, config, options)
    else:
        service.print_msg("Restarting the directory server")
        ds.restart()

    service.print_msg("Restarting the KDC")
    krb.restart()

    if config.setup_ca:
        dogtag_service = services.knownservices[dogtag_constants.SERVICE_NAME]
        dogtag_service.restart(dogtag_constants.PKI_INSTANCE_NAME)

    if options.setup_dns:
        api.Backend.ldap2.connect(autobind=True)
        dns.install(False, True, 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 = [paths.IPA_CLIENT_INSTALL, "--on-master", "--unattended",
                "--domain", config.domain_name, "--server", config.host_name,
                "--realm", config.realm_name]
        if options.no_dns_sshfp:
            args.append("--no-dns-sshfp")
        if options.ssh_trust_dns:
            args.append("--ssh-trust-dns")
        if options.no_ssh:
            args.append("--no-ssh")
        if options.no_sshd:
            args.append("--no-sshd")
        if options.mkhomedir:
            args.append("--mkhomedir")
        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")
Esempio n. 3
0
def install(installer):
    options = installer
    ca_enabled = installer._ca_enabled
    kra_enabled = installer._kra_enabled
    fstore = installer._fstore
    config = installer._config
    cafile = installer._ca_file
    dirsrv_pkcs12_info = installer._dirsrv_pkcs12_info
    http_pkcs12_info = installer._http_pkcs12_info
    pkinit_pkcs12_info = installer._pkinit_pkcs12_info

    remote_api = installer._remote_api
    conn = remote_api.Backend.ldap2
    ccache = os.environ['KRB5CCNAME']

    if installer._add_to_ipaservers:
        try:
            conn.connect(ccache=installer._ccache)
            remote_api.Command['hostgroup_add_member'](
                u'ipaservers',
                host=[unicode(api.env.host)],
            )
        finally:
            if conn.isconnected():
                conn.disconnect()
            os.environ['KRB5CCNAME'] = ccache
    config.dirman_password = ipautil.ipa_generate_password()

    # FIXME: allow to use passed in certs instead
    if ca_enabled:
        configure_certmonger()

    try:
        conn.connect(ccache=ccache)

        # Update and istall updated CA file
        cafile = install_ca_cert(conn, api.env.basedn, api.env.realm, cafile)
        install_ca_cert(conn,
                        api.env.basedn,
                        api.env.realm,
                        cafile,
                        destfile=paths.KDC_CA_BUNDLE_PEM)
        install_ca_cert(conn,
                        api.env.basedn,
                        api.env.realm,
                        cafile,
                        destfile=paths.CA_BUNDLE_PEM)

        # Configure dirsrv
        ds = install_replica_ds(config,
                                options,
                                ca_enabled,
                                remote_api,
                                ca_file=cafile,
                                pkcs12_info=dirsrv_pkcs12_info,
                                fstore=fstore)

        # Always try to install DNS records
        install_dns_records(config, options, remote_api, fstore=fstore)

    finally:
        if conn.isconnected():
            conn.disconnect()

        # Create the management framework config file. Do this irregardless
        # of the state of DS installation. Even if it fails,
        # we need to have master-like configuration in order to perform a
        # successful uninstallation
        # The configuration creation has to be here otherwise previous call
        # To config certmonger would try to connect to local server
        create_ipa_conf(fstore, config, ca_enabled)

    krb = install_krb(config,
                      setup_pkinit=not options.no_pkinit,
                      pkcs12_info=pkinit_pkcs12_info,
                      fstore=fstore)

    # We need to point to the master when certmonger asks for
    # a DS or HTTP certificate.
    # During http installation, the <service>/hostname principal is
    # created locally then the installer waits for the entry to appear
    # on the master selected for the installation.
    # In a later step, the installer requests a SSL certificate through
    # Certmonger (and the op adds the principal if it does not exist yet).
    # If xmlrpc_uri points to the soon-to-be replica,
    # the httpd service is not ready yet to handle certmonger requests
    # and certmonger tries to find another master. The master can be
    # different from the one selected for the installation, and it is
    # possible that the principal has not been replicated yet. This
    # may lead to a replication conflict.
    # This is why we need to force the use of the same master by
    # setting xmlrpc_uri
    create_ipa_conf(fstore, config, ca_enabled, master=config.master_host_name)

    # we now need to enable ssl on the ds
    ds.enable_ssl()

    install_http(config,
                 auto_redirect=not options.no_ui_redirect,
                 pkcs12_info=http_pkcs12_info,
                 ca_is_configured=ca_enabled,
                 ca_file=cafile,
                 fstore=fstore)

    # Need to point back to ourself after the cert for HTTP is obtained
    create_ipa_conf(fstore, config, ca_enabled)

    otpd = otpdinstance.OtpdInstance()
    otpd.create_instance('OTPD', config.host_name,
                         ipautil.realm_to_suffix(config.realm_name))

    if kra_enabled:
        # A KRA peer always provides a CA, too.
        mode = custodiainstance.CustodiaModes.KRA_PEER
    elif ca_enabled:
        mode = custodiainstance.CustodiaModes.CA_PEER
    else:
        mode = custodiainstance.CustodiaModes.MASTER_PEER
    custodia = custodiainstance.get_custodia_instance(config, mode)
    custodia.create_instance()

    if ca_enabled:
        options.realm_name = config.realm_name
        options.domain_name = config.domain_name
        options.host_name = config.host_name
        options.dm_password = config.dirman_password
        ca.install(False, config, options, custodia=custodia)

    # configure PKINIT now that all required services are in place
    krb.enable_ssl()

    # Apply any LDAP updates. Needs to be done after the replica is synced-up
    service.print_msg("Applying LDAP updates")
    ds.apply_updates()
    service.print_msg("Finalize replication settings")
    ds.finalize_replica_config()

    if kra_enabled:
        kra.install(api, config, options, custodia=custodia)

    service.print_msg("Restarting the KDC")
    krb.restart()

    custodia.import_dm_password()
    promote_sssd(config.host_name)
    promote_openldap_conf(config.host_name, config.master_host_name)

    if options.setup_dns:
        dns.install(False, True, options, api)

    if options.setup_adtrust:
        adtrust.install(False, options, fstore, api)

    # Enable configured services and update DNS SRV records
    service.enable_services(config.host_name)
    api.Command.dns_update_system_records()
    ca_servers = service.find_providing_servers('CA', api.Backend.ldap2, api)
    api.Backend.ldap2.disconnect()

    # Everything installed properly, activate ipa service.
    services.knownservices.ipa.enable()

    # Print a warning if CA role is only installed on one server
    if len(ca_servers) == 1:
        msg = textwrap.dedent(u'''
            WARNING: The CA service is only installed on one server ({}).
            It is strongly recommended to install it on another server.
            Run ipa-ca-install(1) on another master to accomplish this.
        '''.format(ca_servers[0]))
        print(msg, file=sys.stderr)
Esempio n. 4
0
def install(installer):
    options = installer
    ca_enabled = installer._ca_enabled
    kra_enabled = installer._kra_enabled
    fstore = installer._fstore
    config = installer._config
    cafile = installer._ca_file
    dirsrv_pkcs12_info = installer._dirsrv_pkcs12_info
    http_pkcs12_info = installer._http_pkcs12_info
    pkinit_pkcs12_info = installer._pkinit_pkcs12_info

    remote_api = installer._remote_api
    conn = remote_api.Backend.ldap2
    ccache = os.environ['KRB5CCNAME']

    if tasks.configure_pkcs11_modules(fstore):
        print("Disabled p11-kit-proxy")

    if installer._add_to_ipaservers:
        try:
            conn.connect(ccache=installer._ccache)
            remote_api.Command['hostgroup_add_member'](
                u'ipaservers',
                host=[unicode(api.env.host)],
            )
        finally:
            if conn.isconnected():
                conn.disconnect()
            os.environ['KRB5CCNAME'] = ccache
    config.dirman_password = ipautil.ipa_generate_password()

    # FIXME: allow to use passed in certs instead
    if ca_enabled:
        configure_certmonger()

    try:
        conn.connect(ccache=ccache)

        # Update and istall updated CA file
        cafile = install_ca_cert(conn, api.env.basedn, api.env.realm, cafile)
        install_ca_cert(conn, api.env.basedn, api.env.realm, cafile,
                        destfile=paths.KDC_CA_BUNDLE_PEM)
        install_ca_cert(conn, api.env.basedn, api.env.realm, cafile,
                        destfile=paths.CA_BUNDLE_PEM)

        # Configure dirsrv
        ds = install_replica_ds(config, options, ca_enabled,
                                remote_api,
                                ca_file=cafile,
                                pkcs12_info=dirsrv_pkcs12_info,
                                fstore=fstore)

        # Always try to install DNS records
        install_dns_records(config, options, remote_api, fstore=fstore)

    finally:
        if conn.isconnected():
            conn.disconnect()

        # Create the management framework config file. Do this irregardless
        # of the state of DS installation. Even if it fails,
        # we need to have master-like configuration in order to perform a
        # successful uninstallation
        # The configuration creation has to be here otherwise previous call
        # To config certmonger would try to connect to local server
        create_ipa_conf(fstore, config, ca_enabled)

    krb = install_krb(
        config,
        setup_pkinit=not options.no_pkinit,
        pkcs12_info=pkinit_pkcs12_info,
        fstore=fstore)

    # We need to point to the master when certmonger asks for
    # a DS or HTTP certificate.
    # During http installation, the <service>/hostname principal is
    # created locally then the installer waits for the entry to appear
    # on the master selected for the installation.
    # In a later step, the installer requests a SSL certificate through
    # Certmonger (and the op adds the principal if it does not exist yet).
    # If xmlrpc_uri points to the soon-to-be replica,
    # the httpd service is not ready yet to handle certmonger requests
    # and certmonger tries to find another master. The master can be
    # different from the one selected for the installation, and it is
    # possible that the principal has not been replicated yet. This
    # may lead to a replication conflict.
    # This is why we need to force the use of the same master by
    # setting xmlrpc_uri
    create_ipa_conf(fstore, config, ca_enabled,
                    master=config.master_host_name)

    # we now need to enable ssl on the ds
    ds.enable_ssl()

    install_http(
        config,
        auto_redirect=not options.no_ui_redirect,
        pkcs12_info=http_pkcs12_info,
        ca_is_configured=ca_enabled,
        ca_file=cafile,
        fstore=fstore)

    # Need to point back to ourself after the cert for HTTP is obtained
    create_ipa_conf(fstore, config, ca_enabled)

    otpd = otpdinstance.OtpdInstance()
    otpd.create_instance('OTPD', config.host_name,
                         ipautil.realm_to_suffix(config.realm_name))

    if kra_enabled:
        # A KRA peer always provides a CA, too.
        mode = custodiainstance.CustodiaModes.KRA_PEER
    elif ca_enabled:
        mode = custodiainstance.CustodiaModes.CA_PEER
    else:
        mode = custodiainstance.CustodiaModes.MASTER_PEER
    custodia = custodiainstance.get_custodia_instance(config, mode)
    custodia.create_instance()

    if ca_enabled:
        options.realm_name = config.realm_name
        options.domain_name = config.domain_name
        options.host_name = config.host_name
        options.dm_password = config.dirman_password
        ca.install(False, config, options, custodia=custodia)

    # configure PKINIT now that all required services are in place
    krb.enable_ssl()

    # Apply any LDAP updates. Needs to be done after the replica is synced-up
    service.print_msg("Applying LDAP updates")
    ds.apply_updates()
    service.print_msg("Finalize replication settings")
    ds.finalize_replica_config()

    if kra_enabled:
        kra.install(api, config, options, custodia=custodia)

    service.print_msg("Restarting the KDC")
    krb.restart()

    custodia.import_dm_password()
    promote_sssd(config.host_name)
    promote_openldap_conf(config.host_name, config.master_host_name)

    if options.setup_dns:
        dns.install(False, True, options, api)

    if options.setup_adtrust:
        adtrust.install(False, options, fstore, api)

    if options.hidden_replica:
        # Set services to hidden
        service.hide_services(config.host_name)
    else:
        # Enable configured services
        service.enable_services(config.host_name)
    # update DNS SRV records. Although it's only really necessary in
    # enabled-service case, also perform update in hidden replica case.
    api.Command.dns_update_system_records()

    ca_servers = find_providing_servers('CA', api.Backend.ldap2, api=api)
    api.Backend.ldap2.disconnect()

    # Everything installed properly, activate ipa service.
    services.knownservices.ipa.enable()

    # Print a warning if CA role is only installed on one server
    if len(ca_servers) == 1:
        msg = textwrap.dedent(u'''
            WARNING: The CA service is only installed on one server ({}).
            It is strongly recommended to install it on another server.
            Run ipa-ca-install(1) on another master to accomplish this.
        '''.format(ca_servers[0]))
        print(msg, file=sys.stderr)