Blame SOURCES/0004-AD-Allow-configuring-auto_private_groups-per-subdoma.patch

5fca41
From 6f6b3b1f4fcec79a1640a97fb3cd875f2cd8b83a Mon Sep 17 00:00:00 2001
5fca41
From: Jakub Hrozek <jhrozek@redhat.com>
5fca41
Date: Tue, 19 Mar 2019 11:01:10 +0100
5fca41
Subject: [PATCH] AD: Allow configuring auto_private_groups per subdomain or
5fca41
 with subdomain_inherit
5fca41
MIME-Version: 1.0
5fca41
Content-Type: text/plain; charset=UTF-8
5fca41
Content-Transfer-Encoding: 8bit
5fca41
5fca41
Resolves:
5fca41
https://pagure.io/SSSD/sssd/issue/3965
5fca41
5fca41
Previously, subdomains that used ID mapping always only used MPGs and
5fca41
POSIX subdomains always inherited the parent domain settings. This patch
5fca41
is a small RFE which allows to either set the auto_private_groups option
5fca41
directly per subdomain or set it for all subdomains using the
5fca41
subdomain_inherit option
5fca41
5fca41
Reviewed-by: Pavel Březina <pbrezina@redhat.com>
5fca41
(cherry picked from commit 41c497b8b9e6efb9f2aa8e4cc869d465c3b954b3)
5fca41
---
5fca41
 src/man/sssd.conf.5.xml               |  38 +++++----
5fca41
 src/providers/ad/ad_subdomains.c      | 107 ++++++++++++++++++++++----
5fca41
 src/providers/ldap/sdap_async_users.c |   2 +-
5fca41
 src/util/domain_info_utils.c          |  14 +++-
5fca41
 src/util/util.h                       |   3 +
5fca41
 5 files changed, 130 insertions(+), 34 deletions(-)
5fca41
5fca41
diff --git a/src/man/sssd.conf.5.xml b/src/man/sssd.conf.5.xml
5fca41
index 41ba7b924..3d017f638 100644
5fca41
--- a/src/man/sssd.conf.5.xml
5fca41
+++ b/src/man/sssd.conf.5.xml
5fca41
@@ -2995,6 +2995,13 @@ subdomain_inherit = ldap_purge_cache_timeout
5fca41
                                             Create user's private group unconditionally from user's UID number.
5fca41
                                             The GID number is ignored in this case.
5fca41
                                         </para>
5fca41
+                                        <para>
5fca41
+                                            NOTE: Because the GID number and the user private group
5fca41
+                                            are inferred from the UID number, it is not supported
5fca41
+                                            to have multiple entries with the same UID or GID number
5fca41
+                                            with this option. In other words, enabling this option
5fca41
+                                            enforces uniqueness across the ID space.
5fca41
+                                        </para>
5fca41
                                     </listitem>
5fca41
                                 </varlistentry>
5fca41
                                 <varlistentry>
5fca41
@@ -3041,24 +3048,25 @@ subdomain_inherit = ldap_purge_cache_timeout
5fca41
                                 </varlistentry>
5fca41
                             </variablelist>
5fca41
                         </para>
5fca41
-			<para>
5fca41
-			    For POSIX subdomains, setting the option in the main
5fca41
-			    domain is inherited in the subdomain.
5fca41
-			</para>
5fca41
-			<para>
5fca41
-			    For ID-mapping subdomains, auto_private_groups is
5fca41
-			    already enabled for the subdomains and setting it to
5fca41
-			    false will not have any effect for the subdomain.
5fca41
-			</para>
5fca41
                         <para>
5fca41
-                            NOTE: Because the GID number and the user private group
5fca41
-                            are inferred from the UID number, it is not supported
5fca41
-                            to have multiple entries with the same UID or GID number
5fca41
-                            with this option. In other words, enabling this option
5fca41
-                            enforces uniqueness across the ID space.
5fca41
+                            For subdomains, the default value is False for
5fca41
+                            subdomains that use assigned POSIX IDs and True
5fca41
+                            for subdomains that use automatic ID-mapping.
5fca41
                         </para>
5fca41
                         <para>
