pgreco / rpms / ipa

Forked from forks/areguera/rpms/ipa 4 years ago
Clone

Blame SOURCES/0123-Turn-on-NSSOCSP-check-in-mod_nss-conf.patch

483b06
From e8f329dd4340d5216d86160a8065e0530b981b47 Mon Sep 17 00:00:00 2001
483b06
From: Pavel Vomacka <pvomacka@redhat.com>
483b06
Date: Thu, 6 Apr 2017 16:15:47 +0200
483b06
Subject: [PATCH] Turn on NSSOCSP check in mod_nss conf
483b06
483b06
Turn on NSSOCSP directive during install/replica install/upgrade.
483b06
That check whether the certificate which is used for login is
483b06
revoked or not using OSCP.
483b06
483b06
Marks the server cert in httpd NSS DB as trusted peer ('P,,')
483b06
to avoid chicken and egg problem when it is needed to contact
483b06
the OCSP responder when httpd is starting.
483b06
483b06
https://pagure.io/freeipa/issue/6370
483b06
483b06
Reviewed-By: Florence Blanc-Renaud <frenaud@redhat.com>
483b06
Reviewed-By: Rob Crittenden <rcritten@redhat.com>
483b06
Reviewed-By: Jan Cholasta <jcholast@redhat.com>
483b06
Reviewed-By: Martin Basti <mbasti@redhat.com>
483b06
---
483b06
 freeipa.spec.in                       |  4 ++++
483b06
 install/restart_scripts/restart_httpd | 14 +++++++++++++-
483b06
 ipaserver/install/httpinstance.py     | 30 ++++++++++++++++++++++++++++++
483b06
 ipaserver/install/server/upgrade.py   | 25 +++++++++++++++++++++++++
483b06
 ipaserver/setup.py                    |  1 +
483b06
 5 files changed, 73 insertions(+), 1 deletion(-)
483b06
483b06
diff --git a/freeipa.spec.in b/freeipa.spec.in
483b06
index 1dd550bd39fd14349ede58bde337783aa5c0ea04..1b3ed15036eab6262b144d970cbdfdad31ac13ea 100644
483b06
--- a/freeipa.spec.in
483b06
+++ b/freeipa.spec.in
483b06
@@ -195,6 +195,7 @@ BuildRequires:  python-nose
483b06
 BuildRequires:  python-paste
483b06
 BuildRequires:  systemd-python
483b06
 BuildRequires:  python2-jinja2
483b06
+BuildRequires:  python-augeas
483b06
 
483b06
 %if 0%{?with_python3}
483b06
 # FIXME: this depedency is missing - server will not work
483b06
@@ -232,6 +233,7 @@ BuildRequires:  python3-nose
483b06
 BuildRequires:  python3-paste
483b06
 BuildRequires:  python3-systemd
483b06
 BuildRequires:  python3-jinja2
483b06
+BuildRequires:  python3-augeas
483b06
 %endif # with_python3
483b06
 %endif # with_lint
483b06
 
483b06
@@ -355,6 +357,7 @@ Requires: python-dns >= 1.15
483b06
 Requires: python-kdcproxy >= 0.3
483b06
 Requires: rpm-libs
483b06
 Requires: pki-base-python2
483b06
+Requires: python-augeas
483b06
 
483b06
 %description -n python2-ipaserver
