Blame SOURCES/0003-GPO-Add-option-ad_gpo_ignore_unreadable.patch

5cd47f
From ad058011b6b75b15c674be46a3ae9b3cc5228175 Mon Sep 17 00:00:00 2001
5cd47f
From: =?UTF-8?q?Michal=20=C5=BDidek?= <mzidek@redhat.com>
5cd47f
Date: Wed, 17 Oct 2018 16:57:20 +0200
5cd47f
Subject: [PATCH] GPO: Add option ad_gpo_ignore_unreadable
5cd47f
5cd47f
Add option to ignore group policy containers in AD
5cd47f
with unreadable or missing attributes. This is
5cd47f
for the case when server contains GPOs that
5cd47f
have very strict permissions on their attributes
5cd47f
in AD but are unrelated to access control.
5cd47f
5cd47f
Rather then using this option it is better to
5cd47f
change the permissions on the AD objects but
5cd47f
that may not be always possible (company policy,
5cd47f
not access to server etc.).
5cd47f
5cd47f
Resolves:
5cd47f
https://pagure.io/SSSD/sssd/issue/3867
5cd47f
CVE-2018-16838
5cd47f
5cd47f
Reviewed-by: Jakub Hrozek <jhrozek@redhat.com>
5cd47f
(cherry picked from commit 2f27dd9f05c2d3ed1c190ba387bc97738988efb0)
5cd47f
---
5cd47f
 src/config/cfg_rules.ini     |  1 +
5cd47f
 src/man/sssd-ad.5.xml        | 19 ++++++++++
5cd47f
 src/providers/ad/ad_common.h |  1 +
5cd47f
 src/providers/ad/ad_gpo.c    | 67 +++++++++++++++++++++++++++++++++---
5cd47f
 src/providers/ad/ad_opts.c   |  1 +
5cd47f
 5 files changed, 85 insertions(+), 4 deletions(-)
5cd47f
5cd47f
diff --git a/src/config/cfg_rules.ini b/src/config/cfg_rules.ini
5cd47f
index 887428437..603211711 100644
5cd47f
--- a/src/config/cfg_rules.ini
5cd47f
+++ b/src/config/cfg_rules.ini
5cd47f
@@ -439,6 +439,7 @@ option = ad_enabled_domains
5cd47f
 option = ad_enable_gc
5cd47f
 option = ad_gpo_access_control
5cd47f
 option = ad_gpo_implicit_deny
5cd47f
+option = ad_gpo_ignore_unreadable
5cd47f
 option = ad_gpo_cache_timeout
5cd47f
 option = ad_gpo_default_right
5cd47f
 option = ad_gpo_map_batch