5fca41
-                            Default: False
5fca41
+                            The value of auto_private_groups can either be set per subdomains
5fca41
+                            in a subsection, for example:
5fca41
+<programlisting>
5fca41
+[domain/forest.domain/sub.domain]
5fca41
+auto_private_groups = false
5fca41
+</programlisting>
5fca41
+                            or globally for all subdomains in the main domain section
5fca41
+                            using the subdomain_inherit option:
5fca41
+<programlisting>
5fca41
+[domain/forest.domain]
5fca41
+subdomain_inherit = auto_private_groups
5fca41
+auto_private_groups = false
5fca41
+</programlisting>
5fca41
                         </para>
5fca41
                     </listitem>
5fca41
                 </varlistentry>
5fca41
diff --git a/src/providers/ad/ad_subdomains.c b/src/providers/ad/ad_subdomains.c
5fca41
index 5b046773c..4fc4be094 100644
5fca41
--- a/src/providers/ad/ad_subdomains.c
5fca41
+++ b/src/providers/ad/ad_subdomains.c
5fca41
@@ -436,8 +436,87 @@ static errno_t ad_subdom_enumerates(struct sss_domain_info *parent,
5fca41
     return EOK;
5fca41
 }
5fca41
 
5fca41
+static enum sss_domain_mpg_mode
5fca41
+get_default_subdom_mpg_mode(struct sdap_idmap_ctx *idmap_ctx,
5fca41
+                            struct sss_domain_info *parent,
5fca41
+                            const char *subdom_name,
5fca41
+                            char *subdom_sid_str)
5fca41
+{
5fca41
+    bool use_id_mapping;
5fca41
+    bool inherit_option;
5fca41
+    enum sss_domain_mpg_mode default_mpg_mode;
5fca41
+
5fca41
+    inherit_option = string_in_list(CONFDB_DOMAIN_AUTO_UPG,
5fca41
+                                    parent->sd_inherit, false);
5fca41
+    if (inherit_option) {
5fca41
+        return get_domain_mpg_mode(parent);
5fca41
+    }
5fca41
+
5fca41
+    use_id_mapping = sdap_idmap_domain_has_algorithmic_mapping(idmap_ctx,
5fca41
+                                                               subdom_name,
5fca41
+                                                               subdom_sid_str);
5fca41
+    if (use_id_mapping == true) {
5fca41
+        default_mpg_mode = MPG_ENABLED;
5fca41
+    } else {
5fca41
+        /* Domains that use the POSIX attributes set by the admin must
5fca41
+         * inherit the MPG setting from the parent domain so that the
5fca41
+         * auto_private_groups options works for trusted domains as well
5fca41
+         */
5fca41
+        default_mpg_mode = get_domain_mpg_mode(parent);
5fca41
+    }
5fca41
+
5fca41
+    return default_mpg_mode;
5fca41
+}
5fca41
+
5fca41
+static enum sss_domain_mpg_mode
5fca41
+ad_subdom_mpg_mode(TALLOC_CTX *mem_ctx,
5fca41
+                   struct confdb_ctx *cdb,
5fca41
+                   struct sss_domain_info *parent,
5fca41
+                   enum sss_domain_mpg_mode default_mpg_mode,
5fca41
+                   const char *subdom_name)
5fca41
+{
5fca41
+    char *subdom_conf_path;
5fca41
+    char *mpg_str_opt;
5fca41
+    errno_t ret;
5fca41
+    enum sss_domain_mpg_mode ret_mode;
5fca41
+
5fca41
+    subdom_conf_path = subdomain_create_conf_path_from_str(mem_ctx,
5fca41
+                                                           parent->name,
5fca41
+                                                           subdom_name);
5fca41
+    if (subdom_conf_path == NULL) {
5fca41
+        DEBUG(SSSDBG_OP_FAILURE,
5fca41
+              "subdom_conf_path failed, will use %s mode as fallback\n",
5fca41
+              str_domain_mpg_mode(default_mpg_mode));
5fca41
+        return default_mpg_mode;
5fca41
+    }
5fca41
+
5fca41
+    ret = confdb_get_string(cdb, mem_ctx, subdom_conf_path,
5fca41
+                            CONFDB_DOMAIN_AUTO_UPG,
5fca41
+                            NULL,
5fca41
+                            &mpg_str_opt);
5fca41
+    talloc_free(subdom_conf_path);
5fca41
+    if (ret != EOK) {
5fca41
+        DEBUG(SSSDBG_OP_FAILURE,
5fca41
+              "condb_get_string failed, will use %s mode as fallback\n",
5fca41
+              str_domain_mpg_mode(default_mpg_mode));
5fca41
+        return default_mpg_mode;
5fca41
+    }
5fca41
+
5fca41
+    if (mpg_str_opt == NULL) {
5fca41
+        DEBUG(SSSDBG_CONF_SETTINGS,
5fca41
+              "Subdomain MPG mode not set, using %s\n",
5fca41
+              str_domain_mpg_mode(default_mpg_mode));
5fca41
+        return default_mpg_mode;
5fca41
+    }
5fca41
+
5fca41
+    ret_mode = str_to_domain_mpg_mode(mpg_str_opt);
5fca41
+    talloc_free(mpg_str_opt);
5fca41
+    return ret_mode;
5fca41
+}
5fca41
+
5fca41
 static errno_t
