pgreco / rpms / ipa

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

Blame SOURCES/0053-adtrust-make-sure-that-runtime-hostname-result-is-co.patch

483b06
From dd4ae3da2d341a25b63936b689e53fdbc8e93f65 Mon Sep 17 00:00:00 2001
483b06
From: Alexander Bokovoy <abokovoy@redhat.com>
483b06
Date: Mon, 20 Mar 2017 13:23:44 +0200
483b06
Subject: [PATCH] adtrust: make sure that runtime hostname result is consistent
483b06
 with the configuration
483b06
483b06
FreeIPA's `ipasam` module to Samba uses gethostname() call to identify
483b06
own server's host name. This value is then used in multiple places,
483b06
including construction of cifs/host.name principal. `ipasam` module
483b06
always uses GSSAPI authentication when talking to LDAP, so Kerberos
483b06
keys must be available in the /etc/samba/samba.keytab. However, if
483b06
the principal was created using non-FQDN name but system reports
483b06
FQDN name, `ipasam` will fail to acquire Kerberos credentials.
483b06
Same with FQDN principal and non-FQDN hostname.
483b06
483b06
Also host name and principal name must have the same case.
483b06
483b06
Report an error when configuring ADTrust instance with inconsistent
483b06
runtime hostname and configuration. This prevents errors like this:
483b06
483b06
    [20/21]: starting CIFS services
483b06
    ipa         : CRITICAL CIFS services failed to start
483b06
483b06
    where samba logs have this:
483b06
483b06
    [2017/03/20 06:34:27.385307,  0] ipa_sam.c:4193(bind_callback_cleanup)
483b06
      kerberos error: code=-1765328203, message=Keytab contains no suitable keys for cifs/ipatrust@EXAMPLE.COM
483b06
    [2017/03/20 06:34:27.385476,  1] ../source3/lib/smbldap.c:1206(get_cached_ldap_connect)
483b06
      Connection to LDAP server failed for the 16 try!
483b06
483b06
Fixes https://pagure.io/freeipa/issue/6786
483b06
483b06
Reviewed-By: Martin Basti <mbasti@redhat.com>
483b06
---
483b06
 ipaserver/install/adtrustinstance.py | 12 ++++++++++++
483b06
 1 file changed, 12 insertions(+)
483b06
483b06
diff --git a/ipaserver/install/adtrustinstance.py b/ipaserver/install/adtrustinstance.py
483b06
index 0b189854f568ea5d8c0e68077255939887ff0cc3..b4db055045823ce8ae7e3b264e1442a085f81b2d 100644
483b06
--- a/ipaserver/install/adtrustinstance.py
483b06
+++ b/ipaserver/install/adtrustinstance.py
483b06
@@ -27,6 +27,7 @@ import uuid
483b06
 import string
483b06
 import struct
483b06
 import re
483b06
+import socket
483b06
 
483b06
 import six
483b06
 
483b06
@@ -689,6 +690,15 @@ class ADTRUSTInstance(service.Service):
483b06
         except Exception as e:
483b06
             root_logger.critical("Enabling nsswitch support in slapi-nis failed with error '%s'" % e)
483b06
 
483b06
+    def __validate_server_hostname(self):
483b06
+        hostname = socket.gethostname()
483b06
+        if hostname != self.fqdn:
483b06
+            raise ValueError("Host reports different name than configured: "
483b06
+                             "'%s' versus '%s'. Samba requires to have "
483b06
+                             "the same hostname or Kerberos principal "
483b06
+                             "'cifs/%s' will not be found in Samba keytab." %
483b06
+                             (hostname, self.fqdn, self.fqdn))
483b06
+
483b06
     def __start(self):
483b06
         try:
483b06
             self.start()
483b06
@@ -804,6 +814,8 @@ class ADTRUSTInstance(service.Service):
483b06
         api.Backend.ldap2.add_entry(entry)
483b06
 
483b06
     def create_instance(self):
483b06
+        self.step("validate server hostname",
483b06
+                  self.__validate_server_hostname)
483b06
         self.step("stopping smbd", self.__stop)
483b06
         self.step("creating samba domain object", \
483b06
                   self.__create_samba_domain_object)
483b06
-- 
483b06
2.12.2
483b06