5cd47f
diff --git a/src/man/sssd-ad.5.xml b/src/man/sssd-ad.5.xml
5cd47f
index f9b7f7667..b14f07f7f 100644
5cd47f
--- a/src/man/sssd-ad.5.xml
5cd47f
+++ b/src/man/sssd-ad.5.xml
5cd47f
@@ -437,6 +437,25 @@ DOM:dom1:(memberOf:1.2.840.113556.1.4.1941:=cn=nestedgroup,ou=groups,dc=example,
5cd47f
                     </listitem>
5cd47f
                 </varlistentry>
5cd47f
 
5cd47f
+                <varlistentry>
5cd47f
+                    <term>ad_gpo_ignore_unreadable (boolean)</term>
5cd47f
+                    <listitem>
5cd47f
+                        <para>
5cd47f
+                            Normally when some group policy containers (AD
5cd47f
+                            object) of applicable group policy objects are
5cd47f
+                            not readable by SSSD then users are denied access.
5cd47f
+                            This option allows to ignore group policy
5cd47f
+                            containers and with them associated policies
5cd47f
+                            if their attributes in group policy containers
5cd47f
+                            are not readable for SSSD.
5cd47f
+                        </para>
5cd47f
+                        <para>
5cd47f
+                            Default: False
5cd47f
+                        </para>
5cd47f
+                    </listitem>
5cd47f
+                </varlistentry>
5cd47f
+
5cd47f
+
5cd47f
 
5cd47f
                 <varlistentry>
5cd47f
                     <term>ad_gpo_cache_timeout (integer)</term>
5cd47f
diff --git a/src/providers/ad/ad_common.h b/src/providers/ad/ad_common.h
5cd47f
index 2c52c997a..529753a8a 100644
5cd47f
--- a/src/providers/ad/ad_common.h
5cd47f
+++ b/src/providers/ad/ad_common.h
5cd47f
@@ -53,6 +53,7 @@ enum ad_basic_opt {
5cd47f
     AD_ENABLE_GC,
5cd47f
     AD_GPO_ACCESS_CONTROL,
5cd47f
     AD_GPO_IMPLICIT_DENY,
5cd47f
+    AD_GPO_IGNORE_UNREADABLE,
5cd47f
     AD_GPO_CACHE_TIMEOUT,
5cd47f
     AD_GPO_MAP_INTERACTIVE,
5cd47f
     AD_GPO_MAP_REMOTE_INTERACTIVE,
5cd47f
diff --git a/src/providers/ad/ad_gpo.c b/src/providers/ad/ad_gpo.c
5cd47f
index 3b472e0e9..5f85910a9 100644
5cd47f
--- a/src/providers/ad/ad_gpo.c
5cd47f
+++ b/src/providers/ad/ad_gpo.c
5cd47f
@@ -3603,6 +3603,7 @@ struct ad_gpo_process_gpo_state {
5cd47f
     struct ad_access_ctx *access_ctx;
5cd47f
     struct tevent_context *ev;
5cd47f
     struct sdap_id_op *sdap_op;
5cd47f
+    struct dp_option *ad_options;
5cd47f
     struct sdap_options *opts;
5cd47f
     char *server_hostname;
5cd47f
     struct sss_domain_info *host_domain;
5cd47f
@@ -3647,6 +3648,7 @@ ad_gpo_process_gpo_send(TALLOC_CTX *mem_ctx,
5cd47f
 
5cd47f
     state->ev = ev;
5cd47f
     state->sdap_op = sdap_op;
5cd47f
+    state->ad_options = access_ctx->ad_options;
5cd47f
     state->opts = opts;
5cd47f
     state->server_hostname = server_hostname;
5cd47f
     state->host_domain = host_domain;
5cd47f
@@ -3871,6 +3873,54 @@ static bool machine_ext_names_is_blank(char *attr_value)
5cd47f
     return true;
5cd47f
 }
5cd47f
 
5cd47f
+static errno_t
5cd47f
+ad_gpo_missing_or_unreadable_attr(struct ad_gpo_process_gpo_state *state,
5cd47f
+                                  struct tevent_req *req)
5cd47f
+{
5cd47f
+    bool ignore_unreadable = dp_opt_get_bool(state->ad_options,
5cd47f
+                                             AD_GPO_IGNORE_UNREADABLE);
5cd47f
+
5cd47f
+    if (ignore_unreadable) {
5cd47f
+        /* If admins decided to skip GPOs with unreadable
5cd47f
+         * attributes just log the SID of skipped GPO */
5cd47f
+        DEBUG(SSSDBG_TRACE_FUNC,
5cd47f
+              "Group Policy Container with DN [%s] has unreadable or missing "
5cd47f
+              "attributes -> skipping this GPO "
5cd47f
+              "(ad_gpo_ignore_unreadable = True)\n",
5cd47f
+              state->candidate_gpos[state->gpo_index]->gpo_dn);
5cd47f
+        state->gpo_index++;
5cd47f
+        return ad_gpo_get_gpo_attrs_step(req);
5cd47f
+    } else {
5cd47f
+        /* Inform in logs and syslog that this GPO can
5cd47f
+         * not be processed due to unreadable or missing
5cd47f
+         * attributes and point to possible server side
5cd47f
+         * and client side solutions. */
5cd47f
+        DEBUG(SSSDBG_CRIT_FAILURE,
5cd47f
+              "Group Policy Container with DN [%s] is unreadable or has "
5cd47f
+              "unreadable or missing attributes. In order to fix this "
5cd47f
+              "make sure that this AD object has following attributes "
5cd47f
+              "readable: nTSecurityDescriptor, cn, gPCFileSysPath, "
5cd47f
+              "gPCMachineExtensionNames, gPCFunctionalityVersion, flags. "
5cd47f
+              "Alternatively if you do not have access to the server or can "
5cd47f
+              "not change permissions on this object, you can use option "
5cd47f
+              "ad_gpo_ignore_unreadable = True which will skip this GPO."
5cd47f
+              "See 'man ad_gpo_ignore_unreadable for details.'\n",
5cd47f
+              state->candidate_gpos[state->gpo_index]->gpo_dn);
5cd47f
+        sss_log(SSSDBG_CRIT_FAILURE,
5cd47f
+                "Group Policy Container with DN [%s] is unreadable or has "
5cd47f
+                "unreadable or missing attributes. In order to fix this "
5cd47f
+                "make sure that this AD object has following attributes "
5cd47f
+                "readable: nTSecurityDescriptor, cn, gPCFileSysPath, "
5cd47f
+                "gPCMachineExtensionNames, gPCFunctionalityVersion, flags. "
5cd47f
+                "Alternatively if you do not have access to the server or can "
5cd47f
+                "not change permissions on this object, you can use option "
5cd47f
+                "ad_gpo_ignore_unreadable = True which will skip this GPO."
5cd47f
+                "See 'man ad_gpo_ignore_unreadable for details.'\n",
5cd47f
+                state->candidate_gpos[state->gpo_index]->gpo_dn);
5cd47f
+        return EFAULT;
5cd47f
+    }
5cd47f
+}
5cd47f
+
5cd47f
 static errno_t
5cd47f
 ad_gpo_sd_process_attrs(struct tevent_req *req,
5cd47f
                         char *smb_host,
5cd47f
@@ -3890,7 +3940,10 @@ ad_gpo_sd_process_attrs(struct tevent_req *req,
5cd47f
 
5cd47f
     /* retrieve AD_AT_CN */
5cd47f
     ret = sysdb_attrs_get_string(result, AD_AT_CN, &gpo_guid);
5cd47f
-    if (ret != EOK) {
5cd47f
+    if (ret == ENOENT) {
5cd47f
+        ret = ad_gpo_missing_or_unreadable_attr(state, req);
5cd47f
+        goto done;
5cd47f
+    } else if (ret != EOK) {
5cd47f
         DEBUG(SSSDBG_OP_FAILURE,
5cd47f
               "sysdb_attrs_get_string failed: [%d](%s)\n",
5cd47f
               ret, sss_strerror(ret));
5cd47f
@@ -3911,7 +3964,10 @@ ad_gpo_sd_process_attrs(struct tevent_req *req,
5cd47f
                                  AD_AT_FILE_SYS_PATH,
5cd47f
                                  &raw_file_sys_path);
5cd47f
 
5cd47f
-    if (ret != EOK) {
5cd47f
+    if (ret == ENOENT) {
5cd47f
+        ret = ad_gpo_missing_or_unreadable_attr(state, req);
5cd47f
+        goto done;
5cd47f
+    } else if (ret != EOK) {
5cd47f
         DEBUG(SSSDBG_OP_FAILURE,
5cd47f
               "sysdb_attrs_get_string failed: [%d](%s)\n",
5cd47f
               ret, sss_strerror(ret));
5cd47f
@@ -3959,7 +4015,10 @@ ad_gpo_sd_process_attrs(struct tevent_req *req,
5cd47f
     /* retrieve AD_AT_FLAGS */
5cd47f
     ret = sysdb_attrs_get_int32_t(result, AD_AT_FLAGS,
5cd47f
                                   &gp_gpo->gpo_flags);
5cd47f
-    if (ret != EOK) {
5cd47f
+    if (ret == ENOENT) {
5cd47f
+        ret = ad_gpo_missing_or_unreadable_attr(state, req);
5cd47f
+        goto done;
5cd47f
+    } else if (ret != EOK) {
5cd47f
         DEBUG(SSSDBG_OP_FAILURE,
5cd47f
               "sysdb_attrs_get_int32_t failed: [%d](%s)\n",
5cd47f
               ret, sss_strerror(ret));
5cd47f
@@ -3977,7 +4036,7 @@ ad_gpo_sd_process_attrs(struct tevent_req *req,
5cd47f
     if ((ret == ENOENT) || (el->num_values == 0)) {
5cd47f
         DEBUG(SSSDBG_OP_FAILURE,
5cd47f
               "nt_sec_desc attribute not found or has no value\n");
5cd47f
-        ret = ENOENT;
5cd47f
+        ret = ad_gpo_missing_or_unreadable_attr(state, req);
5cd47f
         goto done;
5cd47f
     }
5cd47f
 
5cd47f
diff --git a/src/providers/ad/ad_opts.c b/src/providers/ad/ad_opts.c
5cd47f
index b274ba9b3..c408295f3 100644
5cd47f
--- a/src/providers/ad/ad_opts.c
5cd47f
+++ b/src/providers/ad/ad_opts.c
5cd47f
@@ -39,6 +39,7 @@ struct dp_option ad_basic_opts[] = {
5cd47f
     { "ad_enable_gc", DP_OPT_BOOL, BOOL_TRUE, BOOL_TRUE },
5cd47f
     { "ad_gpo_access_control", DP_OPT_STRING, { AD_GPO_ACCESS_MODE_DEFAULT }, NULL_STRING },
5cd47f
     { "ad_gpo_implicit_deny", DP_OPT_BOOL, BOOL_FALSE, BOOL_FALSE },
5cd47f
+    { "ad_gpo_ignore_unreadable", DP_OPT_BOOL, BOOL_FALSE, BOOL_FALSE },
5cd47f
     { "ad_gpo_cache_timeout", DP_OPT_NUMBER, { .number = 5 }, NULL_NUMBER },
5cd47f
     { "ad_gpo_map_interactive", DP_OPT_STRING, NULL_STRING, NULL_STRING },
5cd47f
     { "ad_gpo_map_remote_interactive", DP_OPT_STRING, NULL_STRING, NULL_STRING },
5cd47f
-- 
5cd47f
2.19.1
5cd47f