483b06
 IPA is an integrated solution to provide centrally managed Identity (users,
483b06
@@ -384,6 +387,7 @@ Requires: python3-pyasn1
483b06
 Requires: python3-dbus
483b06
 Requires: python3-dns >= 1.15
483b06
 Requires: python3-kdcproxy >= 0.3
483b06
+Requires: python3-augeas
483b06
 Requires: rpm-libs
483b06
 Requires: pki-base-python3
483b06
 
483b06
diff --git a/install/restart_scripts/restart_httpd b/install/restart_scripts/restart_httpd
483b06
index d1684812904a9d32842a0ca548ec6b9df5a5a0b7..b661b82b896b109c3859ac82c2d84ab27b839f72 100644
483b06
--- a/install/restart_scripts/restart_httpd
483b06
+++ b/install/restart_scripts/restart_httpd
483b06
@@ -21,11 +21,23 @@
483b06
 
483b06
 import syslog
483b06
 import traceback
483b06
+from ipalib import api
483b06
 from ipaplatform import services
483b06
-from ipaserver.install import certs
483b06
+from ipaplatform.paths import paths
483b06
+from ipaserver.install import certs, installutils
483b06
 
483b06
 
483b06
 def _main():
483b06
+
483b06
+    api.bootstrap(in_server=True, context='restart', confdir=paths.ETC_IPA)
483b06
+    api.finalize()
483b06
+
483b06
+    db = certs.CertDB(api.env.realm, nssdir=paths.HTTPD_ALIAS_DIR)
483b06
+    nickname = installutils.get_directive(paths.HTTPD_NSS_CONF, "NSSNickname")
483b06
+
483b06
+    # Add trust flag which set certificate trusted for SSL connections.
483b06
+    db.trust_root_cert(nickname, "P,,")
483b06
+
483b06
     syslog.syslog(syslog.LOG_NOTICE, 'certmonger restarted httpd')
483b06
 
483b06
     try:
483b06
diff --git a/ipaserver/install/httpinstance.py b/ipaserver/install/httpinstance.py
483b06
index 7898c53bc02785e2750dba61a5696f079355c9d7..ab688a85f157b1886842a91bb7d22f9ea99e3615 100644
483b06
--- a/ipaserver/install/httpinstance.py
483b06
+++ b/ipaserver/install/httpinstance.py
483b06
@@ -29,6 +29,7 @@ import pipes
483b06
 import locale
483b06
 
483b06
 import six
483b06
+from augeas import Augeas
483b06
 
483b06
 from ipalib.install import certmonger
483b06
 from ipaserver.install import service
483b06
@@ -153,6 +154,7 @@ class HTTPInstance(service.Service):
483b06
                   self.set_mod_nss_protocol)
483b06
         self.step("setting mod_nss password file", self.__set_mod_nss_passwordfile)
483b06
         self.step("enabling mod_nss renegotiate", self.enable_mod_nss_renegotiate)
483b06
+        self.step("enabling mod_nss OCSP", self.enable_mod_nss_ocsp)
483b06
         self.step("adding URL rewriting rules", self.__add_include)
483b06
         self.step("configuring httpd", self.__configure_http)
483b06
         self.step("setting up httpd keytab", self.request_service_keytab)
483b06
@@ -259,6 +261,31 @@ class HTTPInstance(service.Service):
483b06
         installutils.set_directive(paths.HTTPD_NSS_CONF, 'NSSRenegotiation', 'on', False)
483b06
         installutils.set_directive(paths.HTTPD_NSS_CONF, 'NSSRequireSafeNegotiation', 'on', False)
483b06
 
483b06
+    def enable_mod_nss_ocsp(self):
483b06
+        aug = Augeas(flags=Augeas.NO_LOAD | Augeas.NO_MODL_AUTOLOAD)
483b06
+
483b06
+        aug.set('/augeas/load/Httpd/lens', 'Httpd.lns')
483b06
+        aug.set('/augeas/load/Httpd/incl', paths.HTTPD_NSS_CONF)
483b06
+        aug.load()
483b06
+
483b06
+        path = '/files{}/VirtualHost'.format(paths.HTTPD_NSS_CONF)
483b06
+
483b06
+        ocsp_comment = aug.get(
483b06
+                        '{}/#comment[.=~regexp("NSSOCSP .*")]'.format(path))
483b06
+        ocsp_dir = aug.get('{}/directive[.="NSSOCSP"]'.format(path))
483b06
+
483b06
+        if ocsp_dir is None and ocsp_comment is not None:
483b06
+            # Directive is missing, comment is present
483b06
+            aug.set('{}/#comment[.=~regexp("NSSOCSP .*")]'.format(path),
483b06
+                    'NSSOCSP')
483b06
+            aug.rename('{}/#comment[.="NSSOCSP"]'.format(path), 'directive')
483b06
+        elif ocsp_dir is None:
483b06
+            # Directive is missing and comment is missing
483b06
+            aug.set('{}/directive[last()+1]'.format(path), "NSSOCSP")
483b06
+
483b06
+        aug.set('{}/directive[. = "NSSOCSP"]/arg'.format(path), 'on')
483b06
+        aug.save()
483b06
+
483b06
     def set_mod_nss_cipher_suite(self):
483b06
         ciphers = ','.join(NSS_CIPHER_SUITE)
483b06
         installutils.set_directive(paths.HTTPD_NSS_CONF, 'NSSCipherSuite', ciphers, False)
