2007-10-15 15:42:12 -04:00
|
|
|
# Authors: Rob Crittenden <rcritten@redhat.com>
|
|
|
|
|
#
|
|
|
|
|
# Copyright (C) 2007 Red Hat
|
|
|
|
|
# see file 'COPYING' for use and warranty information
|
|
|
|
|
#
|
2010-12-09 13:59:11 +01:00
|
|
|
# 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.
|
2007-10-15 15:42:12 -04:00
|
|
|
#
|
|
|
|
|
# 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
|
2010-12-09 13:59:11 +01:00
|
|
|
# along with this program. If not, see <http://www.gnu.org/licenses/>.
|
2007-10-15 15:42:12 -04:00
|
|
|
#
|
|
|
|
|
|
2007-12-13 09:31:28 +00:00
|
|
|
import os
|
|
|
|
|
import os.path
|
2007-10-15 15:42:12 -04:00
|
|
|
import tempfile
|
|
|
|
|
import pwd
|
2007-12-12 09:36:32 -05:00
|
|
|
import shutil
|
2013-10-25 10:22:08 +02:00
|
|
|
import re
|
2015-01-08 09:06:46 +00:00
|
|
|
import dbus
|
|
|
|
|
import shlex
|
|
|
|
|
import pipes
|
|
|
|
|
|
|
|
|
|
import service
|
|
|
|
|
import certs
|
|
|
|
|
import installutils
|
2009-02-05 15:03:08 -05:00
|
|
|
from ipapython import sysrestore
|
|
|
|
|
from ipapython import ipautil
|
2012-08-23 12:38:45 -04:00
|
|
|
from ipapython import dogtag
|
2015-06-23 17:01:00 +02:00
|
|
|
from ipapython.dn import DN
|
2014-08-14 17:14:07 +02:00
|
|
|
from ipapython.ipa_log_manager import root_logger
|
|
|
|
|
import ipapython.errors
|
2013-10-25 10:22:08 +02:00
|
|
|
from ipaserver.install import sysupgrade
|
2013-01-21 06:05:07 -05:00
|
|
|
from ipalib import api
|
2015-06-23 17:01:00 +02:00
|
|
|
from ipalib import errors
|
2014-05-29 10:51:08 +02:00
|
|
|
from ipaplatform.tasks import tasks
|
2014-05-29 14:47:17 +02:00
|
|
|
from ipaplatform.paths import paths
|
2015-01-20 09:38:43 +00:00
|
|
|
from ipaplatform import services
|
2014-08-14 17:14:07 +02:00
|
|
|
|
|
|
|
|
SELINUX_BOOLEAN_SETTINGS = dict(
|
|
|
|
|
httpd_can_network_connect='on',
|
|
|
|
|
httpd_manage_ipa='on',
|
2015-07-14 11:11:36 +00:00
|
|
|
httpd_run_ipa='on',
|
2014-08-14 17:14:07 +02:00
|
|
|
)
|
2007-10-15 15:42:12 -04:00
|
|
|
|
|
|
|
|
|
2013-10-25 10:22:08 +02:00
|
|
|
def httpd_443_configured():
|
|
|
|
|
"""
|
|
|
|
|
We now allow mod_ssl to be installed so don't automatically disable it.
|
|
|
|
|
However it can't share the same listen port as mod_nss, so check for that.
|
|
|
|
|
|
|
|
|
|
Returns True if something other than mod_nss is listening on 443.
|
|
|
|
|
False otherwise.
|
|
|
|
|
"""
|
|
|
|
|
try:
|
2014-05-29 14:47:17 +02:00
|
|
|
(stdout, stderr, rc) = ipautil.run([paths.HTTPD, '-t', '-D', 'DUMP_VHOSTS'])
|
2013-10-25 10:22:08 +02:00
|
|
|
except ipautil.CalledProcessError, e:
|
|
|
|
|
service.print_msg("WARNING: cannot check if port 443 is already configured")
|
|
|
|
|
service.print_msg("httpd returned error when checking: %s" % e)
|
|
|
|
|
return False
|
|
|
|
|
|
|
|
|
|
port_line_re = re.compile(r'(?P<address>\S+):(?P<port>\d+)')
|
|
|
|
|
for line in stdout.splitlines():
|
|
|
|
|
m = port_line_re.match(line)
|
|
|
|
|
if m and int(m.group('port')) == 443:
|
|
|
|
|
service.print_msg("Apache is already configured with a listener on port 443:")
|
|
|
|
|
service.print_msg(line)
|
|
|
|
|
return True
|
|
|
|
|
|
|
|
|
|
return False
|
|
|
|
|
|
2008-01-22 11:58:06 +00:00
|
|
|
class WebGuiInstance(service.SimpleServiceInstance):
|
|
|
|
|
def __init__(self):
|
|
|
|
|
service.SimpleServiceInstance.__init__(self, "ipa_webgui")
|
|
|
|
|
|
|
|
|
|
class HTTPInstance(service.Service):
|
2013-03-15 10:09:58 +01:00
|
|
|
def __init__(self, fstore=None, cert_nickname='Server-Cert'):
|
2012-10-11 03:32:17 -04:00
|
|
|
service.Service.__init__(self, "httpd", service_desc="the web interface")
|
2008-03-27 19:01:38 -04:00
|
|
|
if fstore:
|
|
|
|
|
self.fstore = fstore
|
|
|
|
|
else:
|
2014-05-29 14:47:17 +02:00
|
|
|
self.fstore = sysrestore.FileStore(paths.SYSRESTORE)
|
2007-10-15 15:42:12 -04:00
|
|
|
|
2013-03-15 10:09:58 +01:00
|
|
|
self.cert_nickname = cert_nickname
|
2014-10-13 14:30:15 +02:00
|
|
|
self.ca_is_configured = True
|
2013-03-15 10:09:58 +01:00
|
|
|
|
2012-05-13 07:36:35 -04:00
|
|
|
subject_base = ipautil.dn_attribute_property('_subject_base')
|
|
|
|
|
|
2013-03-14 13:58:27 +01:00
|
|
|
def create_instance(self, realm, fqdn, domain_name, dm_password=None,
|
|
|
|
|
autoconfig=True, pkcs12_info=None,
|
2014-10-13 14:30:15 +02:00
|
|
|
subject_base=None, auto_redirect=True, ca_file=None,
|
|
|
|
|
ca_is_configured=None):
|
|
|
|
|
self.fqdn = fqdn
|
|
|
|
|
self.realm = realm
|
2008-02-15 20:47:29 -05:00
|
|
|
self.domain = domain_name
|
2009-12-07 23:17:00 -05:00
|
|
|
self.dm_password = dm_password
|
2012-04-18 11:22:35 -04:00
|
|
|
self.suffix = ipautil.realm_to_suffix(self.realm)
|
2008-02-05 12:23:53 -05:00
|
|
|
self.pkcs12_info = pkcs12_info
|
2009-12-07 23:17:00 -05:00
|
|
|
self.principal = "HTTP/%s@%s" % (self.fqdn, self.realm)
|
|
|
|
|
self.dercert = None
|
2010-01-20 11:26:20 -05:00
|
|
|
self.subject_base = subject_base
|
2012-08-23 12:38:45 -04:00
|
|
|
self.sub_dict = dict(
|
|
|
|
|
REALM=realm,
|
|
|
|
|
FQDN=fqdn,
|
|
|
|
|
DOMAIN=self.domain,
|
|
|
|
|
AUTOREDIR='' if auto_redirect else '#',
|
|
|
|
|
CRL_PUBLISH_PATH=dogtag.install_constants.CRL_PUBLISH_PATH,
|
|
|
|
|
)
|
2013-03-26 15:31:07 +01:00
|
|
|
self.ca_file = ca_file
|
2014-10-13 14:30:15 +02:00
|
|
|
if ca_is_configured is not None:
|
|
|
|
|
self.ca_is_configured = ca_is_configured
|
2008-03-27 19:01:38 -04:00
|
|
|
|
2011-01-05 07:46:30 -05:00
|
|
|
# get a connection to the DS
|
|
|
|
|
self.ldap_connect()
|
|
|
|
|
|
|
|
|
|
|
2011-02-02 16:24:30 +01:00
|
|
|
self.step("setting mod_nss port to 443", self.__set_mod_nss_port)
|
2014-11-25 08:12:53 +00:00
|
|
|
self.step("setting mod_nss protocol list to TLSv1.0 - TLSv1.2",
|
|
|
|
|
self.set_mod_nss_protocol)
|
2011-02-02 16:24:30 +01:00
|
|
|
self.step("setting mod_nss password file", self.__set_mod_nss_passwordfile)
|
2011-10-06 20:37:57 -04:00
|
|
|
self.step("enabling mod_nss renegotiate", self.enable_mod_nss_renegotiate)
|
2011-02-02 16:24:30 +01:00
|
|
|
self.step("adding URL rewriting rules", self.__add_include)
|
2007-12-13 09:31:28 +00:00
|
|
|
self.step("configuring httpd", self.__configure_http)
|
2015-01-08 09:06:46 +00:00
|
|
|
if self.ca_is_configured:
|
|
|
|
|
self.step("configure certmonger for renewals",
|
|
|
|
|
self.configure_certmonger_renewal_guard)
|
2011-02-02 16:24:30 +01:00
|
|
|
self.step("setting up ssl", self.__setup_ssl)
|
2014-06-12 10:24:24 +02:00
|
|
|
self.step("importing CA certificates from LDAP", self.__import_ca_certs)
|
2008-02-05 12:23:53 -05:00
|
|
|
if autoconfig:
|
2011-02-02 16:24:30 +01:00
|
|
|
self.step("setting up browser autoconfig", self.__setup_autoconfig)
|
2009-04-13 13:39:15 -04:00
|
|
|
self.step("publish CA cert", self.__publish_ca_cert)
|
2009-12-07 23:17:00 -05:00
|
|
|
self.step("creating a keytab for httpd", self.__create_http_keytab)
|
2012-02-15 09:42:59 -05:00
|
|
|
self.step("clean up any existing httpd ccache", self.remove_httpd_ccache)
|
2012-04-03 10:47:40 +02:00
|
|
|
self.step("configuring SELinux for httpd", self.configure_selinux_for_httpd)
|
2015-06-23 17:01:00 +02:00
|
|
|
if not self.is_kdcproxy_configured():
|
|
|
|
|
self.step("create KDC proxy config", self.create_kdcproxy_conf)
|
|
|
|
|
self.step("enable KDC proxy", self.enable_kdcproxy)
|
2008-01-14 12:43:26 -05:00
|
|
|
self.step("restarting httpd", self.__start)
|
|
|
|
|
self.step("configuring httpd to start on boot", self.__enable)
|
2007-12-13 09:31:28 +00:00
|
|
|
|
2012-10-11 03:32:17 -04:00
|
|
|
self.start_creation(runtime=60)
|
|
|
|
|
|
2008-01-14 12:43:26 -05:00
|
|
|
def __start(self):
|
|
|
|
|
self.backup_state("running", self.is_running())
|
|
|
|
|
self.restart()
|
|
|
|
|
|
|
|
|
|
def __enable(self):
|
2015-01-27 11:04:03 +01:00
|
|
|
self.backup_state("enabled", self.is_enabled())
|
2010-12-04 15:42:14 -05:00
|
|
|
# We do not let the system start IPA components on its own,
|
|
|
|
|
# Instead we reply on the IPA init script to start only enabled
|
|
|
|
|
# components as found in our LDAP configuration tree
|
|
|
|
|
self.ldap_enable('HTTP', self.fqdn, self.dm_password, self.suffix)
|
2008-01-14 12:43:26 -05:00
|
|
|
|
2012-04-03 10:47:40 +02:00
|
|
|
def configure_selinux_for_httpd(self):
|
2007-10-15 15:42:12 -04:00
|
|
|
try:
|
2014-08-14 17:14:07 +02:00
|
|
|
tasks.set_selinux_booleans(SELINUX_BOOLEAN_SETTINGS,
|
|
|
|
|
self.backup_state)
|
|
|
|
|
except ipapython.errors.SetseboolError as e:
|
|
|
|
|
self.print_msg(e.format_service_warning('web interface'))
|
2008-03-27 19:01:38 -04:00
|
|
|
|
|
|
|
|
def __create_http_keytab(self):
|
2010-09-08 22:11:31 -04:00
|
|
|
installutils.kadmin_addprinc(self.principal)
|
2014-05-29 14:47:17 +02:00
|
|
|
installutils.create_keytab(paths.IPA_KEYTAB, self.principal)
|
2010-09-08 22:11:31 -04:00
|
|
|
self.move_service(self.principal)
|
2009-12-07 23:17:00 -05:00
|
|
|
self.add_cert_to_service()
|
2007-10-15 15:42:12 -04:00
|
|
|
|
|
|
|
|
pent = pwd.getpwnam("apache")
|
2014-05-29 14:47:17 +02:00
|
|
|
os.chown(paths.IPA_KEYTAB, pent.pw_uid, pent.pw_gid)
|
2007-10-15 15:42:12 -04:00
|
|
|
|
2012-02-15 09:42:59 -05:00
|
|
|
def remove_httpd_ccache(self):
|
2012-01-10 22:39:26 -05:00
|
|
|
# Clean up existing ccache
|
2014-01-16 14:12:29 +01:00
|
|
|
# Make sure that empty env is passed to avoid passing KRB5CCNAME from
|
|
|
|
|
# current env
|
2014-01-22 16:08:51 +01:00
|
|
|
ipautil.run(['kdestroy', '-A'], runas='apache', raiseonerr=False, env={})
|
2013-05-07 10:33:55 -04:00
|
|
|
|
|
|
|
|
def __configure_http(self):
|
2014-05-29 14:47:17 +02:00
|
|
|
target_fname = paths.HTTPD_IPA_CONF
|
2007-12-13 09:31:28 +00:00
|
|
|
http_txt = ipautil.template_file(ipautil.SHARE_DIR + "ipa.conf", self.sub_dict)
|
2014-05-29 14:47:17 +02:00
|
|
|
self.fstore.backup_file(paths.HTTPD_IPA_CONF)
|
2011-08-30 16:32:40 +02:00
|
|
|
http_fd = open(target_fname, "w")
|
|
|
|
|
http_fd.write(http_txt)
|
2008-02-21 16:25:09 -05:00
|
|
|
http_fd.close()
|
2011-08-30 16:32:40 +02:00
|
|
|
os.chmod(target_fname, 0644)
|
2007-10-15 15:42:12 -04:00
|
|
|
|
2014-05-29 14:47:17 +02:00
|
|
|
target_fname = paths.HTTPD_IPA_REWRITE_CONF
|
2008-02-21 16:25:09 -05:00
|
|
|
http_txt = ipautil.template_file(ipautil.SHARE_DIR + "ipa-rewrite.conf", self.sub_dict)
|
2014-05-29 14:47:17 +02:00
|
|
|
self.fstore.backup_file(paths.HTTPD_IPA_REWRITE_CONF)
|
2011-08-30 16:32:40 +02:00
|
|
|
http_fd = open(target_fname, "w")
|
2008-02-21 16:25:09 -05:00
|
|
|
http_fd.write(http_txt)
|
|
|
|
|
http_fd.close()
|
2011-08-30 16:32:40 +02:00
|
|
|
os.chmod(target_fname, 0644)
|
2007-10-15 15:42:12 -04:00
|
|
|
|
2013-11-26 08:53:34 +00:00
|
|
|
def change_mod_nss_port_from_http(self):
|
2013-10-25 10:22:08 +02:00
|
|
|
# mod_ssl enforces SSLEngine on for vhost on 443 even though
|
|
|
|
|
# the listener is mod_nss. This then crashes the httpd as mod_nss
|
|
|
|
|
# listened port obviously does not match mod_ssl requirements.
|
|
|
|
|
#
|
2013-11-26 08:53:34 +00:00
|
|
|
# The workaround for this was to change port to http. It is no longer
|
|
|
|
|
# necessary, as mod_nss now ships with default configuration which
|
|
|
|
|
# sets SSLEngine off when mod_ssl is installed.
|
2013-10-25 10:22:08 +02:00
|
|
|
#
|
2013-11-26 08:53:34 +00:00
|
|
|
# Remove the workaround.
|
|
|
|
|
if sysupgrade.get_upgrade_state('nss.conf', 'listen_port_updated'):
|
2014-05-29 14:47:17 +02:00
|
|
|
installutils.set_directive(paths.HTTPD_NSS_CONF, 'Listen', '443', quotes=False)
|
2013-11-26 08:53:34 +00:00
|
|
|
sysupgrade.set_upgrade_state('nss.conf', 'listen_port_updated', False)
|
2007-10-15 15:42:12 -04:00
|
|
|
|
|
|
|
|
def __set_mod_nss_port(self):
|
2014-05-29 14:47:17 +02:00
|
|
|
self.fstore.backup_file(paths.HTTPD_NSS_CONF)
|
|
|
|
|
if installutils.update_file(paths.HTTPD_NSS_CONF, '8443', '443') != 0:
|
|
|
|
|
print "Updating port in %s failed." % paths.HTTPD_NSS_CONF
|
2008-02-21 16:25:09 -05:00
|
|
|
|
2008-07-11 11:34:29 -04:00
|
|
|
def __set_mod_nss_nickname(self, nickname):
|
2014-05-29 14:47:17 +02:00
|
|
|
installutils.set_directive(paths.HTTPD_NSS_CONF, 'NSSNickname', nickname)
|
2008-07-11 11:34:29 -04:00
|
|
|
|
2014-11-25 08:12:53 +00:00
|
|
|
def set_mod_nss_protocol(self):
|
|
|
|
|
installutils.set_directive(paths.HTTPD_NSS_CONF, 'NSSProtocol', 'TLSv1.0,TLSv1.1,TLSv1.2', False)
|
2014-10-21 15:59:04 +03:00
|
|
|
|
2011-10-06 20:37:57 -04:00
|
|
|
def enable_mod_nss_renegotiate(self):
|
2014-05-29 14:47:17 +02:00
|
|
|
installutils.set_directive(paths.HTTPD_NSS_CONF, 'NSSRenegotiation', 'on', False)
|
|
|
|
|
installutils.set_directive(paths.HTTPD_NSS_CONF, 'NSSRequireSafeNegotiation', 'on', False)
|
2011-08-17 15:36:18 -04:00
|
|
|
|
2009-04-13 13:39:15 -04:00
|
|
|
def __set_mod_nss_passwordfile(self):
|
2014-05-29 14:47:17 +02:00
|
|
|
installutils.set_directive(paths.HTTPD_NSS_CONF, 'NSSPassPhraseDialog', 'file:/etc/httpd/conf/password.conf')
|
2009-04-13 13:39:15 -04:00
|
|
|
|
2008-02-21 16:25:09 -05:00
|
|
|
def __add_include(self):
|
|
|
|
|
"""This should run after __set_mod_nss_port so is already backed up"""
|
2014-05-29 14:47:17 +02:00
|
|
|
if installutils.update_file(paths.HTTPD_NSS_CONF, '</VirtualHost>', 'Include conf.d/ipa-rewrite.conf\n</VirtualHost>') != 0:
|
|
|
|
|
print "Adding Include conf.d/ipa-rewrite to %s failed." % paths.HTTPD_NSS_CONF
|
|
|
|
|
|
2015-01-08 09:06:46 +00:00
|
|
|
def configure_certmonger_renewal_guard(self):
|
2015-01-20 09:38:43 +00:00
|
|
|
certmonger = services.knownservices.certmonger
|
|
|
|
|
certmonger_stopped = not certmonger.is_running()
|
|
|
|
|
|
|
|
|
|
if certmonger_stopped:
|
|
|
|
|
certmonger.start()
|
|
|
|
|
try:
|
|
|
|
|
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('IPA')
|
|
|
|
|
if path:
|
|
|
|
|
ca_obj = bus.get_object('org.fedorahosted.certmonger', path)
|
|
|
|
|
ca_iface = dbus.Interface(ca_obj,
|
|
|
|
|
'org.freedesktop.DBus.Properties')
|
|
|
|
|
helper = ca_iface.Get('org.fedorahosted.certmonger.ca',
|
|
|
|
|
'external-helper')
|
|
|
|
|
if helper:
|
|
|
|
|
args = shlex.split(helper)
|
|
|
|
|
if args[0] != paths.IPA_SERVER_GUARD:
|
|
|
|
|
self.backup_state('certmonger_ipa_helper', helper)
|
|
|
|
|
args = [paths.IPA_SERVER_GUARD] + args
|
|
|
|
|
helper = ' '.join(pipes.quote(a) for a in args)
|
|
|
|
|
ca_iface.Set('org.fedorahosted.certmonger.ca',
|
|
|
|
|
'external-helper', helper)
|
|
|
|
|
finally:
|
|
|
|
|
if certmonger_stopped:
|
|
|
|
|
certmonger.stop()
|
2015-01-08 09:06:46 +00:00
|
|
|
|
|
|
|
|
def __setup_ssl(self):
|
2013-03-27 14:25:18 +01:00
|
|
|
fqdn = self.fqdn
|
2010-12-08 16:35:12 -05:00
|
|
|
|
|
|
|
|
ca_db = certs.CertDB(self.realm, host_name=fqdn, subject_base=self.subject_base)
|
|
|
|
|
|
|
|
|
|
db = certs.CertDB(self.realm, subject_base=self.subject_base)
|
2008-02-05 12:23:53 -05:00
|
|
|
if self.pkcs12_info:
|
2014-10-13 14:30:15 +02:00
|
|
|
if self.ca_is_configured:
|
2014-06-09 16:04:09 +02:00
|
|
|
trust_flags = 'CT,C,C'
|
|
|
|
|
else:
|
|
|
|
|
trust_flags = None
|
2013-03-26 15:31:07 +01:00
|
|
|
db.create_from_pkcs12(self.pkcs12_info[0], self.pkcs12_info[1],
|
2014-06-09 16:04:09 +02:00
|
|
|
passwd=None, ca_file=self.ca_file,
|
|
|
|
|
trust_flags=trust_flags)
|
2009-04-13 13:39:15 -04:00
|
|
|
server_certs = db.find_server_certs()
|
2008-07-11 11:34:29 -04:00
|
|
|
if len(server_certs) == 0:
|
2009-08-11 17:08:09 -04:00
|
|
|
raise RuntimeError("Could not find a suitable server cert in import in %s" % self.pkcs12_info[0])
|
2008-07-11 11:34:29 -04:00
|
|
|
|
2009-07-24 09:29:33 -04:00
|
|
|
db.create_password_conf()
|
2013-03-14 13:58:27 +01:00
|
|
|
|
2008-07-11 11:34:29 -04:00
|
|
|
# We only handle one server cert
|
|
|
|
|
nickname = server_certs[0][0]
|
2011-06-08 10:54:41 -04:00
|
|
|
self.dercert = db.get_cert_from_db(nickname, pem=False)
|
2013-03-14 13:58:27 +01:00
|
|
|
|
2014-10-13 14:30:15 +02:00
|
|
|
if self.ca_is_configured:
|
2013-03-14 13:58:27 +01:00
|
|
|
db.track_server_cert(nickname, self.principal, db.passwd_fname, 'restart_httpd')
|
2008-07-11 11:34:29 -04:00
|
|
|
|
|
|
|
|
self.__set_mod_nss_nickname(nickname)
|
2008-02-05 12:23:53 -05:00
|
|
|
else:
|
2010-12-08 16:35:12 -05:00
|
|
|
|
|
|
|
|
db.create_password_conf()
|
2013-03-15 10:09:58 +01:00
|
|
|
self.dercert = db.create_server_cert(self.cert_nickname, self.fqdn,
|
|
|
|
|
ca_db)
|
|
|
|
|
db.track_server_cert(self.cert_nickname, self.principal,
|
|
|
|
|
db.passwd_fname, 'restart_httpd')
|
2010-12-08 16:35:12 -05:00
|
|
|
db.create_signing_cert("Signing-Cert", "Object Signing Cert", ca_db)
|
2007-12-12 09:36:32 -05:00
|
|
|
|
2008-04-28 15:28:13 -04:00
|
|
|
# Fix the database permissions
|
2010-12-08 16:35:12 -05:00
|
|
|
os.chmod(certs.NSS_DIR + "/cert8.db", 0660)
|
|
|
|
|
os.chmod(certs.NSS_DIR + "/key3.db", 0660)
|
|
|
|
|
os.chmod(certs.NSS_DIR + "/secmod.db", 0660)
|
|
|
|
|
os.chmod(certs.NSS_DIR + "/pwdfile.txt", 0660)
|
2008-04-28 15:28:13 -04:00
|
|
|
|
|
|
|
|
pent = pwd.getpwnam("apache")
|
2010-12-08 16:35:12 -05:00
|
|
|
os.chown(certs.NSS_DIR + "/cert8.db", 0, pent.pw_gid )
|
|
|
|
|
os.chown(certs.NSS_DIR + "/key3.db", 0, pent.pw_gid )
|
|
|
|
|
os.chown(certs.NSS_DIR + "/secmod.db", 0, pent.pw_gid )
|
|
|
|
|
os.chown(certs.NSS_DIR + "/pwdfile.txt", 0, pent.pw_gid )
|
2009-09-10 16:15:14 -04:00
|
|
|
|
|
|
|
|
# Fix SELinux permissions on the database
|
2014-05-29 10:18:21 +02:00
|
|
|
tasks.restore_context(certs.NSS_DIR + "/cert8.db")
|
|
|
|
|
tasks.restore_context(certs.NSS_DIR + "/key3.db")
|
2009-09-10 16:15:14 -04:00
|
|
|
|
2014-06-12 10:24:24 +02:00
|
|
|
def __import_ca_certs(self):
|
|
|
|
|
db = certs.CertDB(self.realm, subject_base=self.subject_base)
|
2014-10-13 14:30:15 +02:00
|
|
|
self.import_ca_certs(db, self.ca_is_configured)
|
2014-06-12 10:24:24 +02:00
|
|
|
|
2007-12-12 09:36:32 -05:00
|
|
|
def __setup_autoconfig(self):
|
2014-05-29 14:47:17 +02:00
|
|
|
target_fname = paths.PREFERENCES_HTML
|
2012-10-08 07:54:47 -04:00
|
|
|
ipautil.copy_template_file(
|
|
|
|
|
ipautil.SHARE_DIR + "preferences.html.template",
|
|
|
|
|
target_fname, self.sub_dict)
|
2012-10-04 17:08:17 +02:00
|
|
|
os.chmod(target_fname, 0644)
|
|
|
|
|
|
2007-12-12 09:36:32 -05:00
|
|
|
# The signing cert is generated in __setup_ssl
|
2010-12-08 16:35:12 -05:00
|
|
|
db = certs.CertDB(self.realm, subject_base=self.subject_base)
|
2012-10-08 07:54:47 -04:00
|
|
|
with open(db.passwd_fname) as pwdfile:
|
|
|
|
|
pwd = pwdfile.read()
|
2009-09-10 16:15:14 -04:00
|
|
|
|
2012-10-04 17:08:17 +02:00
|
|
|
# Setup configure.jar
|
2013-06-25 16:53:24 +02:00
|
|
|
if db.has_nickname('Signing-Cert'):
|
|
|
|
|
tmpdir = tempfile.mkdtemp(prefix="tmp-")
|
2014-05-29 14:47:17 +02:00
|
|
|
target_fname = paths.CONFIGURE_JAR
|
|
|
|
|
shutil.copy(paths.PREFERENCES_HTML, tmpdir)
|
2013-06-25 16:53:24 +02:00
|
|
|
db.run_signtool(["-k", "Signing-Cert",
|
|
|
|
|
"-Z", target_fname,
|
|
|
|
|
"-e", ".html", "-p", pwd,
|
|
|
|
|
tmpdir])
|
|
|
|
|
shutil.rmtree(tmpdir)
|
|
|
|
|
os.chmod(target_fname, 0644)
|
|
|
|
|
else:
|
|
|
|
|
root_logger.warning('Object-signing certificate was not found; '
|
|
|
|
|
'therefore, configure.jar was not created.')
|
2008-01-11 11:57:36 +00:00
|
|
|
|
2014-08-29 14:11:33 +02:00
|
|
|
self.setup_firefox_extension(self.realm, self.domain)
|
2012-10-08 07:54:47 -04:00
|
|
|
|
2014-08-29 14:11:33 +02:00
|
|
|
def setup_firefox_extension(self, realm, domain):
|
2012-10-08 07:54:47 -04:00
|
|
|
"""Set up the signed browser configuration extension
|
|
|
|
|
"""
|
|
|
|
|
|
2014-05-29 14:47:17 +02:00
|
|
|
target_fname = paths.KRB_JS
|
2012-10-08 07:54:47 -04:00
|
|
|
sub_dict = dict(REALM=realm, DOMAIN=domain)
|
|
|
|
|
db = certs.CertDB(realm)
|
|
|
|
|
with open(db.passwd_fname) as pwdfile:
|
|
|
|
|
pwd = pwdfile.read()
|
|
|
|
|
|
|
|
|
|
ipautil.copy_template_file(ipautil.SHARE_DIR + "krb.js.template",
|
|
|
|
|
target_fname, sub_dict)
|
|
|
|
|
os.chmod(target_fname, 0644)
|
|
|
|
|
|
2012-10-04 17:08:17 +02:00
|
|
|
# Setup extension
|
2012-10-08 07:54:47 -04:00
|
|
|
tmpdir = tempfile.mkdtemp(prefix="tmp-")
|
2012-10-04 17:08:17 +02:00
|
|
|
extdir = tmpdir + "/ext"
|
2014-05-29 14:47:17 +02:00
|
|
|
target_fname = paths.KERBEROSAUTH_XPI
|
|
|
|
|
shutil.copytree(paths.FFEXTENSION, extdir)
|
2012-10-08 07:54:47 -04:00
|
|
|
if db.has_nickname('Signing-Cert'):
|
|
|
|
|
db.run_signtool(["-k", "Signing-Cert",
|
|
|
|
|
"-p", pwd,
|
|
|
|
|
"-X", "-Z", target_fname,
|
|
|
|
|
extdir])
|
|
|
|
|
else:
|
|
|
|
|
root_logger.warning('Object-signing certificate was not found. '
|
|
|
|
|
'Creating unsigned Firefox configuration extension.')
|
|
|
|
|
filenames = os.listdir(extdir)
|
2014-05-29 14:47:17 +02:00
|
|
|
ipautil.run([paths.ZIP, '-r', target_fname] + filenames,
|
2012-10-08 07:54:47 -04:00
|
|
|
cwd=extdir)
|
2012-10-04 17:08:17 +02:00
|
|
|
shutil.rmtree(tmpdir)
|
|
|
|
|
os.chmod(target_fname, 0644)
|
|
|
|
|
|
2009-04-13 13:39:15 -04:00
|
|
|
def __publish_ca_cert(self):
|
2010-12-08 16:35:12 -05:00
|
|
|
ca_db = certs.CertDB(self.realm)
|
2014-05-29 14:47:17 +02:00
|
|
|
ca_db.publish_ca_cert(paths.CA_CRT)
|
2009-04-13 13:39:15 -04:00
|
|
|
|
2015-06-23 17:01:00 +02:00
|
|
|
def is_kdcproxy_configured(self):
|
|
|
|
|
"""Check if KDC proxy has already been configured in the past"""
|
|
|
|
|
return os.path.isfile(paths.HTTPD_IPA_KDCPROXY_CONF)
|
|
|
|
|
|
|
|
|
|
def enable_kdcproxy(self):
|
|
|
|
|
"""Add ipaConfigString=kdcProxyEnabled to cn=KDC"""
|
|
|
|
|
entry_name = DN(('cn', 'KDC'), ('cn', self.fqdn), ('cn', 'masters'),
|
|
|
|
|
('cn', 'ipa'), ('cn', 'etc'), self.suffix)
|
|
|
|
|
attr_name = 'kdcProxyEnabled'
|
|
|
|
|
|
|
|
|
|
try:
|
|
|
|
|
entry = self.admin_conn.get_entry(entry_name, ['ipaConfigString'])
|
|
|
|
|
except errors.NotFound:
|
|
|
|
|
pass
|
|
|
|
|
else:
|
|
|
|
|
if any(attr_name.lower() == val.lower()
|
|
|
|
|
for val in entry.get('ipaConfigString', [])):
|
|
|
|
|
root_logger.debug("service KDCPROXY already enabled")
|
|
|
|
|
return
|
|
|
|
|
|
|
|
|
|
entry.setdefault('ipaConfigString', []).append(attr_name)
|
|
|
|
|
try:
|
|
|
|
|
self.admin_conn.update_entry(entry)
|
|
|
|
|
except errors.EmptyModlist:
|
|
|
|
|
root_logger.debug("service KDCPROXY already enabled")
|
|
|
|
|
return
|
|
|
|
|
except:
|
|
|
|
|
root_logger.debug("failed to enable service KDCPROXY")
|
|
|
|
|
raise
|
|
|
|
|
|
|
|
|
|
root_logger.debug("service KDCPROXY enabled")
|
|
|
|
|
return
|
|
|
|
|
|
|
|
|
|
entry = self.admin_conn.make_entry(
|
|
|
|
|
entry_name,
|
|
|
|
|
objectclass=["nsContainer", "ipaConfigObject"],
|
|
|
|
|
cn=['KDC'],
|
|
|
|
|
ipaconfigstring=[attr_name]
|
|
|
|
|
)
|
|
|
|
|
|
|
|
|
|
try:
|
|
|
|
|
self.admin_conn.add_entry(entry)
|
|
|
|
|
except errors.DuplicateEntry:
|
|
|
|
|
root_logger.debug("failed to add service KDCPROXY entry")
|
|
|
|
|
raise
|
|
|
|
|
|
|
|
|
|
def create_kdcproxy_conf(self):
|
|
|
|
|
"""Create ipa-kdc-proxy.conf in /etc/ipa/kdcproxy"""
|
|
|
|
|
target_fname = paths.HTTPD_IPA_KDCPROXY_CONF
|
|
|
|
|
sub_dict = dict(KDCPROXY_CONFIG=paths.KDCPROXY_CONFIG)
|
|
|
|
|
http_txt = ipautil.template_file(
|
|
|
|
|
ipautil.SHARE_DIR + "ipa-kdc-proxy.conf.template", sub_dict)
|
|
|
|
|
self.fstore.backup_file(target_fname)
|
|
|
|
|
with open(target_fname, 'w') as f:
|
|
|
|
|
f.write(http_txt)
|
|
|
|
|
os.chmod(target_fname, 0644)
|
|
|
|
|
|
2008-01-11 11:57:36 +00:00
|
|
|
def uninstall(self):
|
2010-05-03 15:21:51 -04:00
|
|
|
if self.is_configured():
|
|
|
|
|
self.print_msg("Unconfiguring web server")
|
|
|
|
|
|
2008-01-11 11:57:36 +00:00
|
|
|
running = self.restore_state("running")
|
|
|
|
|
enabled = self.restore_state("enabled")
|
|
|
|
|
|
|
|
|
|
|
2013-03-26 18:06:50 +01:00
|
|
|
self.stop_tracking_certificates()
|
2015-01-08 09:06:46 +00:00
|
|
|
|
|
|
|
|
helper = self.restore_state('certmonger_ipa_helper')
|
|
|
|
|
if helper:
|
|
|
|
|
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('IPA')
|
|
|
|
|
if path:
|
|
|
|
|
ca_obj = bus.get_object('org.fedorahosted.certmonger', path)
|
|
|
|
|
ca_iface = dbus.Interface(ca_obj,
|
|
|
|
|
'org.freedesktop.DBus.Properties')
|
|
|
|
|
ca_iface.Set('org.fedorahosted.certmonger.ca',
|
|
|
|
|
'external-helper', helper)
|
|
|
|
|
|
2014-05-29 14:47:17 +02:00
|
|
|
for f in [paths.HTTPD_IPA_CONF, paths.HTTPD_SSL_CONF, paths.HTTPD_NSS_CONF]:
|
2008-03-27 19:01:38 -04:00
|
|
|
try:
|
|
|
|
|
self.fstore.restore_file(f)
|
|
|
|
|
except ValueError, error:
|
2011-11-15 14:39:31 -05:00
|
|
|
root_logger.debug(error)
|
2008-03-27 19:01:38 -04:00
|
|
|
pass
|
2008-01-11 11:57:36 +00:00
|
|
|
|
2015-05-15 15:45:34 +02:00
|
|
|
# Remove the ccache file for the HTTPD service
|
|
|
|
|
ipautil.run([paths.KDESTROY, '-c', paths.KRB5CC_HTTPD], runas='apache',
|
|
|
|
|
raiseonerr=False)
|
|
|
|
|
|
2011-09-09 17:07:09 -04:00
|
|
|
# Remove the configuration files we create
|
2014-05-29 14:47:17 +02:00
|
|
|
installutils.remove_file(paths.HTTPD_IPA_REWRITE_CONF)
|
|
|
|
|
installutils.remove_file(paths.HTTPD_IPA_CONF)
|
|
|
|
|
installutils.remove_file(paths.HTTPD_IPA_PKI_PROXY_CONF)
|
2015-06-23 17:01:00 +02:00
|
|
|
installutils.remove_file(paths.HTTPD_IPA_KDCPROXY_CONF_SYMLINK)
|
2015-06-29 10:45:15 +02:00
|
|
|
installutils.remove_file(paths.HTTPD_IPA_KDCPROXY_CONF)
|
2011-09-09 17:07:09 -04:00
|
|
|
|
2014-08-14 17:14:07 +02:00
|
|
|
# Restore SELinux boolean states
|
|
|
|
|
boolean_states = {name: self.restore_state(name)
|
|
|
|
|
for name in SELINUX_BOOLEAN_SETTINGS}
|
|
|
|
|
try:
|
|
|
|
|
tasks.set_selinux_booleans(boolean_states)
|
|
|
|
|
except ipapython.errors.SetseboolError as e:
|
|
|
|
|
self.print_msg('WARNING: ' + str(e))
|
2008-01-11 11:57:36 +00:00
|
|
|
|
2015-01-27 11:04:03 +01:00
|
|
|
if running:
|
|
|
|
|
self.restart()
|
|
|
|
|
|
|
|
|
|
# disabled by default, by ldap_enable()
|
|
|
|
|
if enabled:
|
|
|
|
|
self.enable()
|
2013-03-26 18:06:50 +01:00
|
|
|
|
|
|
|
|
def stop_tracking_certificates(self):
|
|
|
|
|
db = certs.CertDB(api.env.realm)
|
|
|
|
|
db.untrack_server_cert(self.cert_nickname)
|