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/>.
|
|
|
|
#
|
|
|
|
|
|
|
|
import base64
|
2015-08-25 14:42:25 -05:00
|
|
|
import binascii
|
|
|
|
import ldap
|
2014-03-18 10:23:30 -05:00
|
|
|
import os
|
|
|
|
import shutil
|
|
|
|
import tempfile
|
|
|
|
import traceback
|
2014-10-07 09:46:15 -05:00
|
|
|
import dbus
|
2015-09-21 01:32:04 -05:00
|
|
|
import pwd
|
2014-03-18 10:23:30 -05:00
|
|
|
|
|
|
|
from pki.client import PKIConnection
|
|
|
|
import pki.system
|
|
|
|
|
2015-08-25 14:42:25 -05:00
|
|
|
from ipalib import errors
|
|
|
|
|
2014-03-18 10:23:30 -05:00
|
|
|
from ipaplatform import services
|
2016-01-19 05:43:18 -06:00
|
|
|
from ipaplatform.constants import constants
|
2016-01-19 07:18:30 -06:00
|
|
|
from ipaplatform.paths import paths
|
2014-03-18 10:23:30 -05:00
|
|
|
from ipapython import certmonger
|
|
|
|
from ipapython import ipaldap
|
|
|
|
from ipapython import ipautil
|
|
|
|
from ipapython.dn import DN
|
|
|
|
from ipaserver.install import service
|
|
|
|
from ipaserver.install import installutils
|
2015-08-25 14:42:25 -05:00
|
|
|
from ipaserver.install import replication
|
2014-03-18 10:23:30 -05:00
|
|
|
from ipaserver.install.installutils import stopped_service
|
|
|
|
from ipapython.ipa_log_manager import log_mgr
|
|
|
|
|
2016-09-26 11:24:39 -05:00
|
|
|
# pylint: disable=unused-variable
|
|
|
|
|
2016-01-19 05:43:18 -06:00
|
|
|
HTTPD_USER = constants.HTTPD_USER
|
2014-03-18 10:23:30 -05:00
|
|
|
|
2016-01-19 07:18:30 -06:00
|
|
|
|
2014-03-18 10:23:30 -05:00
|
|
|
def get_security_domain():
|
|
|
|
"""
|
|
|
|
Get the security domain from the REST interface on the local Dogtag CA
|
|
|
|
This function will succeed if the local dogtag CA is up.
|
|
|
|
"""
|
|
|
|
connection = PKIConnection()
|
|
|
|
domain_client = pki.system.SecurityDomainClient(connection)
|
|
|
|
info = domain_client.get_security_domain_info()
|
|
|
|
return info
|
|
|
|
|
|
|
|
|
|
|
|
def is_installing_replica(sys_type):
|
|
|
|
"""
|
|
|
|
We expect only one of each type of Dogtag subsystem in an IPA deployment.
|
|
|
|
That means that if a subsystem of the specified type has already been
|
|
|
|
deployed - and therefore appears in the security domain - then we must be
|
|
|
|
installing a replica.
|
|
|
|
"""
|
|
|
|
info = get_security_domain()
|
|
|
|
try:
|
|
|
|
sys_list = info.systems[sys_type]
|
|
|
|
return len(sys_list.hosts) > 0
|
|
|
|
except KeyError:
|
|
|
|
return False
|
|
|
|
|
|
|
|
|
2015-09-21 01:32:04 -05:00
|
|
|
def export_kra_agent_pem():
|
|
|
|
"""
|
|
|
|
Export ipaCert with private key for client authentication.
|
|
|
|
"""
|
|
|
|
fd, filename = tempfile.mkstemp(dir=paths.HTTPD_ALIAS_DIR)
|
|
|
|
os.close(fd)
|
|
|
|
|
|
|
|
args = ["/usr/bin/pki",
|
|
|
|
"-d", paths.HTTPD_ALIAS_DIR,
|
|
|
|
"-C", paths.ALIAS_PWDFILE_TXT,
|
|
|
|
"client-cert-show", "ipaCert",
|
|
|
|
"--client-cert", filename]
|
|
|
|
ipautil.run(args)
|
|
|
|
|
2016-01-19 05:43:18 -06:00
|
|
|
pent = pwd.getpwnam(HTTPD_USER)
|
2015-09-21 01:32:04 -05:00
|
|
|
os.chown(filename, 0, pent.pw_gid)
|
|
|
|
os.chmod(filename, 0o440)
|
|
|
|
|
|
|
|
os.rename(filename, paths.KRA_AGENT_PEM)
|
|
|
|
|
|
|
|
|
2014-03-18 10:23:30 -05:00
|
|
|
class DogtagInstance(service.Service):
|
|
|
|
"""
|
|
|
|
This is the base class for a Dogtag 10+ instance, which uses a
|
|
|
|
shared tomcat instance and DS to host the relevant subsystems.
|
|
|
|
|
|
|
|
It contains functions that will be common to installations of the
|
|
|
|
CA, KRA, and eventually TKS and TPS.
|
|
|
|
"""
|
|
|
|
|
2014-10-07 09:46:15 -05:00
|
|
|
tracking_reqs = None
|
|
|
|
server_cert_name = None
|
|
|
|
|
2015-11-09 11:28:47 -06:00
|
|
|
def __init__(self, realm, subsystem, service_desc, host_name=None,
|
|
|
|
dm_password=None, ldapi=True,
|
|
|
|
nss_db=paths.PKI_TOMCAT_ALIAS_DIR):
|
2014-03-18 10:23:30 -05:00
|
|
|
"""Initializer"""
|
|
|
|
|
|
|
|
super(DogtagInstance, self).__init__(
|
2015-11-09 11:28:47 -06:00
|
|
|
'pki-tomcatd',
|
2014-03-18 10:23:30 -05:00
|
|
|
service_desc=service_desc,
|
|
|
|
dm_password=dm_password,
|
|
|
|
ldapi=ldapi
|
|
|
|
)
|
|
|
|
|
|
|
|
self.realm = realm
|
|
|
|
self.admin_password = None
|
|
|
|
self.fqdn = host_name
|
|
|
|
self.pkcs12_info = None
|
|
|
|
self.clone = False
|
|
|
|
|
|
|
|
self.basedn = DN(('o', 'ipa%s' % subsystem.lower()))
|
2015-08-25 14:42:25 -05:00
|
|
|
self.admin_user = "admin"
|
|
|
|
self.admin_dn = DN(('uid', self.admin_user),
|
|
|
|
('ou', 'people'), ('o', 'ipaca'))
|
|
|
|
self.admin_groups = None
|
2014-03-18 10:23:30 -05:00
|
|
|
self.agent_db = tempfile.mkdtemp(prefix="tmp-")
|
|
|
|
self.subsystem = subsystem
|
|
|
|
self.security_domain_name = "IPA"
|
|
|
|
# replication parameters
|
|
|
|
self.master_host = None
|
|
|
|
self.master_replication_port = None
|
|
|
|
self.subject_base = None
|
2015-11-09 11:28:47 -06:00
|
|
|
self.nss_db = nss_db
|
2014-03-18 10:23:30 -05:00
|
|
|
|
|
|
|
self.log = log_mgr.get_logger(self)
|
|
|
|
|
|
|
|
def __del__(self):
|
|
|
|
shutil.rmtree(self.agent_db, ignore_errors=True)
|
|
|
|
|
|
|
|
def is_installed(self):
|
|
|
|
"""
|
|
|
|
Determine if subsystem instance has been installed.
|
|
|
|
|
|
|
|
Returns True/False
|
|
|
|
"""
|
|
|
|
return os.path.exists(os.path.join(
|
2015-11-09 11:28:47 -06:00
|
|
|
paths.VAR_LIB_PKI_TOMCAT_DIR, self.subsystem.lower()))
|
2014-03-18 10:23:30 -05:00
|
|
|
|
|
|
|
def spawn_instance(self, cfg_file, nolog_list=None):
|
|
|
|
"""
|
|
|
|
Create and configure a new Dogtag instance using pkispawn.
|
|
|
|
Passes in a configuration file with IPA-specific
|
|
|
|
parameters.
|
|
|
|
"""
|
|
|
|
subsystem = self.subsystem
|
|
|
|
|
|
|
|
# Define the things we don't want logged
|
|
|
|
if nolog_list is None:
|
|
|
|
nolog_list = []
|
|
|
|
nolog = tuple(nolog_list) + (self.admin_password, self.dm_password)
|
|
|
|
|
|
|
|
args = [paths.PKISPAWN,
|
|
|
|
"-s", subsystem,
|
|
|
|
"-f", cfg_file]
|
|
|
|
|
|
|
|
with open(cfg_file) as f:
|
|
|
|
self.log.debug(
|
|
|
|
'Contents of pkispawn configuration file (%s):\n%s',
|
|
|
|
cfg_file, ipautil.nolog_replace(f.read(), nolog))
|
|
|
|
|
|
|
|
try:
|
|
|
|
ipautil.run(args, nolog=nolog)
|
2015-07-30 09:49:29 -05:00
|
|
|
except ipautil.CalledProcessError as e:
|
2015-04-20 05:34:38 -05:00
|
|
|
self.handle_setup_error(e)
|
2014-03-18 10:23:30 -05:00
|
|
|
|
|
|
|
def restart_instance(self):
|
|
|
|
try:
|
2015-11-09 11:28:47 -06:00
|
|
|
self.restart('pki-tomcat')
|
2014-03-18 10:23:30 -05:00
|
|
|
except Exception:
|
|
|
|
self.log.debug(traceback.format_exc())
|
|
|
|
self.log.critical(
|
|
|
|
"Failed to restart the Dogtag instance."
|
|
|
|
"See the installation log for details.")
|
|
|
|
|
|
|
|
def start_instance(self):
|
|
|
|
try:
|
2015-11-09 11:28:47 -06:00
|
|
|
self.start('pki-tomcat')
|
2014-03-18 10:23:30 -05:00
|
|
|
except Exception:
|
|
|
|
self.log.debug(traceback.format_exc())
|
|
|
|
self.log.critical(
|
|
|
|
"Failed to restart the Dogtag instance."
|
|
|
|
"See the installation log for details.")
|
|
|
|
|
|
|
|
def stop_instance(self):
|
|
|
|
try:
|
2015-11-09 11:28:47 -06:00
|
|
|
self.stop('pki-tomcat')
|
2014-03-18 10:23:30 -05:00
|
|
|
except Exception:
|
|
|
|
self.log.debug(traceback.format_exc())
|
|
|
|
self.log.critical(
|
|
|
|
"Failed to restart the Dogtag instance."
|
|
|
|
"See the installation log for details.")
|
|
|
|
|
|
|
|
def enable_client_auth_to_db(self, config):
|
|
|
|
"""
|
|
|
|
Enable client auth connection to the internal db.
|
|
|
|
Path to CS.cfg config file passed in.
|
|
|
|
"""
|
|
|
|
|
2015-11-09 11:28:47 -06:00
|
|
|
with stopped_service('pki-tomcatd', 'pki-tomcat'):
|
2014-03-18 10:23:30 -05:00
|
|
|
installutils.set_directive(
|
|
|
|
config,
|
|
|
|
'authz.instance.DirAclAuthz.ldap.ldapauth.authtype',
|
|
|
|
'SslClientAuth', quotes=False, separator='=')
|
|
|
|
installutils.set_directive(
|
|
|
|
config,
|
|
|
|
'authz.instance.DirAclAuthz.ldap.ldapauth.clientCertNickname',
|
|
|
|
'subsystemCert cert-pki-ca', quotes=False, separator='=')
|
|
|
|
installutils.set_directive(
|
|
|
|
config,
|
2015-11-09 11:28:47 -06:00
|
|
|
'authz.instance.DirAclAuthz.ldap.ldapconn.port', '636',
|
2014-03-18 10:23:30 -05:00
|
|
|
quotes=False, separator='=')
|
|
|
|
installutils.set_directive(
|
|
|
|
config,
|
|
|
|
'authz.instance.DirAclAuthz.ldap.ldapconn.secureConn',
|
|
|
|
'true', quotes=False, separator='=')
|
|
|
|
|
|
|
|
installutils.set_directive(
|
|
|
|
config,
|
|
|
|
'internaldb.ldapauth.authtype',
|
|
|
|
'SslClientAuth', quotes=False, separator='=')
|
|
|
|
|
|
|
|
installutils.set_directive(
|
|
|
|
config,
|
|
|
|
'internaldb.ldapauth.clientCertNickname',
|
|
|
|
'subsystemCert cert-pki-ca', quotes=False, separator='=')
|
|
|
|
installutils.set_directive(
|
|
|
|
config,
|
2015-11-09 11:28:47 -06:00
|
|
|
'internaldb.ldapconn.port', '636', quotes=False, separator='=')
|
2014-03-18 10:23:30 -05:00
|
|
|
installutils.set_directive(
|
|
|
|
config,
|
|
|
|
'internaldb.ldapconn.secureConn', 'true', quotes=False,
|
|
|
|
separator='=')
|
2013-11-06 06:29:09 -06:00
|
|
|
# Remove internaldb password as is not needed anymore
|
2015-11-09 11:28:47 -06:00
|
|
|
installutils.set_directive(paths.PKI_TOMCAT_PASSWORD_CONF,
|
2013-11-06 06:29:09 -06:00
|
|
|
'internaldb', None)
|
2014-03-18 10:23:30 -05:00
|
|
|
|
|
|
|
def uninstall(self):
|
|
|
|
if self.is_installed():
|
|
|
|
self.print_msg("Unconfiguring %s" % self.subsystem)
|
|
|
|
|
|
|
|
try:
|
2015-11-09 11:28:47 -06:00
|
|
|
ipautil.run([paths.PKIDESTROY,
|
|
|
|
"-i", 'pki-tomcat',
|
2014-03-18 10:23:30 -05:00
|
|
|
"-s", self.subsystem])
|
2015-07-30 09:49:29 -05:00
|
|
|
except ipautil.CalledProcessError as e:
|
2014-03-18 10:23:30 -05:00
|
|
|
self.log.critical("failed to uninstall %s instance %s",
|
|
|
|
self.subsystem, e)
|
|
|
|
|
|
|
|
def http_proxy(self):
|
|
|
|
""" Update the http proxy file """
|
|
|
|
template_filename = ipautil.SHARE_DIR + "ipa-pki-proxy.conf"
|
|
|
|
sub_dict = dict(
|
2015-11-09 11:28:47 -06:00
|
|
|
DOGTAG_PORT=8009,
|
2014-03-18 10:23:30 -05:00
|
|
|
CLONE='' if self.clone else '#',
|
|
|
|
FQDN=self.fqdn,
|
|
|
|
)
|
|
|
|
template = ipautil.template_file(template_filename, sub_dict)
|
|
|
|
with open(paths.HTTPD_IPA_PKI_PROXY_CONF, "w") as fd:
|
|
|
|
fd.write(template)
|
|
|
|
|
2015-01-08 03:06:46 -06:00
|
|
|
def configure_certmonger_renewal(self):
|
2014-10-07 09:46:15 -05:00
|
|
|
"""
|
|
|
|
Create a new CA type for certmonger that will retrieve updated
|
|
|
|
certificates from the dogtag master server.
|
|
|
|
"""
|
|
|
|
cmonger = services.knownservices.certmonger
|
|
|
|
cmonger.enable()
|
|
|
|
services.knownservices.messagebus.start()
|
|
|
|
cmonger.start()
|
|
|
|
|
|
|
|
bus = dbus.SystemBus()
|
|
|
|
obj = bus.get_object('org.fedorahosted.certmonger',
|
|
|
|
'/org/fedorahosted/certmonger')
|
|
|
|
iface = dbus.Interface(obj, 'org.fedorahosted.certmonger')
|
|
|
|
path = iface.find_ca_by_nickname('dogtag-ipa-ca-renew-agent')
|
|
|
|
if not path:
|
|
|
|
iface.add_known_ca(
|
|
|
|
'dogtag-ipa-ca-renew-agent',
|
2015-08-10 08:46:03 -05:00
|
|
|
paths.DOGTAG_IPA_CA_RENEW_AGENT_SUBMIT,
|
|
|
|
dbus.Array([], dbus.Signature('s')))
|
2014-10-07 09:46:15 -05:00
|
|
|
|
2014-03-18 10:23:30 -05:00
|
|
|
def __get_pin(self):
|
|
|
|
try:
|
2015-11-09 11:28:47 -06:00
|
|
|
return certmonger.get_pin('internal')
|
2015-07-30 09:49:29 -05:00
|
|
|
except IOError as e:
|
2014-03-18 10:23:30 -05:00
|
|
|
self.log.debug(
|
|
|
|
'Unable to determine PIN for the Dogtag instance: %s', e)
|
|
|
|
raise RuntimeError(e)
|
|
|
|
|
2014-10-07 09:46:15 -05:00
|
|
|
def configure_renewal(self):
|
|
|
|
""" Configure certmonger to renew system certs """
|
2014-03-18 10:23:30 -05:00
|
|
|
pin = self.__get_pin()
|
|
|
|
|
2014-10-07 09:46:15 -05:00
|
|
|
for nickname, profile in self.tracking_reqs:
|
2014-03-18 10:23:30 -05:00
|
|
|
try:
|
|
|
|
certmonger.dogtag_start_tracking(
|
|
|
|
ca='dogtag-ipa-ca-renew-agent',
|
|
|
|
nickname=nickname,
|
|
|
|
pin=pin,
|
|
|
|
pinfile=None,
|
2015-11-09 11:28:47 -06:00
|
|
|
secdir=self.nss_db,
|
2014-03-18 10:23:30 -05:00
|
|
|
pre_command='stop_pkicad',
|
|
|
|
post_command='renew_ca_cert "%s"' % nickname,
|
|
|
|
profile=profile)
|
2015-07-30 09:49:29 -05:00
|
|
|
except RuntimeError as e:
|
2014-03-18 10:23:30 -05:00
|
|
|
self.log.error(
|
|
|
|
"certmonger failed to start tracking certificate: %s", e)
|
|
|
|
|
2014-10-07 09:46:15 -05:00
|
|
|
def track_servercert(self):
|
|
|
|
"""
|
|
|
|
Specifically do not tell certmonger to restart the CA. This will be
|
|
|
|
done by the renewal script, renew_ca_cert once all the subsystem
|
|
|
|
certificates are renewed.
|
|
|
|
"""
|
|
|
|
pin = self.__get_pin()
|
|
|
|
try:
|
|
|
|
certmonger.dogtag_start_tracking(
|
|
|
|
ca='dogtag-ipa-renew-agent',
|
|
|
|
nickname=self.server_cert_name,
|
|
|
|
pin=pin,
|
|
|
|
pinfile=None,
|
2015-11-09 11:28:47 -06:00
|
|
|
secdir=self.nss_db,
|
2015-01-06 07:08:54 -06:00
|
|
|
pre_command='stop_pkicad',
|
|
|
|
post_command='renew_ca_cert "%s"' % self.server_cert_name)
|
2015-07-30 09:49:29 -05:00
|
|
|
except RuntimeError as e:
|
2014-10-07 09:46:15 -05:00
|
|
|
self.log.error(
|
|
|
|
"certmonger failed to start tracking certificate: %s" % e)
|
|
|
|
|
|
|
|
def stop_tracking_certificates(self, stop_certmonger=True):
|
2014-03-18 10:23:30 -05:00
|
|
|
"""Stop tracking our certificates. Called on uninstall.
|
|
|
|
"""
|
2014-09-01 21:49:54 -05:00
|
|
|
self.print_msg(
|
|
|
|
"Configuring certmonger to stop tracking system certificates "
|
|
|
|
"for %s" % self.subsystem)
|
|
|
|
|
2014-03-18 10:23:30 -05:00
|
|
|
cmonger = services.knownservices.certmonger
|
|
|
|
services.knownservices.messagebus.start()
|
|
|
|
cmonger.start()
|
|
|
|
|
2014-10-07 09:46:15 -05:00
|
|
|
nicknames = [nickname for nickname, profile in self.tracking_reqs]
|
|
|
|
if self.server_cert_name is not None:
|
|
|
|
nicknames.append(self.server_cert_name)
|
2014-03-18 10:23:30 -05:00
|
|
|
|
2014-10-07 09:46:15 -05:00
|
|
|
for nickname in nicknames:
|
2014-03-18 10:23:30 -05:00
|
|
|
try:
|
|
|
|
certmonger.stop_tracking(
|
2015-11-09 11:28:47 -06:00
|
|
|
self.nss_db, nickname=nickname)
|
2015-07-30 09:49:29 -05:00
|
|
|
except RuntimeError as e:
|
2014-03-18 10:23:30 -05:00
|
|
|
self.log.error(
|
|
|
|
"certmonger failed to stop tracking certificate: %s", e)
|
|
|
|
|
2014-10-07 09:46:15 -05:00
|
|
|
if stop_certmonger:
|
|
|
|
cmonger.stop()
|
2014-03-18 10:23:30 -05:00
|
|
|
|
|
|
|
@staticmethod
|
2016-06-16 22:33:26 -05:00
|
|
|
def update_cert_cs_cfg(directive, cert, cs_cfg):
|
2014-03-18 10:23:30 -05:00
|
|
|
"""
|
|
|
|
When renewing a Dogtag subsystem certificate the configuration file
|
|
|
|
needs to get the new certificate as well.
|
|
|
|
|
2016-06-16 22:33:26 -05:00
|
|
|
``directive`` is the directive to update in CS.cfg
|
2014-03-18 10:23:30 -05:00
|
|
|
cert is a DER-encoded certificate.
|
|
|
|
cs_cfg is the path to the CS.cfg file
|
|
|
|
"""
|
|
|
|
|
2015-11-09 11:28:47 -06:00
|
|
|
with stopped_service('pki-tomcatd', 'pki-tomcat'):
|
2014-03-18 10:23:30 -05:00
|
|
|
installutils.set_directive(
|
|
|
|
cs_cfg,
|
2016-06-16 22:33:26 -05:00
|
|
|
directive,
|
2014-03-18 10:23:30 -05:00
|
|
|
base64.b64encode(cert),
|
|
|
|
quotes=False,
|
|
|
|
separator='=')
|
|
|
|
|
|
|
|
def get_admin_cert(self):
|
|
|
|
"""
|
|
|
|
Get the certificate for the admin user by checking the ldap entry
|
|
|
|
for the user. There should be only one certificate per user.
|
|
|
|
"""
|
|
|
|
self.log.debug('Trying to find the certificate for the admin user')
|
|
|
|
conn = None
|
|
|
|
|
|
|
|
try:
|
2015-08-25 14:42:25 -05:00
|
|
|
conn = ipaldap.IPAdmin(self.fqdn, ldapi=True, realm=self.realm)
|
|
|
|
conn.do_external_bind('root')
|
2014-03-18 10:23:30 -05:00
|
|
|
|
2015-08-25 14:42:25 -05:00
|
|
|
entry_attrs = conn.get_entry(self.admin_dn, ['usercertificate'])
|
2014-03-18 10:23:30 -05:00
|
|
|
admin_cert = entry_attrs.get('usercertificate')[0]
|
|
|
|
|
|
|
|
# TODO(edewata) Add check to warn if there is more than one cert.
|
|
|
|
finally:
|
|
|
|
if conn is not None:
|
|
|
|
conn.unbind()
|
|
|
|
|
|
|
|
return base64.b64encode(admin_cert)
|
2015-04-20 05:34:38 -05:00
|
|
|
|
|
|
|
def handle_setup_error(self, e):
|
|
|
|
self.log.critical("Failed to configure %s instance: %s"
|
|
|
|
% (self.subsystem, e))
|
|
|
|
self.log.critical("See the installation logs and the following "
|
|
|
|
"files/directories for more information:")
|
2015-11-09 11:28:47 -06:00
|
|
|
self.log.critical(" %s" % paths.TOMCAT_TOPLEVEL_DIR)
|
2015-04-20 05:34:38 -05:00
|
|
|
|
|
|
|
raise RuntimeError("%s configuration failed." % self.subsystem)
|
2015-08-25 14:42:25 -05:00
|
|
|
|
|
|
|
def __add_admin_to_group(self, group):
|
|
|
|
dn = DN(('cn', group), ('ou', 'groups'), ('o', 'ipaca'))
|
|
|
|
entry = self.admin_conn.get_entry(dn)
|
|
|
|
members = entry.get('uniqueMember', [])
|
|
|
|
members.append(self.admin_dn)
|
|
|
|
mod = [(ldap.MOD_REPLACE, 'uniqueMember', members)]
|
|
|
|
try:
|
|
|
|
self.admin_conn.modify_s(dn, mod)
|
|
|
|
except ldap.TYPE_OR_VALUE_EXISTS:
|
|
|
|
# already there
|
|
|
|
pass
|
|
|
|
|
|
|
|
def setup_admin(self):
|
|
|
|
self.admin_user = "admin-%s" % self.fqdn
|
|
|
|
self.admin_password = binascii.hexlify(os.urandom(16))
|
|
|
|
|
|
|
|
if not self.admin_conn:
|
|
|
|
self.ldap_connect()
|
|
|
|
|
|
|
|
self.admin_dn = DN(('uid', self.admin_user),
|
|
|
|
('ou', 'people'), ('o', 'ipaca'))
|
|
|
|
|
|
|
|
# remove user if left-over exists
|
|
|
|
try:
|
|
|
|
entry = self.admin_conn.delete_entry(self.admin_dn)
|
|
|
|
except errors.NotFound:
|
|
|
|
pass
|
|
|
|
|
|
|
|
# add user
|
|
|
|
entry = self.admin_conn.make_entry(
|
|
|
|
self.admin_dn,
|
|
|
|
objectclass=["top", "person", "organizationalPerson",
|
|
|
|
"inetOrgPerson", "cmsuser"],
|
|
|
|
uid=[self.admin_user],
|
|
|
|
cn=[self.admin_user],
|
|
|
|
sn=[self.admin_user],
|
|
|
|
usertype=['adminType'],
|
|
|
|
mail=['root@localhost'],
|
|
|
|
userPassword=[self.admin_password],
|
|
|
|
userstate=['1']
|
|
|
|
)
|
|
|
|
self.admin_conn.add_entry(entry)
|
|
|
|
|
|
|
|
for group in self.admin_groups:
|
|
|
|
self.__add_admin_to_group(group)
|
|
|
|
|
|
|
|
# Now wait until the other server gets replicated this data
|
|
|
|
master_conn = ipaldap.IPAdmin(self.master_host,
|
2015-11-09 11:28:47 -06:00
|
|
|
port=389,
|
2015-08-25 14:42:25 -05:00
|
|
|
protocol='ldap')
|
|
|
|
master_conn.do_sasl_gssapi_bind()
|
|
|
|
replication.wait_for_entry(master_conn, entry)
|
|
|
|
del master_conn
|
|
|
|
|
|
|
|
def __remove_admin_from_group(self, group):
|
|
|
|
dn = DN(('cn', group), ('ou', 'groups'), ('o', 'ipaca'))
|
|
|
|
entry = self.admin_conn.get_entry(dn)
|
|
|
|
mod = [(ldap.MOD_DELETE, 'uniqueMember', self.admin_dn)]
|
|
|
|
try:
|
|
|
|
self.admin_conn.modify_s(dn, mod)
|
|
|
|
except ldap.NO_SUCH_ATTRIBUTE:
|
|
|
|
# already removed
|
|
|
|
pass
|
|
|
|
|
|
|
|
def teardown_admin(self):
|
|
|
|
|
|
|
|
if not self.admin_conn:
|
|
|
|
self.ldap_connect()
|
|
|
|
|
|
|
|
for group in self.admin_groups:
|
|
|
|
self.__remove_admin_from_group(group)
|
|
|
|
self.admin_conn.delete_entry(self.admin_dn)
|
2016-02-25 02:09:35 -06:00
|
|
|
|
|
|
|
def _use_ldaps_during_spawn(self, config, ds_cacert=paths.IPA_CA_CRT):
|
|
|
|
config.set(self.subsystem, "pki_ds_ldaps_port", "636")
|
|
|
|
config.set(self.subsystem, "pki_ds_secure_connection", "True")
|
|
|
|
config.set(self.subsystem, "pki_ds_secure_connection_ca_pem_file",
|
|
|
|
ds_cacert)
|