483b06
@@ -351,6 +378,7 @@ class HTTPInstance(service.Service):
483b06
                           create=True)
483b06
         self.disable_system_trust()
483b06
         self.create_password_conf()
483b06
+
483b06
         if self.pkcs12_info:
483b06
             if self.ca_is_configured:
483b06
                 trust_flags = 'CT,C,C'
483b06
@@ -375,6 +403,8 @@ class HTTPInstance(service.Service):
483b06
             self.__set_mod_nss_nickname(nickname)
483b06
             self.add_cert_to_service()
483b06
 
483b06
+            db.trust_root_cert(nickname, "P,,")
483b06
+
483b06
         else:
483b06
             if not self.promote:
483b06
                 ca_args = [
483b06
diff --git a/ipaserver/install/server/upgrade.py b/ipaserver/install/server/upgrade.py
483b06
index 9aec2d857aee1a601f351218e253d44b14f6d4ec..7b0476d442902f2c3dc65819d54953e820f5e560 100644
483b06
--- a/ipaserver/install/server/upgrade.py
483b06
+++ b/ipaserver/install/server/upgrade.py
483b06
@@ -1392,6 +1392,24 @@ def fix_trust_flags():
483b06
     sysupgrade.set_upgrade_state('http', 'fix_trust_flags', True)
483b06
 
483b06
 
483b06
+def fix_server_cert_trust_flags():
483b06
+    root_logger.info(
483b06
+        '[Fixing server certificate trust flags in %s]' %
483b06
+        paths.HTTPD_ALIAS_DIR)
483b06
+
483b06
+    if sysupgrade.get_upgrade_state('http', 'fix_serv_cert_trust_flags'):
483b06
+        root_logger.info("Trust flags already processed")
483b06
+        return
483b06
+
483b06
+    db = certs.CertDB(api.env.realm, nssdir=paths.HTTPD_ALIAS_DIR)
483b06
+    sc_nickname = installutils.get_directive(paths.HTTPD_NSS_CONF,
483b06
+                                             "NSSNickname")
483b06
+    # Add trust flag which set certificate trusted for SSL connections.
483b06
+    db.trust_root_cert(sc_nickname, "P,,")
483b06
+
483b06
+    sysupgrade.set_upgrade_state('http', 'fix_serv_cert_trust_flags', True)
483b06
+
483b06
+
483b06
 def update_mod_nss_protocol(http):
483b06
     root_logger.info('[Updating mod_nss protocol versions]')
483b06
 
483b06
@@ -1404,6 +1422,11 @@ def update_mod_nss_protocol(http):
483b06
     sysupgrade.set_upgrade_state('nss.conf', 'protocol_updated_tls12', True)
483b06
 
483b06
 
483b06
+def enable_mod_nss_ocsp(http):
483b06
+    root_logger.info('[Updating mod_nss enabling OCSP]')
483b06
+    http.enable_mod_nss_ocsp()
483b06
+
483b06
+
483b06
 def update_mod_nss_cipher_suite(http):
483b06
     root_logger.info('[Updating mod_nss cipher suite]')
483b06
 
483b06
@@ -1671,7 +1694,9 @@ def upgrade_configuration():
483b06
     update_ipa_httpd_service_conf(http)
483b06
     update_mod_nss_protocol(http)
483b06
     update_mod_nss_cipher_suite(http)
483b06
+    enable_mod_nss_ocsp(http)
483b06
     fix_trust_flags()
483b06
+    fix_server_cert_trust_flags()
483b06
     update_http_keytab(http)
483b06
     http.configure_gssproxy()
483b06
     http.start()
483b06
diff --git a/ipaserver/setup.py b/ipaserver/setup.py
483b06
index 42b0c1b0618ef9867acb1fe2add5702a756cf2d2..e0b69e547ef8c2b76ce14ab27c1c29260e33f57f 100755
483b06
--- a/ipaserver/setup.py
483b06
+++ b/ipaserver/setup.py
483b06
@@ -60,6 +60,7 @@ if __name__ == '__main__':
483b06
             "pyasn1",
483b06
             "pyldap",
483b06
             "six",
483b06
+            "python-augeas",
483b06
             # not available on PyPI
483b06
             # "python-libipa_hbac",
483b06
             # "python-sss",
483b06
-- 
483b06
2.9.3
483b06