2007-10-15 14:42:12 -05:00
|
|
|
# Authors: Rob Crittenden <rcritten@redhat.com>
|
|
|
|
#
|
|
|
|
# Copyright (C) 2007 Red Hat
|
|
|
|
# see file 'COPYING' for use and warranty information
|
|
|
|
#
|
2010-12-09 06:59:11 -06: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 14:42:12 -05: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 06:59:11 -06:00
|
|
|
# along with this program. If not, see <http://www.gnu.org/licenses/>.
|
2007-10-15 14:42:12 -05:00
|
|
|
#
|
|
|
|
|
2015-08-12 06:44:11 -05:00
|
|
|
from __future__ import print_function
|
2017-11-30 13:55:50 -06:00
|
|
|
from __future__ import absolute_import
|
2015-08-12 06:44:11 -05:00
|
|
|
|
2017-05-24 09:35:07 -05:00
|
|
|
import logging
|
2007-12-13 03:31:28 -06:00
|
|
|
import os
|
2018-03-19 05:46:12 -05:00
|
|
|
import glob
|
|
|
|
import errno
|
2015-01-08 03:06:46 -06:00
|
|
|
import shlex
|
|
|
|
import pipes
|
2017-11-30 13:55:50 -06:00
|
|
|
import tempfile
|
2015-11-25 10:17:18 -06:00
|
|
|
|
2017-04-06 09:15:47 -05:00
|
|
|
from augeas import Augeas
|
2018-03-19 05:46:12 -05:00
|
|
|
import dbus
|
0000-12-31 18:09:24 -05:50
|
|
|
|
2016-11-23 08:04:40 -06:00
|
|
|
from ipalib.install import certmonger
|
2017-05-22 03:15:14 -05:00
|
|
|
from ipapython import ipaldap
|
|
|
|
from ipaserver.install import replication
|
2015-07-31 03:15:01 -05:00
|
|
|
from ipaserver.install import service
|
|
|
|
from ipaserver.install import certs
|
|
|
|
from ipaserver.install import installutils
|
2018-05-23 03:37:58 -05:00
|
|
|
from ipapython import directivesetter
|
2016-10-25 01:49:10 -05:00
|
|
|
from ipapython import dogtag
|
2009-02-05 14:03:08 -06:00
|
|
|
from ipapython import ipautil
|
2015-06-23 10:01:00 -05:00
|
|
|
from ipapython.dn import DN
|
2014-08-14 10:14:07 -05:00
|
|
|
import ipapython.errors
|
2013-10-25 03:22:08 -05:00
|
|
|
from ipaserver.install import sysupgrade
|
2017-11-30 13:55:50 -06:00
|
|
|
from ipalib import api, x509
|
2018-05-04 05:16:33 -05:00
|
|
|
from ipalib.constants import IPAAPI_USER, MOD_SSL_VERIFY_DEPTH
|
2015-10-06 08:02:37 -05:00
|
|
|
from ipaplatform.constants import constants
|
2014-05-29 03:51:08 -05:00
|
|
|
from ipaplatform.tasks import tasks
|
2014-05-29 07:47:17 -05:00
|
|
|
from ipaplatform.paths import paths
|
2015-01-20 03:38:43 -06:00
|
|
|
from ipaplatform import services
|
2014-08-14 10:14:07 -05:00
|
|
|
|
2017-05-24 09:35:07 -05:00
|
|
|
logger = logging.getLogger(__name__)
|
|
|
|
|
2015-10-06 08:02:37 -05:00
|
|
|
HTTPD_USER = constants.HTTPD_USER
|
2016-03-18 05:22:33 -05:00
|
|
|
KDCPROXY_USER = constants.KDCPROXY_USER
|
0000-12-31 18:09:24 -05:50
|
|
|
|
2017-11-30 13:55:50 -06:00
|
|
|
OCSP_DIRECTIVE = 'SSLOCSPEnable'
|
|
|
|
|
|
|
|
OCSP_ENABLED = 'ocsp_enabled'
|
2013-10-25 03:22:08 -05:00
|
|
|
|
2015-09-21 03:09:50 -05:00
|
|
|
|
2008-01-22 05:58:06 -06:00
|
|
|
class WebGuiInstance(service.SimpleServiceInstance):
|
|
|
|
def __init__(self):
|
|
|
|
service.SimpleServiceInstance.__init__(self, "ipa_webgui")
|
|
|
|
|
2017-03-24 03:52:18 -05:00
|
|
|
|
0000-12-31 18:09:24 -05:50
|
|
|
class HTTPInstance(service.Service):
|
2016-11-04 08:58:42 -05:00
|
|
|
def __init__(self, fstore=None, cert_nickname='Server-Cert',
|
|
|
|
api=api):
|
2016-11-03 10:38:06 -05:00
|
|
|
super(HTTPInstance, self).__init__(
|
|
|
|
"httpd",
|
|
|
|
service_desc="the web interface",
|
2016-11-03 11:43:33 -05:00
|
|
|
fstore=fstore,
|
2016-11-04 08:58:42 -05:00
|
|
|
api=api,
|
2016-11-03 11:54:14 -05:00
|
|
|
service_prefix=u'HTTP',
|
|
|
|
service_user=HTTPD_USER,
|
2016-11-29 10:10:22 -06:00
|
|
|
keytab=paths.HTTP_KEYTAB)
|
2007-10-15 14:42:12 -05:00
|
|
|
|
2017-03-24 03:52:18 -05:00
|
|
|
self.cacert_nickname = None
|
2013-03-15 04:09:58 -05:00
|
|
|
self.cert_nickname = cert_nickname
|
2014-10-13 07:30:15 -05:00
|
|
|
self.ca_is_configured = True
|
2016-11-29 10:10:22 -06:00
|
|
|
self.keytab_user = constants.GSSPROXY_USER
|
2013-03-15 04:09:58 -05:00
|
|
|
|
Use DN objects instead of strings
* 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
2012-05-13 06:36:35 -05:00
|
|
|
subject_base = ipautil.dn_attribute_property('_subject_base')
|
|
|
|
|
2017-05-22 03:15:14 -05:00
|
|
|
def create_instance(self, realm, fqdn, domain_name, dm_password=None,
|
|
|
|
pkcs12_info=None,
|
2014-10-13 07:30:15 -05:00
|
|
|
subject_base=None, auto_redirect=True, ca_file=None,
|
2017-05-22 03:15:14 -05:00
|
|
|
ca_is_configured=None, promote=False,
|
|
|
|
master_fqdn=None):
|
0000-12-31 18:09:24 -05:50
|
|
|
self.fqdn = fqdn
|
|
|
|
self.realm = realm
|
2008-02-15 19:47:29 -06:00
|
|
|
self.domain = domain_name
|
2017-05-22 03:15:14 -05:00
|
|
|
self.dm_password = dm_password
|
2012-04-18 10:22:35 -05:00
|
|
|
self.suffix = ipautil.realm_to_suffix(self.realm)
|
2008-02-05 11:23:53 -06:00
|
|
|
self.pkcs12_info = pkcs12_info
|
2017-06-16 03:18:07 -05:00
|
|
|
self.cert = None
|
2010-01-20 10:26:20 -06:00
|
|
|
self.subject_base = subject_base
|
2012-08-23 11:38:45 -05:00
|
|
|
self.sub_dict = dict(
|
|
|
|
REALM=realm,
|
|
|
|
FQDN=fqdn,
|
|
|
|
DOMAIN=self.domain,
|
|
|
|
AUTOREDIR='' if auto_redirect else '#',
|
2015-11-09 11:28:47 -06:00
|
|
|
CRL_PUBLISH_PATH=paths.PKI_CA_PUBLISH_DIR,
|
2017-03-29 03:33:32 -05:00
|
|
|
FONTS_DIR=paths.FONTS_DIR,
|
2019-04-17 06:52:53 -05:00
|
|
|
FONTS_OPENSANS_DIR=paths.FONTS_OPENSANS_DIR,
|
|
|
|
FONTS_FONTAWESOME_DIR=paths.FONTS_FONTAWESOME_DIR,
|
2017-03-29 03:33:32 -05:00
|
|
|
GSSAPI_SESSION_KEY=paths.GSSAPI_SESSION_KEY,
|
|
|
|
IPA_CUSTODIA_SOCKET=paths.IPA_CUSTODIA_SOCKET,
|
|
|
|
IPA_CCACHES=paths.IPA_CCACHES,
|
|
|
|
WSGI_PREFIX_DIR=paths.WSGI_PREFIX_DIR,
|
2018-06-14 10:04:13 -05:00
|
|
|
WSGI_PROCESSES=constants.WSGI_PROCESSES,
|
2012-08-23 11:38:45 -05:00
|
|
|
)
|
2013-03-26 09:31:07 -05:00
|
|
|
self.ca_file = ca_file
|
2014-10-13 07:30:15 -05:00
|
|
|
if ca_is_configured is not None:
|
|
|
|
self.ca_is_configured = ca_is_configured
|
2015-06-11 14:45:38 -05:00
|
|
|
self.promote = promote
|
2017-05-22 03:15:14 -05:00
|
|
|
self.master_fqdn = master_fqdn
|
2008-03-27 18:01:38 -05:00
|
|
|
|
2017-04-07 00:40:41 -05:00
|
|
|
self.step("stopping httpd", self.__stop)
|
2017-11-30 13:55:50 -06:00
|
|
|
self.step("backing up ssl.conf", self.backup_ssl_conf)
|
|
|
|
self.step("disabling nss.conf", self.disable_nss_conf)
|
2017-12-05 08:22:34 -06:00
|
|
|
self.step("configuring mod_ssl certificate paths",
|
|
|
|
self.configure_mod_ssl_certs)
|
2017-11-30 13:55:50 -06:00
|
|
|
self.step("setting mod_ssl protocol list to TLSv1.0 - TLSv1.2",
|
|
|
|
self.set_mod_ssl_protocol)
|
|
|
|
self.step("configuring mod_ssl log directory",
|
|
|
|
self.set_mod_ssl_logdir)
|
|
|
|
self.step("disabling mod_ssl OCSP", self.disable_mod_ssl_ocsp)
|
2011-02-02 09:24:30 -06:00
|
|
|
self.step("adding URL rewriting rules", self.__add_include)
|
2007-12-13 03:31:28 -06:00
|
|
|
self.step("configuring httpd", self.__configure_http)
|
2017-02-17 07:31:55 -06:00
|
|
|
self.step("setting up httpd keytab", self.request_service_keytab)
|
2016-11-29 10:10:22 -06:00
|
|
|
self.step("configuring Gssproxy", self.configure_gssproxy)
|
2016-11-10 06:14:34 -06:00
|
|
|
self.step("setting up ssl", self.__setup_ssl)
|
2015-01-08 03:06:46 -06:00
|
|
|
if self.ca_is_configured:
|
|
|
|
self.step("configure certmonger for renewals",
|
|
|
|
self.configure_certmonger_renewal_guard)
|
2017-03-13 10:12:46 -05:00
|
|
|
self.step("publish CA cert", self.__publish_ca_cert)
|
2016-11-29 10:10:22 -06:00
|
|
|
self.step("clean up any existing httpd ccaches",
|
|
|
|
self.remove_httpd_ccaches)
|
2012-04-03 03:47:40 -05:00
|
|
|
self.step("configuring SELinux for httpd", self.configure_selinux_for_httpd)
|
2015-06-23 10:01:00 -05: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)
|
2017-04-07 00:40:41 -05:00
|
|
|
self.step("starting httpd", self.start)
|
2008-01-14 11:43:26 -06:00
|
|
|
self.step("configuring httpd to start on boot", self.__enable)
|
2015-12-09 01:18:21 -06:00
|
|
|
self.step("enabling oddjobd", self.enable_and_start_oddjobd)
|
2007-12-13 03:31:28 -06:00
|
|
|
|
2017-03-01 10:35:56 -06:00
|
|
|
self.start_creation()
|
0000-12-31 18:09:24 -05:50
|
|
|
|
2017-04-07 00:40:41 -05:00
|
|
|
def __stop(self):
|
2008-01-14 11:43:26 -06:00
|
|
|
self.backup_state("running", self.is_running())
|
2017-04-07 00:40:41 -05:00
|
|
|
self.stop()
|
2008-01-14 11:43:26 -06:00
|
|
|
|
|
|
|
def __enable(self):
|
2015-01-27 04:04:03 -06:00
|
|
|
self.backup_state("enabled", self.is_enabled())
|
2010-12-04 14:42:14 -06: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
|
2018-07-05 17:04:39 -05:00
|
|
|
self.ldap_configure('HTTP', self.fqdn, None, self.suffix)
|
2008-01-14 11:43:26 -06:00
|
|
|
|
2012-04-03 03:47:40 -05:00
|
|
|
def configure_selinux_for_httpd(self):
|
2007-10-15 14:42:12 -05:00
|
|
|
try:
|
2017-05-18 10:19:23 -05:00
|
|
|
tasks.set_selinux_booleans(constants.SELINUX_BOOLEAN_HTTPD,
|
2014-08-14 10:14:07 -05:00
|
|
|
self.backup_state)
|
|
|
|
except ipapython.errors.SetseboolError as e:
|
|
|
|
self.print_msg(e.format_service_warning('web interface'))
|
2008-03-27 18:01:38 -05:00
|
|
|
|
2016-11-29 10:10:22 -06:00
|
|
|
def remove_httpd_ccaches(self):
|
|
|
|
# Clean up existing ccaches
|
2014-01-16 07:12:29 -06:00
|
|
|
# Make sure that empty env is passed to avoid passing KRB5CCNAME from
|
|
|
|
# current env
|
2016-11-29 10:10:22 -06:00
|
|
|
installutils.remove_file(paths.HTTP_CCACHE)
|
|
|
|
for f in os.listdir(paths.IPA_CCACHES):
|
|
|
|
os.remove(os.path.join(paths.IPA_CCACHES, f))
|
2013-05-07 09:33:55 -05:00
|
|
|
|
0000-12-31 18:09:24 -05:50
|
|
|
def __configure_http(self):
|
2016-03-16 03:04:42 -05:00
|
|
|
self.update_httpd_service_ipa_conf()
|
2018-02-06 03:05:49 -06:00
|
|
|
self.update_httpd_wsgi_conf()
|
2016-03-16 03:04:42 -05:00
|
|
|
|
2018-05-04 03:47:00 -05:00
|
|
|
# create /etc/httpd/alias, see https://pagure.io/freeipa/issue/7529
|
|
|
|
session_dir = os.path.dirname(self.sub_dict['GSSAPI_SESSION_KEY'])
|
|
|
|
if not os.path.isdir(session_dir):
|
|
|
|
os.makedirs(session_dir)
|
2018-06-22 05:25:33 -05:00
|
|
|
# Must be world-readable / executable
|
|
|
|
os.chmod(session_dir, 0o755)
|
2018-08-02 04:22:55 -05:00
|
|
|
# Restore SELinux context of session_dir /etc/httpd/alias, see
|
|
|
|
# https://pagure.io/freeipa/issue/7662
|
|
|
|
tasks.restore_context(session_dir)
|
2018-05-04 03:47:00 -05:00
|
|
|
|
2014-05-29 07:47:17 -05:00
|
|
|
target_fname = paths.HTTPD_IPA_CONF
|
2016-11-22 09:06:45 -06:00
|
|
|
http_txt = ipautil.template_file(
|
2017-03-15 12:28:07 -05:00
|
|
|
os.path.join(paths.USR_SHARE_IPA_DIR,
|
|
|
|
"ipa.conf.template"),
|
|
|
|
self.sub_dict)
|
2014-05-29 07:47:17 -05:00
|
|
|
self.fstore.backup_file(paths.HTTPD_IPA_CONF)
|
2011-08-30 09:32:40 -05:00
|
|
|
http_fd = open(target_fname, "w")
|
0000-12-31 18:09:24 -05:50
|
|
|
http_fd.write(http_txt)
|
2008-02-21 15:25:09 -06:00
|
|
|
http_fd.close()
|
2015-07-15 09:38:06 -05:00
|
|
|
os.chmod(target_fname, 0o644)
|
2007-10-15 14:42:12 -05:00
|
|
|
|
2014-05-29 07:47:17 -05:00
|
|
|
target_fname = paths.HTTPD_IPA_REWRITE_CONF
|
2016-11-22 09:06:45 -06:00
|
|
|
http_txt = ipautil.template_file(
|
2017-03-15 12:28:07 -05:00
|
|
|
os.path.join(paths.USR_SHARE_IPA_DIR,
|
|
|
|
"ipa-rewrite.conf.template"),
|
2016-11-22 09:06:45 -06:00
|
|
|
self.sub_dict)
|
2014-05-29 07:47:17 -05:00
|
|
|
self.fstore.backup_file(paths.HTTPD_IPA_REWRITE_CONF)
|
2011-08-30 09:32:40 -05:00
|
|
|
http_fd = open(target_fname, "w")
|
2008-02-21 15:25:09 -06:00
|
|
|
http_fd.write(http_txt)
|
|
|
|
http_fd.close()
|
2015-07-15 09:38:06 -05:00
|
|
|
os.chmod(target_fname, 0o644)
|
2007-10-15 14:42:12 -05:00
|
|
|
|
2016-11-29 10:10:22 -06:00
|
|
|
def configure_gssproxy(self):
|
2017-08-30 07:25:58 -05:00
|
|
|
tasks.configure_http_gssproxy_conf(IPAAPI_USER)
|
2016-11-29 10:10:22 -06:00
|
|
|
services.knownservices.gssproxy.restart()
|
|
|
|
|
2017-12-05 08:22:34 -06:00
|
|
|
def get_mod_nss_nickname(self):
|
2018-05-23 03:37:58 -05:00
|
|
|
cert = directivesetter.get_directive(paths.HTTPD_NSS_CONF,
|
|
|
|
'NSSNickname')
|
|
|
|
nickname = directivesetter.unquote_directive_value(cert,
|
|
|
|
quote_char="'")
|
2017-12-05 08:22:34 -06:00
|
|
|
return nickname
|
|
|
|
|
2017-11-30 13:55:50 -06:00
|
|
|
def backup_ssl_conf(self):
|
|
|
|
self.fstore.backup_file(paths.HTTPD_SSL_CONF)
|
2018-05-21 05:46:42 -05:00
|
|
|
self.fstore.backup_file(paths.HTTPD_SSL_SITE_CONF)
|
2017-11-30 13:55:50 -06:00
|
|
|
|
|
|
|
def disable_nss_conf(self):
|
2018-02-08 03:02:59 -06:00
|
|
|
"""
|
2018-12-11 07:00:25 -06:00
|
|
|
Backs up the original nss.conf file and replace it with the empty one.
|
|
|
|
Empty file avoids recreation of nss.conf in case the package is
|
|
|
|
reinstalled.
|
2018-02-08 03:02:59 -06:00
|
|
|
|
|
|
|
There is no safe way to co-exist since there is no safe port
|
|
|
|
to make mod_nss use, disable it completely.
|
|
|
|
"""
|
2017-11-30 13:55:50 -06:00
|
|
|
if os.path.exists(paths.HTTPD_NSS_CONF):
|
2018-02-08 03:02:59 -06:00
|
|
|
# check that we don't have a backup already
|
|
|
|
# (mod_nss -> mod_ssl upgrade scenario)
|
|
|
|
if not self.fstore.has_file(paths.HTTPD_NSS_CONF):
|
|
|
|
self.fstore.backup_file(paths.HTTPD_NSS_CONF)
|
2018-12-11 07:00:25 -06:00
|
|
|
|
|
|
|
open(paths.HTTPD_NSS_CONF, 'w').close()
|
2017-11-30 13:55:50 -06:00
|
|
|
|
|
|
|
def set_mod_ssl_protocol(self):
|
2018-05-23 03:37:58 -05:00
|
|
|
directivesetter.set_directive(paths.HTTPD_SSL_CONF,
|
2017-11-30 13:55:50 -06:00
|
|
|
'SSLProtocol',
|
|
|
|
'+TLSv1 +TLSv1.1 +TLSv1.2', False)
|
|
|
|
|
|
|
|
def set_mod_ssl_logdir(self):
|
2018-05-21 05:46:42 -05:00
|
|
|
tasks.setup_httpd_logging()
|
2017-11-30 13:55:50 -06:00
|
|
|
|
|
|
|
def disable_mod_ssl_ocsp(self):
|
|
|
|
if sysupgrade.get_upgrade_state('http', OCSP_ENABLED) is None:
|
|
|
|
self.__disable_mod_ssl_ocsp()
|
|
|
|
sysupgrade.set_upgrade_state('http', OCSP_ENABLED, False)
|
|
|
|
|
|
|
|
def __disable_mod_ssl_ocsp(self):
|
2017-04-06 09:15:47 -05:00
|
|
|
aug = Augeas(flags=Augeas.NO_LOAD | Augeas.NO_MODL_AUTOLOAD)
|
|
|
|
|
|
|
|
aug.set('/augeas/load/Httpd/lens', 'Httpd.lns')
|
2017-11-30 13:55:50 -06:00
|
|
|
aug.set('/augeas/load/Httpd/incl', paths.HTTPD_SSL_CONF)
|
2017-04-06 09:15:47 -05:00
|
|
|
aug.load()
|
|
|
|
|
2017-11-30 13:55:50 -06:00
|
|
|
path = '/files{}/VirtualHost'.format(paths.HTTPD_SSL_CONF)
|
2017-06-01 02:56:16 -05:00
|
|
|
ocsp_path = '{}/directive[.="{}"]'.format(path, OCSP_DIRECTIVE)
|
|
|
|
ocsp_arg = '{}/arg'.format(ocsp_path)
|
|
|
|
ocsp_comment = '{}/#comment[.="{}"]'.format(path, OCSP_DIRECTIVE)
|
2017-04-06 09:15:47 -05:00
|
|
|
|
2017-06-01 02:56:16 -05:00
|
|
|
ocsp_dir = aug.get(ocsp_path)
|
2017-04-06 09:15:47 -05:00
|
|
|
|
2017-11-30 13:55:50 -06:00
|
|
|
# there is SSLOCSPEnable directive in nss.conf file, comment it
|
2017-06-01 02:56:16 -05:00
|
|
|
# otherwise just do nothing
|
|
|
|
if ocsp_dir is not None:
|
|
|
|
ocsp_state = aug.get(ocsp_arg)
|
|
|
|
aug.remove(ocsp_arg)
|
|
|
|
aug.rename(ocsp_path, '#comment')
|
|
|
|
aug.set(ocsp_comment, '{} {}'.format(OCSP_DIRECTIVE, ocsp_state))
|
|
|
|
aug.save()
|
2017-04-06 09:15:47 -05:00
|
|
|
|
2008-02-21 15:25:09 -06:00
|
|
|
def __add_include(self):
|
|
|
|
"""This should run after __set_mod_nss_port so is already backed up"""
|
2018-05-21 05:46:42 -05:00
|
|
|
if installutils.update_file(paths.HTTPD_SSL_SITE_CONF,
|
2017-11-30 13:55:50 -06:00
|
|
|
'</VirtualHost>',
|
|
|
|
'Include {path}\n'
|
|
|
|
'</VirtualHost>'.format(
|
|
|
|
path=paths.HTTPD_IPA_REWRITE_CONF)
|
|
|
|
) != 0:
|
|
|
|
self.print_msg("Adding Include conf.d/ipa-rewrite to "
|
2018-05-21 05:46:42 -05:00
|
|
|
"%s failed." % paths.HTTPD_SSL_SITE_CONF)
|
0000-12-31 18:09:24 -05:50
|
|
|
|
2015-01-08 03:06:46 -06:00
|
|
|
def configure_certmonger_renewal_guard(self):
|
2015-01-20 03:38:43 -06: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 03:06:46 -06:00
|
|
|
|
0000-12-31 18:09:24 -05:50
|
|
|
def __setup_ssl(self):
|
2018-03-23 08:34:41 -05:00
|
|
|
key_passwd_file = paths.HTTPD_PASSWD_FILE_FMT.format(host=api.env.host)
|
2018-02-26 03:15:05 -06:00
|
|
|
with open(key_passwd_file, 'wb') as f:
|
|
|
|
os.fchmod(f.fileno(), 0o600)
|
|
|
|
pkey_passwd = ipautil.ipa_generate_password().encode('utf-8')
|
|
|
|
f.write(pkey_passwd)
|
|
|
|
|
2008-02-05 11:23:53 -06:00
|
|
|
if self.pkcs12_info:
|
2018-01-24 06:07:38 -06:00
|
|
|
p12_certs, p12_priv_keys = certs.pkcs12_to_certkeys(
|
|
|
|
*self.pkcs12_info)
|
|
|
|
keys_dict = {
|
|
|
|
k.public_key().public_numbers(): k
|
|
|
|
for k in p12_priv_keys
|
|
|
|
}
|
|
|
|
certs_keys = [
|
|
|
|
(c, keys_dict.get(c.public_key().public_numbers()))
|
|
|
|
for c in p12_certs
|
|
|
|
]
|
|
|
|
server_certs_keys = [
|
|
|
|
(c, k) for c, k in certs_keys if k is not None
|
|
|
|
]
|
|
|
|
|
|
|
|
if not server_certs_keys:
|
2017-11-30 13:55:50 -06:00
|
|
|
raise RuntimeError(
|
|
|
|
"Could not find a suitable server cert in import in %s"
|
|
|
|
% self.pkcs12_info[0]
|
|
|
|
)
|
2008-07-11 10:34:29 -05:00
|
|
|
|
|
|
|
# We only handle one server cert
|
2018-01-24 06:07:38 -06:00
|
|
|
self.cert = server_certs_keys[0][0]
|
|
|
|
x509.write_certificate(self.cert, paths.HTTPD_CERT_FILE)
|
|
|
|
x509.write_pem_private_key(
|
|
|
|
server_certs_keys[0][1],
|
2018-02-26 03:15:05 -06:00
|
|
|
paths.HTTPD_KEY_FILE,
|
|
|
|
passwd=pkey_passwd
|
2018-01-24 06:07:38 -06:00
|
|
|
)
|
2013-03-14 07:58:27 -05:00
|
|
|
|
2014-10-13 07:30:15 -05:00
|
|
|
if self.ca_is_configured:
|
2017-11-30 13:55:50 -06:00
|
|
|
self.start_tracking_certificates()
|
2008-07-11 10:34:29 -05:00
|
|
|
|
2015-06-11 14:45:38 -05:00
|
|
|
self.add_cert_to_service()
|
2010-12-08 15:35:12 -06:00
|
|
|
|
2016-10-31 10:51:49 -05:00
|
|
|
else:
|
|
|
|
if not self.promote:
|
2016-10-25 01:49:10 -05:00
|
|
|
ca_args = [
|
2017-01-13 02:08:42 -06:00
|
|
|
paths.CERTMONGER_DOGTAG_SUBMIT,
|
2016-10-25 01:49:10 -05:00
|
|
|
'--ee-url', 'https://%s:8443/ca/ee/ca' % self.fqdn,
|
2017-01-13 02:08:42 -06:00
|
|
|
'--certfile', paths.RA_AGENT_PEM,
|
|
|
|
'--keyfile', paths.RA_AGENT_KEY,
|
|
|
|
'--cafile', paths.IPA_CA_CRT,
|
2016-10-25 01:49:10 -05:00
|
|
|
'--agent-submit'
|
2017-01-13 02:08:42 -06:00
|
|
|
]
|
2016-10-25 01:49:10 -05:00
|
|
|
helper = " ".join(ca_args)
|
|
|
|
prev_helper = certmonger.modify_ca_helper('IPA', helper)
|
2017-04-07 00:43:09 -05:00
|
|
|
else:
|
|
|
|
prev_helper = None
|
|
|
|
try:
|
|
|
|
certmonger.request_and_wait_for_cert(
|
2017-11-30 13:55:50 -06:00
|
|
|
certpath=(paths.HTTPD_CERT_FILE, paths.HTTPD_KEY_FILE),
|
2017-04-07 00:43:09 -05:00
|
|
|
principal=self.principal,
|
|
|
|
subject=str(DN(('CN', self.fqdn), self.subject_base)),
|
|
|
|
ca='IPA',
|
|
|
|
profile=dogtag.DEFAULT_PROFILE,
|
|
|
|
dns=[self.fqdn],
|
2018-01-16 07:57:07 -06:00
|
|
|
post_command='restart_httpd',
|
|
|
|
storage='FILE',
|
2018-07-08 04:53:58 -05:00
|
|
|
passwd_fname=key_passwd_file,
|
|
|
|
resubmit_timeout=api.env.replication_wait_timeout
|
2017-11-30 13:55:50 -06:00
|
|
|
)
|
2017-04-07 00:43:09 -05:00
|
|
|
finally:
|
|
|
|
if prev_helper is not None:
|
2016-10-25 01:49:10 -05:00
|
|
|
certmonger.modify_ca_helper('IPA', prev_helper)
|
2017-12-05 08:22:34 -06:00
|
|
|
self.cert = x509.load_certificate_from_file(
|
|
|
|
paths.HTTPD_CERT_FILE
|
|
|
|
)
|
2017-04-07 00:43:09 -05:00
|
|
|
|
|
|
|
if prev_helper is not None:
|
2016-10-31 10:51:49 -05:00
|
|
|
self.add_cert_to_service()
|
|
|
|
|
2018-02-08 03:07:51 -06:00
|
|
|
with open(paths.HTTPD_KEY_FILE, 'rb') as f:
|
|
|
|
priv_key = x509.load_pem_private_key(
|
2018-02-26 03:15:05 -06:00
|
|
|
f.read(), pkey_passwd, backend=x509.default_backend())
|
2018-02-08 03:07:51 -06:00
|
|
|
|
2016-12-13 09:32:32 -06:00
|
|
|
# Verify we have a valid server cert
|
2018-02-08 03:07:51 -06:00
|
|
|
if (priv_key.public_key().public_numbers()
|
|
|
|
!= self.cert.public_key().public_numbers()):
|
|
|
|
raise RuntimeError(
|
|
|
|
"The public key of the issued HTTPD service certificate "
|
|
|
|
"does not match its private key.")
|
2016-10-31 10:51:49 -05:00
|
|
|
|
2017-12-05 08:22:34 -06:00
|
|
|
sysupgrade.set_upgrade_state('ssl.conf', 'migrated_to_mod_ssl', True)
|
2017-11-30 13:55:50 -06:00
|
|
|
|
2017-12-05 08:22:34 -06:00
|
|
|
def configure_mod_ssl_certs(self):
|
|
|
|
"""Configure the mod_ssl certificate directives"""
|
2018-05-23 03:37:58 -05:00
|
|
|
directivesetter.set_directive(paths.HTTPD_SSL_SITE_CONF,
|
2017-11-30 13:55:50 -06:00
|
|
|
'SSLCertificateFile',
|
|
|
|
paths.HTTPD_CERT_FILE, False)
|
2018-05-23 03:37:58 -05:00
|
|
|
directivesetter.set_directive(paths.HTTPD_SSL_SITE_CONF,
|
2017-11-30 13:55:50 -06:00
|
|
|
'SSLCertificateKeyFile',
|
|
|
|
paths.HTTPD_KEY_FILE, False)
|
2018-05-23 03:37:58 -05:00
|
|
|
directivesetter.set_directive(
|
2018-02-26 03:15:05 -06:00
|
|
|
paths.HTTPD_SSL_CONF,
|
|
|
|
'SSLPassPhraseDialog',
|
|
|
|
'exec:{passread}'.format(passread=paths.IPA_HTTPD_PASSWD_READER),
|
|
|
|
False)
|
2018-05-23 03:37:58 -05:00
|
|
|
directivesetter.set_directive(paths.HTTPD_SSL_SITE_CONF,
|
2017-11-30 13:55:50 -06:00
|
|
|
'SSLCACertificateFile',
|
|
|
|
paths.IPA_CA_CRT, False)
|
2018-05-04 05:16:33 -05:00
|
|
|
# set SSLVerifyDepth for external CA installations
|
2018-05-23 03:37:58 -05:00
|
|
|
directivesetter.set_directive(paths.HTTPD_SSL_CONF,
|
2018-05-04 05:16:33 -05:00
|
|
|
'SSLVerifyDepth',
|
|
|
|
MOD_SSL_VERIFY_DEPTH,
|
|
|
|
quotes=False)
|
2009-04-13 12:39:15 -05:00
|
|
|
|
2017-03-13 10:12:46 -05:00
|
|
|
def __publish_ca_cert(self):
|
2018-02-08 06:59:31 -06:00
|
|
|
ca_subject = self.cert.issuer
|
|
|
|
certlist = x509.load_certificate_list_from_file(paths.IPA_CA_CRT)
|
|
|
|
ca_certs = [c for c in certlist if c.subject == ca_subject]
|
|
|
|
if not ca_certs:
|
|
|
|
raise RuntimeError("HTTPD cert was issued by an unknown CA.")
|
|
|
|
# at this time we can assume any CA cert will be valid since this is
|
|
|
|
# only run during installation
|
2018-06-22 05:17:23 -05:00
|
|
|
x509.write_certificate_list(certlist, paths.CA_CRT, mode=0o644)
|
2017-03-13 10:12:46 -05:00
|
|
|
|
2015-06-23 10:01:00 -05: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"""
|
2017-04-25 11:55:59 -05:00
|
|
|
service.set_service_entry_config(
|
|
|
|
'KDC', self.fqdn, [u'kdcProxyEnabled'], self.suffix)
|
2015-06-23 10:01:00 -05:00
|
|
|
|
|
|
|
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(
|
2016-11-22 09:06:45 -06:00
|
|
|
os.path.join(paths.USR_SHARE_IPA_DIR,
|
|
|
|
"ipa-kdc-proxy.conf.template"),
|
|
|
|
sub_dict)
|
2015-06-23 10:01:00 -05:00
|
|
|
self.fstore.backup_file(target_fname)
|
|
|
|
with open(target_fname, 'w') as f:
|
|
|
|
f.write(http_txt)
|
2015-07-15 09:38:06 -05:00
|
|
|
os.chmod(target_fname, 0o644)
|
2015-06-23 10:01:00 -05:00
|
|
|
|
2015-12-09 01:18:21 -06:00
|
|
|
def enable_and_start_oddjobd(self):
|
2016-11-18 08:42:23 -06:00
|
|
|
oddjobd = services.service('oddjobd', api)
|
2015-12-09 01:18:21 -06:00
|
|
|
self.sstore.backup_state('oddjobd', 'running', oddjobd.is_running())
|
|
|
|
self.sstore.backup_state('oddjobd', 'enabled', oddjobd.is_enabled())
|
|
|
|
|
|
|
|
try:
|
|
|
|
oddjobd.enable()
|
|
|
|
oddjobd.start()
|
|
|
|
except Exception as e:
|
2017-05-24 09:35:07 -05:00
|
|
|
logger.critical("Unable to start oddjobd: %s", str(e))
|
2015-12-09 01:18:21 -06:00
|
|
|
|
2016-03-16 03:04:42 -05:00
|
|
|
def update_httpd_service_ipa_conf(self):
|
|
|
|
tasks.configure_httpd_service_ipa_conf()
|
|
|
|
|
2018-02-06 03:05:49 -06:00
|
|
|
def update_httpd_wsgi_conf(self):
|
|
|
|
tasks.configure_httpd_wsgi_conf()
|
|
|
|
|
2008-01-11 05:57:36 -06:00
|
|
|
def uninstall(self):
|
2010-05-03 14:21:51 -05:00
|
|
|
if self.is_configured():
|
|
|
|
self.print_msg("Unconfiguring web server")
|
|
|
|
|
2008-01-11 05:57:36 -06:00
|
|
|
running = self.restore_state("running")
|
|
|
|
enabled = self.restore_state("enabled")
|
|
|
|
|
2015-12-09 01:18:21 -06:00
|
|
|
# Restore oddjobd to its original state
|
2016-11-18 08:42:23 -06:00
|
|
|
oddjobd = services.service('oddjobd', api)
|
2015-12-09 01:18:21 -06:00
|
|
|
|
|
|
|
if not self.sstore.restore_state('oddjobd', 'running'):
|
|
|
|
try:
|
|
|
|
oddjobd.stop()
|
|
|
|
except Exception:
|
|
|
|
pass
|
|
|
|
|
|
|
|
if not self.sstore.restore_state('oddjobd', 'enabled'):
|
|
|
|
try:
|
|
|
|
oddjobd.disable()
|
|
|
|
except Exception:
|
|
|
|
pass
|
2008-01-11 05:57:36 -06:00
|
|
|
|
2013-03-26 12:06:50 -05:00
|
|
|
self.stop_tracking_certificates()
|
2015-01-08 03:06:46 -06: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)
|
|
|
|
|
2017-11-30 13:55:50 -06:00
|
|
|
for f in [paths.HTTPD_IPA_CONF, paths.HTTPD_SSL_CONF,
|
2018-05-21 05:46:42 -05:00
|
|
|
paths.HTTPD_SSL_SITE_CONF, paths.HTTPD_NSS_CONF]:
|
2008-03-27 18:01:38 -05:00
|
|
|
try:
|
|
|
|
self.fstore.restore_file(f)
|
2015-07-30 09:49:29 -05:00
|
|
|
except ValueError as error:
|
2017-05-24 09:35:07 -05:00
|
|
|
logger.debug("%s", error)
|
2008-01-11 05:57:36 -06:00
|
|
|
|
2011-09-09 16:07:09 -05:00
|
|
|
# Remove the configuration files we create
|
2018-03-19 05:46:12 -05:00
|
|
|
installutils.remove_keytab(self.keytab)
|
|
|
|
remove_files = [
|
|
|
|
paths.HTTP_CCACHE,
|
|
|
|
paths.HTTPD_CERT_FILE,
|
|
|
|
paths.HTTPD_KEY_FILE,
|
2018-03-23 08:34:41 -05:00
|
|
|
paths.HTTPD_PASSWD_FILE_FMT.format(host=api.env.host),
|
2018-03-19 05:46:12 -05:00
|
|
|
paths.HTTPD_IPA_REWRITE_CONF,
|
|
|
|
paths.HTTPD_IPA_CONF,
|
|
|
|
paths.HTTPD_IPA_PKI_PROXY_CONF,
|
|
|
|
paths.HTTPD_IPA_KDCPROXY_CONF_SYMLINK,
|
|
|
|
paths.HTTPD_IPA_KDCPROXY_CONF,
|
|
|
|
paths.GSSPROXY_CONF,
|
|
|
|
paths.GSSAPI_SESSION_KEY,
|
|
|
|
paths.HTTPD_PASSWORD_CONF,
|
|
|
|
paths.SYSTEMD_SYSTEM_HTTPD_IPA_CONF,
|
|
|
|
]
|
|
|
|
# NSS DB backups
|
|
|
|
remove_files.extend(
|
|
|
|
glob.glob(os.path.join(paths.HTTPD_ALIAS_DIR, '*.ipasave'))
|
|
|
|
)
|
2018-02-06 03:05:49 -06:00
|
|
|
if paths.HTTPD_IPA_WSGI_MODULES_CONF is not None:
|
2018-03-19 05:46:12 -05:00
|
|
|
remove_files.append(paths.HTTPD_IPA_WSGI_MODULES_CONF)
|
|
|
|
|
|
|
|
for filename in remove_files:
|
|
|
|
installutils.remove_file(filename)
|
|
|
|
|
|
|
|
try:
|
|
|
|
os.rmdir(paths.SYSTEMD_SYSTEM_HTTPD_D_DIR)
|
|
|
|
except OSError as e:
|
|
|
|
if e.errno not in {errno.ENOENT, errno.ENOTEMPTY}:
|
|
|
|
logger.error(
|
|
|
|
"Failed to remove directory %s",
|
|
|
|
paths.SYSTEMD_SYSTEM_HTTPD_D_DIR
|
|
|
|
)
|
2011-09-09 16:07:09 -05:00
|
|
|
|
2014-08-14 10:14:07 -05:00
|
|
|
# Restore SELinux boolean states
|
|
|
|
boolean_states = {name: self.restore_state(name)
|
2017-05-18 10:19:23 -05:00
|
|
|
for name in constants.SELINUX_BOOLEAN_HTTPD}
|
2014-08-14 10:14:07 -05:00
|
|
|
try:
|
|
|
|
tasks.set_selinux_booleans(boolean_states)
|
|
|
|
except ipapython.errors.SetseboolError as e:
|
|
|
|
self.print_msg('WARNING: ' + str(e))
|
2008-01-11 05:57:36 -06:00
|
|
|
|
2015-01-27 04:04:03 -06:00
|
|
|
if running:
|
|
|
|
self.restart()
|
|
|
|
|
2018-07-05 17:04:39 -05:00
|
|
|
# disabled by default, by ldap_configure()
|
2015-01-27 04:04:03 -06:00
|
|
|
if enabled:
|
|
|
|
self.enable()
|
2013-03-26 12:06:50 -05:00
|
|
|
|
|
|
|
def stop_tracking_certificates(self):
|
2017-11-30 13:55:50 -06:00
|
|
|
try:
|
|
|
|
certmonger.stop_tracking(certfile=paths.HTTPD_CERT_FILE)
|
|
|
|
except RuntimeError as e:
|
|
|
|
logger.error("certmonger failed to stop tracking certificate: %s",
|
|
|
|
str(e))
|
2016-02-17 08:18:17 -06:00
|
|
|
|
|
|
|
def start_tracking_certificates(self):
|
2017-12-05 08:22:34 -06:00
|
|
|
cert = x509.load_certificate_from_file(paths.HTTPD_CERT_FILE)
|
2017-11-30 13:55:50 -06:00
|
|
|
if certs.is_ipa_issued_cert(api, cert):
|
|
|
|
request_id = certmonger.start_tracking(
|
2017-12-05 08:22:34 -06:00
|
|
|
certpath=(paths.HTTPD_CERT_FILE, paths.HTTPD_KEY_FILE),
|
|
|
|
post_command='restart_httpd', storage='FILE'
|
2017-11-30 13:55:50 -06:00
|
|
|
)
|
|
|
|
subject = str(DN(cert.subject))
|
2017-12-05 08:22:34 -06:00
|
|
|
certmonger.add_principal(request_id, self.principal)
|
2017-11-30 13:55:50 -06:00
|
|
|
certmonger.add_subject(request_id, subject)
|
2017-09-05 09:17:31 -05:00
|
|
|
else:
|
|
|
|
logger.debug("Will not track HTTP server cert %s as it is not "
|
2017-11-30 13:55:50 -06:00
|
|
|
"issued by IPA", cert.subject)
|
2017-05-22 03:15:14 -05:00
|
|
|
|
|
|
|
def request_service_keytab(self):
|
|
|
|
super(HTTPInstance, self).request_service_keytab()
|
|
|
|
|
|
|
|
if self.master_fqdn is not None:
|
|
|
|
service_dn = DN(('krbprincipalname', self.principal),
|
|
|
|
api.env.container_service,
|
|
|
|
self.suffix)
|
|
|
|
|
|
|
|
ldap_uri = ipaldap.get_ldap_uri(self.master_fqdn)
|
|
|
|
with ipaldap.LDAPClient(ldap_uri,
|
|
|
|
start_tls=not self.promote,
|
|
|
|
cacert=paths.IPA_CA_CRT) as remote_ldap:
|
|
|
|
if self.promote:
|
|
|
|
remote_ldap.gssapi_bind()
|
|
|
|
else:
|
|
|
|
remote_ldap.simple_bind(ipaldap.DIRMAN_DN,
|
|
|
|
self.dm_password)
|
2018-06-22 03:00:24 -05:00
|
|
|
replication.wait_for_entry(
|
|
|
|
remote_ldap,
|
|
|
|
service_dn,
|
|
|
|
timeout=api.env.replication_wait_timeout
|
|
|
|
)
|
2017-12-05 08:22:34 -06:00
|
|
|
|
|
|
|
def migrate_to_mod_ssl(self):
|
|
|
|
"""For upgrades only, migrate from mod_nss to mod_ssl"""
|
|
|
|
db = certs.CertDB(api.env.realm, nssdir=paths.HTTPD_ALIAS_DIR)
|
|
|
|
nickname = self.get_mod_nss_nickname()
|
|
|
|
with tempfile.NamedTemporaryFile() as temp:
|
|
|
|
pk12_password = ipautil.ipa_generate_password()
|
|
|
|
pk12_pwdfile = ipautil.write_tmp_file(pk12_password)
|
|
|
|
db.export_pkcs12(temp.name, pk12_pwdfile.name, nickname)
|
|
|
|
certs.install_pem_from_p12(temp.name,
|
|
|
|
pk12_password,
|
|
|
|
paths.HTTPD_CERT_FILE)
|
2018-03-23 08:34:41 -05:00
|
|
|
|
|
|
|
passwd_fname = paths.HTTPD_PASSWD_FILE_FMT.format(
|
|
|
|
host=api.env.host)
|
|
|
|
with open(passwd_fname, 'wb') as passwd_file:
|
|
|
|
os.fchmod(passwd_file.fileno(), 0o600)
|
|
|
|
passwd_file.write(
|
|
|
|
ipautil.ipa_generate_password().encode('utf-8'))
|
|
|
|
|
2017-12-05 08:22:34 -06:00
|
|
|
certs.install_key_from_p12(temp.name,
|
|
|
|
pk12_password,
|
2018-03-23 08:34:41 -05:00
|
|
|
paths.HTTPD_KEY_FILE,
|
|
|
|
out_passwd_fname=passwd_fname)
|
2017-12-05 08:22:34 -06:00
|
|
|
|
2018-02-16 01:06:21 -06:00
|
|
|
self.backup_ssl_conf()
|
2017-12-05 08:22:34 -06:00
|
|
|
self.configure_mod_ssl_certs()
|
|
|
|
self.set_mod_ssl_protocol()
|
|
|
|
self.set_mod_ssl_logdir()
|
2018-02-06 06:08:50 -06:00
|
|
|
self.__add_include()
|
2017-12-05 08:22:34 -06:00
|
|
|
|
|
|
|
self.cert = x509.load_certificate_from_file(paths.HTTPD_CERT_FILE)
|
|
|
|
|
|
|
|
if self.ca_is_configured:
|
|
|
|
db.untrack_server_cert(nickname)
|
|
|
|
self.start_tracking_certificates()
|
|
|
|
|
|
|
|
# remove nickname and CA certs from NSS db
|
|
|
|
|
|
|
|
self.disable_nss_conf()
|