937546
From 6953cecad70fc183ca4a8eddc467a7efa7ff83d3 Mon Sep 17 00:00:00 2001
937546
From: Florence Blanc-Renaud <flo@redhat.com>
937546
Date: Mon, 9 Sep 2019 12:58:48 +0200
937546
Subject: [PATCH] replica install: enforce --server arg
937546
937546
When the --server option is provided to ipa-replica-install (1-step
937546
install), make sure that the server offers all the required roles
937546
(CA, KRA). If it's not the case, refuse the installation.
937546
937546
Note that the --server option is ignored when promoting from client to
937546
replica (2-step install with ipa-client-install and ipa-replica-install),
937546
meaning that the existing behavior is not changed in this use case:
937546
by default the host specified in default.conf as server is used for
937546
enrollment, but if it does not provide a required role, another host can
937546
be picked for CA or KRA setup.
937546
937546
Fixes: https://pagure.io/freeipa/issue/7566
937546
Signed-off-by: Florence Blanc-Renaud <flo@redhat.com>
937546
Reviewed-By: Rob Crittenden <rcritten@redhat.com>
937546
Reviewed-By: Mohammad Rizwan Yusuf <myusuf@redhat.com>
937546
Reviewed-By: Rob Crittenden <rcritten@redhat.com>
937546
Reviewed-By: Mohammad Rizwan Yusuf <myusuf@redhat.com>
937546
---
937546
 install/tools/man/ipa-replica-install.1    |  4 ++-
937546
 ipaserver/install/server/replicainstall.py | 36 ++++++++++++++++++++--
937546
 2 files changed, 37 insertions(+), 3 deletions(-)
937546
937546
diff --git a/install/tools/man/ipa-replica-install.1 b/install/tools/man/ipa-replica-install.1
937546
index a1284135ac67de2b67b322aec3f6bbfb05f1a8ec..12764b8994a04bf56e80492bdcc66578a1f991e0 100644
937546
--- a/install/tools/man/ipa-replica-install.1
937546
+++ b/install/tools/man/ipa-replica-install.1
937546
@@ -51,7 +51,7 @@ One Time Password for joining a machine to the IPA realm.
937546
 Path to host keytab.
937546
 .TP
937546
 \fB\-\-server\fR
937546
-The fully qualified domain name of the IPA server to enroll to.
937546
+The fully qualified domain name of the IPA server to enroll to. The IPA server must provide the CA role if \fB\-\-setup-ca\fR option is specified, and the KRA role if \fB\-\-setup-kra\fR option is specified.
937546
 .TP
937546
 \fB\-n\fR, \fB\-\-domain\fR=\fIDOMAIN\fR
937546
 The primary DNS domain of an existing IPA deployment, e.g. example.com.
937546
@@ -281,3 +281,5 @@ path.
937546
 1 if an error occurred
937546
 
937546
 3 if the host exists in the IPA server or a replication agreement to the remote master already exists
937546
+
937546
+4 if the remote master specified for enrollment does not provide required services such as CA or KRA
937546
diff --git a/ipaserver/install/server/replicainstall.py b/ipaserver/install/server/replicainstall.py
937546
index bd82a9d1483545d478e790a727e48eaa9ac22cfc..14e8b2c3a76525c6ec2a16ca26fa032aab694a59 100644
937546
--- a/ipaserver/install/server/replicainstall.py
937546
+++ b/ipaserver/install/server/replicainstall.py
937546
@@ -1024,6 +1024,8 @@ def promote_check(installer):
937546
             print("IPA client is already configured on this system, ignoring "
937546
                   "the --domain, --server, --realm, --hostname, --password "
937546
                   "and --keytab options.")
937546
+            # Make sure options.server is not used
937546
+            options.server = None
937546
 
937546
     sstore = sysrestore.StateFile(paths.SYSRESTORE)
937546
 
937546
@@ -1269,8 +1271,15 @@ def promote_check(installer):
937546
             config.subject_base = DN(subject_base)
937546
 
937546
         # Find any server with a CA
937546
+        # The order of preference is
937546
+        # 1. the first server specified in --server, if any
937546
+        # 2. the server specified in the config file
937546
+        # 3. any other
937546
+        preferred_cas = [config.ca_host_name]
937546
+        if options.server:
937546
+            preferred_cas.insert(0, options.server)
937546
         ca_host = find_providing_server(
937546
-            'CA', conn, [config.ca_host_name]
937546
+            'CA', conn, preferred_cas
937546
         )
937546
         if ca_host is not None:
937546
             config.ca_host_name = ca_host
937546
@@ -1279,6 +1288,14 @@ def promote_check(installer):
937546
                 logger.error("Certificates could not be provided when "
937546
                              "CA is present on some master.")
937546
                 raise ScriptError(rval=3)
937546
+            if options.setup_ca and options.server and \
937546
+               ca_host != options.server:
937546
+                # Installer was provided with a specific master
937546
+                # but this one doesn't provide CA
937546
+                logger.error("The specified --server %s does not provide CA, "
937546
+                             "please provide a server with the CA role",
937546
+                             options.server)
937546
+                raise ScriptError(rval=4)
937546
         else:
937546
             if options.setup_ca:
937546
                 logger.error("The remote master does not have a CA "
937546
@@ -1293,12 +1310,27 @@ def promote_check(installer):
937546
                 raise ScriptError(rval=3)
937546
 
937546
         # Find any server with a KRA
937546
+        # The order of preference is
937546
+        # 1. the first server specified in --server, if any
937546
+        # 2. the server specified in the config file
937546
+        # 3. any other
937546
+        preferred_kras = [config.kra_host_name]
937546
+        if options.server:
937546
+            preferred_kras.insert(0, options.server)
937546
         kra_host = find_providing_server(
937546
-            'KRA', conn, [config.kra_host_name]
937546
+            'KRA', conn, preferred_kras
937546
         )
937546
         if kra_host is not None:
937546
             config.kra_host_name = kra_host
937546
             kra_enabled = True
937546
+            if options.setup_kra and options.server and \
937546
+               kra_host != options.server:
937546
+                # Installer was provided with a specific master
937546
+                # but this one doesn't provide KRA
937546
+                logger.error("The specified --server %s does not provide KRA, "
937546
+                             "please provide a server with the KRA role",
937546
+                             options.server)
937546
+                raise ScriptError(rval=4)
937546
         else:
937546
             if options.setup_kra:
937546
                 logger.error("There is no active KRA server in the domain, "
937546
-- 
937546
2.20.1
937546