5fca41
-ad_subdom_store(struct sdap_idmap_ctx *idmap_ctx,
5fca41
+ad_subdom_store(struct confdb_ctx *cdb,
5fca41
+                struct sdap_idmap_ctx *idmap_ctx,
5fca41
                 struct sss_domain_info *domain,
5fca41
                 struct sysdb_attrs *subdom_attrs,
5fca41
                 bool enumerate)
5fca41
@@ -451,8 +530,8 @@ ad_subdom_store(struct sdap_idmap_ctx *idmap_ctx,
5fca41
     struct ldb_message_element *el;
5fca41
     char *sid_str = NULL;
5fca41
     uint32_t trust_type;
5fca41
-    bool use_id_mapping;
5fca41
     enum sss_domain_mpg_mode mpg_mode;
5fca41
+    enum sss_domain_mpg_mode default_mpg_mode;
5fca41
 
5fca41
     tmp_ctx = talloc_new(NULL);
5fca41
     if (tmp_ctx == NULL) {
5fca41
@@ -501,17 +580,13 @@ ad_subdom_store(struct sdap_idmap_ctx *idmap_ctx,
5fca41
         goto done;
5fca41
     }
5fca41
 
5fca41
-    use_id_mapping = sdap_idmap_domain_has_algorithmic_mapping(idmap_ctx,
5fca41
-                                                               name, sid_str);
5fca41
-    if (use_id_mapping == true) {
5fca41
-        mpg_mode = MPG_ENABLED;
5fca41
-    } else {
5fca41
-        /* Domains that use the POSIX attributes set by the admin must
5fca41
-         * inherit the MPG setting from the parent domain so that the
5fca41
-         * auto_private_groups options works for trusted domains as well
5fca41
-         */
5fca41
-        mpg_mode = get_domain_mpg_mode(domain);
5fca41
-    }
5fca41
+    default_mpg_mode = get_default_subdom_mpg_mode(idmap_ctx, domain,
5fca41
+                                                   name, sid_str);
5fca41
+
5fca41
+    mpg_mode = ad_subdom_mpg_mode(tmp_ctx, cdb, domain,
5fca41
+                                  default_mpg_mode, name);
5fca41
+    DEBUG(SSSDBG_CONF_SETTINGS, "MPG mode of %s is %s\n",
5fca41
+                                name, str_domain_mpg_mode(mpg_mode));
5fca41
 
5fca41
     ret = sysdb_subdomain_store(domain->sysdb, name, realm, flat, sid_str,
5fca41
                                 mpg_mode, enumerate, domain->forest, 0, NULL);
5fca41
@@ -625,7 +700,8 @@ static errno_t ad_subdomains_refresh(struct be_ctx *be_ctx,
5fca41
                 goto done;
5fca41
             }
5fca41
 
5fca41
-            ret = ad_subdom_store(idmap_ctx, domain, subdomains[c], enumerate);
5fca41
+            ret = ad_subdom_store(be_ctx->cdb, idmap_ctx, domain,
5fca41
+                                  subdomains[c], enumerate);
5fca41
             if (ret) {
5fca41
                 /* Nothing we can do about the error. Let's at least try
5fca41
                  * to reuse the existing domains
5fca41
@@ -660,7 +736,8 @@ static errno_t ad_subdomains_refresh(struct be_ctx *be_ctx,
5fca41
             goto done;
5fca41
         }
5fca41
 
5fca41
-        ret = ad_subdom_store(idmap_ctx, domain, subdomains[c], enumerate);
5fca41
+        ret = ad_subdom_store(be_ctx->cdb, idmap_ctx, domain,
5fca41
+                              subdomains[c], enumerate);
5fca41
         if (ret) {
5fca41
             DEBUG(SSSDBG_MINOR_FAILURE, "Failed to parse subdom data, "
5fca41
                   "will try to use cached subdomain\n");
5fca41
diff --git a/src/providers/ldap/sdap_async_users.c b/src/providers/ldap/sdap_async_users.c
5fca41
index 92eeda1d3..af4dc1a17 100644
5fca41
--- a/src/providers/ldap/sdap_async_users.c
5fca41
+++ b/src/providers/ldap/sdap_async_users.c
5fca41
@@ -389,7 +389,7 @@ int sdap_save_user(TALLOC_CTX *memctx,
5fca41
             goto done;
5fca41
         }
5fca41
 
5fca41
-        if (IS_SUBDOMAIN(dom) || sss_domain_is_mpg(dom) == true) {
5fca41
+        if (sss_domain_is_mpg(dom) == true) {
5fca41
             /* For subdomain users, only create the private group as
5fca41
              * the subdomain is an MPG domain.
5fca41
              * But we have to save the GID of the original primary group
5fca41
diff --git a/src/util/domain_info_utils.c b/src/util/domain_info_utils.c
5fca41
index 4896ef051..4b1c9df39 100644
5fca41
--- a/src/util/domain_info_utils.c
5fca41
+++ b/src/util/domain_info_utils.c
5fca41
@@ -889,6 +889,14 @@ bool sss_domain_is_forest_root(struct sss_domain_info *dom)
5fca41
     return (dom->forest_root == dom);
5fca41
 }
5fca41
 
5fca41
+char *subdomain_create_conf_path_from_str(TALLOC_CTX *mem_ctx,
5fca41
+                                          const char *parent_name,
5fca41
+                                          const char *subdom_name)
5fca41
+{
5fca41
+    return talloc_asprintf(mem_ctx, CONFDB_DOMAIN_PATH_TMPL "/%s",
5fca41
+                           parent_name, subdom_name);
5fca41
+}
5fca41
+
5fca41
 char *subdomain_create_conf_path(TALLOC_CTX *mem_ctx,
5fca41
                                  struct sss_domain_info *subdomain)
5fca41
 {
5fca41
@@ -899,9 +907,9 @@ char *subdomain_create_conf_path(TALLOC_CTX *mem_ctx,
5fca41
         return NULL;
5fca41
     }
5fca41
 
5fca41
-    return talloc_asprintf(mem_ctx, CONFDB_DOMAIN_PATH_TMPL "/%s",
5fca41
-                           subdomain->parent->name,
5fca41
-                           subdomain->name);
5fca41
+    return subdomain_create_conf_path_from_str(mem_ctx,
5fca41
+                                               subdomain->parent->name,
5fca41
+                                               subdomain->name);
5fca41
 }
5fca41
 
5fca41
 const char *sss_domain_type_str(struct sss_domain_info *dom)
5fca41
diff --git a/src/util/util.h b/src/util/util.h
5fca41
index 1e36bf02a..3003583b7 100644
5fca41
--- a/src/util/util.h
5fca41
+++ b/src/util/util.h
5fca41
@@ -557,6 +557,9 @@ find_domain_by_object_name_ex(struct sss_domain_info *domain,
5fca41
 bool subdomain_enumerates(struct sss_domain_info *parent,
5fca41
                           const char *sd_name);
5fca41
 
5fca41
+char *subdomain_create_conf_path_from_str(TALLOC_CTX *mem_ctx,
5fca41
+                                          const char *parent_name,
5fca41
+                                          const char *subdom_name);
5fca41
 char *subdomain_create_conf_path(TALLOC_CTX *mem_ctx,
5fca41
                                  struct sss_domain_info *subdomain);
5fca41
 
5fca41
-- 
5fca41
2.19.1
5fca41