2013-11-27 07:53:57 -06:00
|
|
|
#! /usr/bin/python2
|
2011-09-07 03:17:12 -05:00
|
|
|
#
|
|
|
|
# Authors: Sumit Bose <sbose@redhat.com>
|
|
|
|
# Based on ipa-server-install by Karl MacMillan <kmacmillan@mentalrootkit.com>
|
|
|
|
# and ipa-dns-install by Martin Nagy
|
|
|
|
#
|
|
|
|
# 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/>.
|
|
|
|
#
|
|
|
|
|
2015-08-12 06:44:11 -05:00
|
|
|
from __future__ import print_function
|
|
|
|
|
2015-12-16 12:04:20 -06:00
|
|
|
import os
|
|
|
|
import sys
|
|
|
|
|
2015-09-11 06:43:28 -05:00
|
|
|
import six
|
2015-08-12 06:44:11 -05:00
|
|
|
|
2016-11-23 03:04:43 -06:00
|
|
|
from optparse import SUPPRESS_HELP # pylint: disable=deprecated-module
|
2016-06-21 11:17:55 -05:00
|
|
|
|
2016-11-23 08:04:40 -06:00
|
|
|
from ipalib.install import sysrestore
|
2017-02-08 10:02:09 -06:00
|
|
|
from ipaserver.install import adtrust
|
2015-12-16 12:04:20 -06:00
|
|
|
from ipaserver.install.installutils import (
|
|
|
|
read_password,
|
|
|
|
check_server_configuration,
|
|
|
|
run_script)
|
2017-02-06 06:05:05 -06:00
|
|
|
from ipapython.admintool import ScriptError
|
2011-09-07 03:17:12 -05:00
|
|
|
from ipapython import version
|
2017-02-08 10:02:09 -06:00
|
|
|
from ipapython import ipautil
|
2015-07-20 09:04:07 -05:00
|
|
|
from ipalib import api, errors, krb_utils
|
2011-09-07 03:17:12 -05:00
|
|
|
from ipapython.config import IPAOptionParser
|
2014-06-17 04:45:43 -05:00
|
|
|
from ipaplatform.paths import paths
|
2015-12-16 12:04:20 -06:00
|
|
|
from ipapython.ipa_log_manager import root_logger, standard_logging_setup
|
2011-09-07 03:17:12 -05:00
|
|
|
|
2015-09-11 06:43:28 -05:00
|
|
|
if six.PY3:
|
|
|
|
unicode = str
|
|
|
|
|
2014-06-17 04:45:43 -05:00
|
|
|
log_file_name = paths.IPASERVER_INSTALL_LOG
|
2012-05-31 07:34:09 -05:00
|
|
|
|
2017-02-03 03:33:49 -06:00
|
|
|
|
2011-09-07 03:17:12 -05:00
|
|
|
def parse_options():
|
|
|
|
parser = IPAOptionParser(version=version.VERSION)
|
|
|
|
parser.add_option("-d", "--debug", dest="debug", action="store_true",
|
|
|
|
default=False, help="print debugging information")
|
|
|
|
parser.add_option("--netbios-name", dest="netbios_name",
|
|
|
|
help="NetBIOS name of the IPA domain")
|
2016-06-21 11:17:55 -05:00
|
|
|
|
|
|
|
# no-msdcs has not effect, option is here just for backward compatibility
|
2011-10-13 05:01:57 -05:00
|
|
|
parser.add_option("--no-msdcs", dest="no_msdcs", action="store_true",
|
2016-06-21 11:17:55 -05:00
|
|
|
default=False, help=SUPPRESS_HELP)
|
|
|
|
|
2012-06-12 10:53:36 -05:00
|
|
|
parser.add_option("--rid-base", dest="rid_base", type=int, default=1000,
|
|
|
|
help="Start value for mapping UIDs and GIDs to RIDs")
|
|
|
|
parser.add_option("--secondary-rid-base", dest="secondary_rid_base",
|
|
|
|
type=int, default=100000000,
|
2017-02-03 03:33:49 -06:00
|
|
|
help="Start value of the secondary range for mapping "
|
2012-06-12 10:53:36 -05:00
|
|
|
"UIDs and GIDs to RIDs")
|
2017-02-03 03:33:49 -06:00
|
|
|
parser.add_option("-U", "--unattended", dest="unattended",
|
|
|
|
action="store_true",
|
|
|
|
default=False,
|
|
|
|
help="unattended installation never prompts the user")
|
2012-08-17 07:26:58 -05:00
|
|
|
parser.add_option("-a", "--admin-password",
|
|
|
|
sensitive=True, dest="admin_password",
|
|
|
|
help="admin user kerberos password")
|
|
|
|
parser.add_option("-A", "--admin-name",
|
|
|
|
sensitive=True, dest="admin_name", default='admin',
|
|
|
|
help="admin user principal")
|
2012-10-02 15:11:17 -05:00
|
|
|
parser.add_option("--add-sids", dest="add_sids", action="store_true",
|
2017-02-03 03:33:49 -06:00
|
|
|
default=False, help="Add SIDs for existing users and"
|
2013-01-31 06:58:48 -06:00
|
|
|
" groups as the final step")
|
2015-06-04 16:29:36 -05:00
|
|
|
parser.add_option("--add-agents", dest="add_agents", action="store_true",
|
2017-02-03 03:33:49 -06:00
|
|
|
default=False,
|
|
|
|
help="Add IPA masters to a list of hosts allowed to "
|
|
|
|
"serve information about users from trusted forests")
|
ipa-adtrust-install: configure compatibility tree to serve trusted domain users
Enables support for trusted domains users for old clients through Schema
Compatibility plugin. SSSD supports trusted domains natively starting with
version 1.9 platform. For platforms that lack SSSD or run older SSSD version
one needs to use this option. When enabled, slapi-nis package needs to
be installed and schema-compat-plugin will be configured to provide lookup of
users and groups from trusted domains via SSSD on IPA server. These users and
groups will be available under cn=users,cn=compat,$SUFFIX and
cn=groups,cn=compat,$SUFFIX trees. SSSD will normalize names of users and
groups to lower case.
In addition to providing these users and groups through the compat tree,
this option enables authentication over LDAP for trusted domain users with DN
under compat tree, i.e. using bind DN uid=administrator@ad.domain,cn=users,cn=compat,$SUFFIX.
This authentication is related to PAM stack using 'system-auth' PAM
service. If you have disabled HBAC rule 'allow_all', then make sure there is
special service called 'system-auth' created and HBAC rule to allow access to
anyone to this rule on IPA masters is added. Please note that system-auth PAM
service is not used directly by any other application, therefore it is safe to
create one specifically to support trusted domain users via compatibility path.
https://fedorahosted.org/freeipa/ticket/3567
2013-07-15 11:13:50 -05:00
|
|
|
parser.add_option("--enable-compat",
|
|
|
|
dest="enable_compat", default=False, action="store_true",
|
2017-02-03 03:33:49 -06:00
|
|
|
help="Enable support for trusted domains for old "
|
|
|
|
"clients")
|
2011-09-07 03:17:12 -05:00
|
|
|
|
2016-10-04 09:54:44 -05:00
|
|
|
options, _args = parser.parse_args()
|
2011-09-07 03:17:12 -05:00
|
|
|
safe_options = parser.get_safe_opts(options)
|
|
|
|
|
|
|
|
return safe_options, options
|
|
|
|
|
2017-02-03 03:33:49 -06:00
|
|
|
|
2012-08-17 07:26:58 -05:00
|
|
|
def read_admin_password(admin_name):
|
2017-02-03 03:33:49 -06:00
|
|
|
print("Configuring cross-realm trusts for IPA server requires password "
|
|
|
|
"for user '%s'." % (admin_name))
|
|
|
|
print("This user is a regular system account used for IPA server "
|
|
|
|
"administration.")
|
2015-08-12 06:44:11 -05:00
|
|
|
print("")
|
2012-08-17 07:26:58 -05:00
|
|
|
admin_password = read_password(admin_name, confirm=False, validate=None)
|
|
|
|
return admin_password
|
|
|
|
|
2017-02-03 03:33:49 -06:00
|
|
|
|
2012-08-17 07:26:58 -05:00
|
|
|
def ensure_admin_kinit(admin_name, admin_password):
|
|
|
|
try:
|
|
|
|
ipautil.run(['kinit', admin_name], stdin=admin_password+'\n')
|
2016-10-04 09:54:44 -05:00
|
|
|
except ipautil.CalledProcessError:
|
2017-02-03 03:33:49 -06:00
|
|
|
print("There was error to automatically re-kinit your admin user "
|
|
|
|
"ticket.")
|
2012-08-17 07:26:58 -05:00
|
|
|
return False
|
|
|
|
return True
|
|
|
|
|
2017-02-03 03:33:49 -06:00
|
|
|
|
2011-09-07 03:17:12 -05:00
|
|
|
def main():
|
|
|
|
safe_options, options = parse_options()
|
|
|
|
|
|
|
|
if os.getegid() != 0:
|
2017-02-06 06:05:05 -06:00
|
|
|
raise ScriptError("Must be root to setup AD trusts on server")
|
2011-09-07 03:17:12 -05:00
|
|
|
|
2012-05-31 07:34:09 -05:00
|
|
|
standard_logging_setup(log_file_name, debug=options.debug, filemode='a')
|
2017-02-03 03:33:49 -06:00
|
|
|
print("\nThe log file for this installation can be found in %s"
|
|
|
|
% log_file_name)
|
2011-09-07 03:17:12 -05:00
|
|
|
|
2017-02-03 03:33:49 -06:00
|
|
|
root_logger.debug('%s was invoked with options: %s'
|
|
|
|
% (sys.argv[0], safe_options))
|
|
|
|
root_logger.debug(
|
|
|
|
"missing options might be asked for interactively later\n")
|
2014-03-19 07:54:20 -05:00
|
|
|
root_logger.debug('IPA version %s' % version.VENDOR_VERSION)
|
2011-09-07 03:17:12 -05:00
|
|
|
|
2012-07-13 10:12:48 -05:00
|
|
|
check_server_configuration()
|
2011-09-07 03:17:12 -05:00
|
|
|
|
2014-06-17 04:45:43 -05:00
|
|
|
fstore = sysrestore.FileStore(paths.SYSRESTORE)
|
2011-09-07 03:17:12 -05:00
|
|
|
|
2017-02-03 03:33:49 -06:00
|
|
|
print("================================================================"
|
|
|
|
"==============")
|
|
|
|
print("This program will setup components needed to establish trust to "
|
|
|
|
"AD domains for")
|
2015-08-12 06:44:11 -05:00
|
|
|
print("the FreeIPA Server.")
|
|
|
|
print("")
|
|
|
|
print("This includes:")
|
|
|
|
print(" * Configure Samba")
|
|
|
|
print(" * Add trust related objects to FreeIPA LDAP server")
|
2017-02-03 03:33:49 -06:00
|
|
|
# TODO:
|
|
|
|
# print " * Add a SID to all users and Posix groups"
|
2015-08-12 06:44:11 -05:00
|
|
|
print("")
|
|
|
|
print("To accept the default shown in brackets, press the Enter key.")
|
|
|
|
print("")
|
2011-09-07 03:17:12 -05:00
|
|
|
|
|
|
|
# Check if samba packages are installed
|
2017-02-08 10:02:09 -06:00
|
|
|
# the same check is in the adtrust module but we must fail first if the
|
|
|
|
# package is missing
|
|
|
|
adtrust.check_for_installed_deps()
|
2011-09-07 03:17:12 -05:00
|
|
|
|
|
|
|
# Initialize the ipalib api
|
2016-11-28 09:24:33 -06:00
|
|
|
api.bootstrap(
|
2011-09-07 03:17:12 -05:00
|
|
|
in_server=True,
|
|
|
|
debug=options.debug,
|
2016-11-28 09:24:33 -06:00
|
|
|
context='install',
|
|
|
|
confdir=paths.ETC_IPA
|
2011-09-07 03:17:12 -05:00
|
|
|
)
|
|
|
|
api.finalize()
|
|
|
|
|
2012-08-17 07:26:58 -05:00
|
|
|
admin_password = options.admin_password
|
|
|
|
if not (options.unattended or admin_password):
|
|
|
|
admin_password = read_admin_password(options.admin_name)
|
|
|
|
|
|
|
|
admin_kinited = None
|
|
|
|
if admin_password:
|
|
|
|
admin_kinited = ensure_admin_kinit(options.admin_name, admin_password)
|
|
|
|
if not admin_kinited:
|
2015-08-12 06:44:11 -05:00
|
|
|
print("Proceeding with credentials that existed before")
|
2012-08-17 07:26:58 -05:00
|
|
|
|
2012-07-13 10:12:48 -05:00
|
|
|
try:
|
2015-07-20 09:04:07 -05:00
|
|
|
principal = krb_utils.get_principal()
|
2015-08-31 07:04:33 -05:00
|
|
|
except errors.CCacheError as e:
|
2017-02-06 06:05:05 -06:00
|
|
|
raise ScriptError(
|
2017-02-03 03:33:49 -06:00
|
|
|
"Must have Kerberos credentials to setup AD trusts on server: %s"
|
|
|
|
% e.message)
|
2012-07-13 10:12:48 -05:00
|
|
|
|
|
|
|
try:
|
2015-07-20 09:04:07 -05:00
|
|
|
api.Backend.ldap2.connect()
|
2017-02-06 05:25:52 -06:00
|
|
|
except errors.ACIError:
|
2017-02-06 06:05:05 -06:00
|
|
|
raise ScriptError(
|
|
|
|
"Outdated Kerberos credentials. "
|
|
|
|
"Use kdestroy and kinit to update your ticket")
|
2017-02-06 05:25:52 -06:00
|
|
|
except errors.DatabaseError:
|
2017-02-06 06:05:05 -06:00
|
|
|
raise ScriptError(
|
|
|
|
"Cannot connect to the LDAP database. Please check if IPA "
|
|
|
|
"is running")
|
2011-09-07 03:17:12 -05:00
|
|
|
|
|
|
|
try:
|
2017-02-03 03:33:49 -06:00
|
|
|
user = api.Command.user_show(
|
|
|
|
principal.partition('@')[0].partition('/')[0])['result']
|
2012-07-13 10:12:48 -05:00
|
|
|
group = api.Command.group_show(u'admins')['result']
|
|
|
|
if not (user['uid'][0] in group['member_user'] and
|
|
|
|
group['cn'][0] in user['memberof_group']):
|
|
|
|
raise errors.RequirementError(name='admins group membership')
|
2015-07-30 09:49:29 -05:00
|
|
|
except errors.RequirementError as e:
|
2017-02-06 06:05:05 -06:00
|
|
|
raise ScriptError(
|
2017-02-03 03:33:49 -06:00
|
|
|
"Must have administrative privileges to setup AD trusts on server"
|
|
|
|
)
|
2015-07-30 09:49:29 -05:00
|
|
|
except Exception as e:
|
2017-02-06 06:05:05 -06:00
|
|
|
raise ScriptError(
|
|
|
|
"Unrecognized error during check of admin rights: %s" % e)
|
2011-09-07 03:17:12 -05:00
|
|
|
|
2017-02-08 10:02:09 -06:00
|
|
|
adtrust.install_check(True, options, api)
|
2017-02-17 06:48:46 -06:00
|
|
|
adtrust.install(True, options, fstore, api)
|
2015-06-04 16:29:36 -05:00
|
|
|
|
2015-08-12 06:44:11 -05:00
|
|
|
print("""
|
2012-06-21 08:19:27 -05:00
|
|
|
=============================================================================
|
|
|
|
Setup complete
|
|
|
|
|
|
|
|
You must make sure these network ports are open:
|
|
|
|
\tTCP Ports:
|
2015-10-30 10:11:00 -05:00
|
|
|
\t * 135: epmap
|
2012-06-21 08:19:27 -05:00
|
|
|
\t * 138: netbios-dgm
|
|
|
|
\t * 139: netbios-ssn
|
|
|
|
\t * 445: microsoft-ds
|
2015-10-30 10:11:00 -05:00
|
|
|
\t * 1024..1300: epmap listener range
|
2016-08-22 02:07:59 -05:00
|
|
|
\t * 3268: msft-gc
|
2012-06-21 08:19:27 -05:00
|
|
|
\tUDP Ports:
|
|
|
|
\t * 138: netbios-dgm
|
|
|
|
\t * 139: netbios-ssn
|
|
|
|
\t * 389: (C)LDAP
|
|
|
|
\t * 445: microsoft-ds
|
|
|
|
|
2015-10-30 10:11:00 -05:00
|
|
|
See the ipa-adtrust-install(1) man page for more details
|
|
|
|
|
2012-06-21 08:19:27 -05:00
|
|
|
=============================================================================
|
2015-08-12 06:44:11 -05:00
|
|
|
""")
|
2012-08-17 07:26:58 -05:00
|
|
|
if admin_password:
|
|
|
|
admin_kinited = ensure_admin_kinit(options.admin_name, admin_password)
|
|
|
|
|
|
|
|
if not admin_kinited:
|
2015-08-12 06:44:11 -05:00
|
|
|
print("""
|
2012-06-21 08:19:27 -05:00
|
|
|
WARNING: you MUST re-kinit admin user before using 'ipa trust-*' commands
|
|
|
|
family in order to re-generate Kerberos tickets to include AD-specific
|
2015-08-12 06:44:11 -05:00
|
|
|
information""")
|
2011-09-07 03:17:12 -05:00
|
|
|
|
2016-10-27 08:47:08 -05:00
|
|
|
api.Backend.ldap2.disconnect()
|
|
|
|
|
2011-09-07 03:17:12 -05:00
|
|
|
return 0
|
|
|
|
|
2012-05-31 07:34:09 -05:00
|
|
|
if __name__ == '__main__':
|
2017-02-03 03:33:49 -06:00
|
|
|
run_script(
|
|
|
|
main,
|
|
|
|
log_file_name=log_file_name,
|
|
|
|
operation_name='ipa-adtrust-install')
|