Blame SOURCES/0026-pam-add-pam_gssapi_check_upn-option.patch

b833e0
From fffe3169bb490c4b010b168c639aa6f9b2ec0c52 Mon Sep 17 00:00:00 2001
b833e0
From: =?UTF-8?q?Pavel=20B=C5=99ezina?= <pbrezina@redhat.com>
b833e0
Date: Thu, 10 Dec 2020 22:05:30 +0100
b833e0
Subject: [PATCH 26/27] pam: add pam_gssapi_check_upn option
b833e0
b833e0
:config: Added `pam_gssapi_check_upn` to enforce authentication
b833e0
  only with principal that can be associated with target user.
b833e0
b833e0
Reviewed-by: Robbie Harwood <rharwood@redhat.com>
b833e0
Reviewed-by: Sumit Bose <sbose@redhat.com>
b833e0
---
b833e0
 src/confdb/confdb.c                  | 10 ++++++++++
b833e0
 src/confdb/confdb.h                  |  2 ++
b833e0
 src/config/SSSDConfig/sssdoptions.py |  1 +
b833e0
 src/config/SSSDConfigTest.py         |  6 ++++--
b833e0
 src/config/cfg_rules.ini             |  3 +++
b833e0
 src/config/etc/sssd.api.conf         |  2 ++
b833e0
 src/db/sysdb_subdomains.c            | 12 ++++++++++++
b833e0
 src/man/sssd.conf.5.xml              | 26 ++++++++++++++++++++++++++
b833e0
 src/responder/pam/pamsrv.c           |  9 +++++++++
b833e0
 src/responder/pam/pamsrv.h           |  1 +
b833e0
 10 files changed, 70 insertions(+), 2 deletions(-)
b833e0
b833e0
diff --git a/src/confdb/confdb.c b/src/confdb/confdb.c
b833e0
index 7f1956d6d..2881ce5da 100644
b833e0
--- a/src/confdb/confdb.c
b833e0
+++ b/src/confdb/confdb.c
b833e0
@@ -1593,6 +1593,16 @@ static int confdb_get_domain_internal(struct confdb_ctx *cdb,
b833e0
         }
b833e0
     }
b833e0
 
b833e0
+    tmp = ldb_msg_find_attr_as_string(res->msgs[0], CONFDB_PAM_GSSAPI_CHECK_UPN,
b833e0
+                                      NULL);
b833e0
+    if (tmp != NULL) {
b833e0
+        domain->gssapi_check_upn = talloc_strdup(domain, tmp);
b833e0
+        if (domain->gssapi_check_upn == NULL) {
b833e0
+            ret = ENOMEM;
b833e0
+            goto done;
b833e0
+        }
b833e0
+    }
b833e0
+
b833e0
     domain->has_views = false;
b833e0
     domain->view_name = NULL;
b833e0
 
b833e0
diff --git a/src/confdb/confdb.h b/src/confdb/confdb.h
b833e0
index 7a3bc8bb5..036f9ecad 100644
b833e0
--- a/src/confdb/confdb.h
b833e0
+++ b/src/confdb/confdb.h
b833e0
@@ -145,6 +145,7 @@
b833e0
 #define CONFDB_PAM_P11_URI "p11_uri"
b833e0
 #define CONFDB_PAM_INITGROUPS_SCHEME "pam_initgroups_scheme"
b833e0
 #define CONFDB_PAM_GSSAPI_SERVICES "pam_gssapi_services"
b833e0
+#define CONFDB_PAM_GSSAPI_CHECK_UPN "pam_gssapi_check_upn"
b833e0
 
b833e0
 /* SUDO */
b833e0
 #define CONFDB_SUDO_CONF_ENTRY "config/sudo"
b833e0
@@ -435,6 +436,7 @@ struct sss_domain_info {
b833e0
 
b833e0
     /* List of PAM services that are allowed to authenticate with GSSAPI. */
b833e0
     char **gssapi_services;
b833e0
+    char *gssapi_check_upn; /* true | false | NULL */
b833e0
 };
b833e0
 
b833e0
 /**
b833e0
diff --git a/src/config/SSSDConfig/sssdoptions.py b/src/config/SSSDConfig/sssdoptions.py
b833e0
index f59fe8d9f..5da52a937 100644
b833e0
--- a/src/config/SSSDConfig/sssdoptions.py
b833e0
+++ b/src/config/SSSDConfig/sssdoptions.py
b833e0
@@ -105,6 +105,7 @@ class SSSDOptions(object):
b833e0
         'p11_uri': _('PKCS#11 URI to restrict the selection of devices for Smartcard authentication'),
b833e0
         'pam_initgroups_scheme' : _('When shall the PAM responder force an initgroups request'),
b833e0
         'pam_gssapi_services' : _('List of PAM services that are allowed to authenticate with GSSAPI.'),
b833e0
+        'pam_gssapi_check_upn' : _('Whether to match authenticated UPN with target user'),
b833e0
 
b833e0
         # [sudo]
b833e0
         'sudo_timed': _('Whether to evaluate the time-based attributes in sudo rules'),
b833e0
diff --git a/src/config/SSSDConfigTest.py b/src/config/SSSDConfigTest.py
b833e0
index 21fffe1b6..ea4e4f6c9 100755
b833e0
--- a/src/config/SSSDConfigTest.py
b833e0
+++ b/src/config/SSSDConfigTest.py
b833e0
@@ -654,7 +654,8 @@ class SSSDConfigTestSSSDDomain(unittest.TestCase):
b833e0
             're_expression',
b833e0
             'cached_auth_timeout',
b833e0
             'auto_private_groups',
b833e0
-            'pam_gssapi_services']
b833e0
+            'pam_gssapi_services',
b833e0
+            'pam_gssapi_check_upn']
b833e0
 
b833e0
         self.assertTrue(type(options) == dict,
b833e0
                         "Options should be a dictionary")
b833e0
@@ -1032,7 +1033,8 @@ class SSSDConfigTestSSSDDomain(unittest.TestCase):
b833e0
             're_expression',
b833e0
             'cached_auth_timeout',
b833e0
             'auto_private_groups',
b833e0
-            'pam_gssapi_services']
b833e0
+            'pam_gssapi_services',
b833e0
+            'pam_gssapi_check_upn']
b833e0
 
b833e0
         self.assertTrue(type(options) == dict,
b833e0
                         "Options should be a dictionary")
b833e0
diff --git a/src/config/cfg_rules.ini b/src/config/cfg_rules.ini
b833e0
index c6dfd5648..6642c6321 100644
b833e0
--- a/src/config/cfg_rules.ini
b833e0
+++ b/src/config/cfg_rules.ini
b833e0
@@ -140,6 +140,7 @@ option = p11_wait_for_card_timeout
b833e0
 option = p11_uri
b833e0
 option = pam_initgroups_scheme
b833e0
 option = pam_gssapi_services
b833e0
+option = pam_gssapi_check_upn
b833e0
 
b833e0
 [rule/allowed_sudo_options]
b833e0
 validator = ini_allowed_options
b833e0
@@ -439,6 +440,7 @@ option = full_name_format
b833e0
 option = re_expression
b833e0
 option = auto_private_groups
b833e0
 option = pam_gssapi_services
b833e0
+option = pam_gssapi_check_upn
b833e0
 
b833e0
 #Entry cache timeouts
b833e0
 option = entry_cache_user_timeout
b833e0
@@ -834,6 +836,7 @@ option = ad_site
b833e0
 option = use_fully_qualified_names
b833e0
 option = auto_private_groups
b833e0
 option = pam_gssapi_services
b833e0
+option = pam_gssapi_check_upn
b833e0
 
b833e0
 [rule/sssd_checks]
b833e0
 validator = sssd_checks
b833e0
diff --git a/src/config/etc/sssd.api.conf b/src/config/etc/sssd.api.conf
b833e0
index f46f3c46d..d3cad7380 100644
b833e0
--- a/src/config/etc/sssd.api.conf
b833e0
+++ b/src/config/etc/sssd.api.conf
b833e0
@@ -81,6 +81,7 @@ p11_wait_for_card_timeout = int, None, false
b833e0
 p11_uri = str, None, false
b833e0
 pam_initgroups_scheme = str, None, false
b833e0
 pam_gssapi_services = str, None, false
b833e0
+pam_gssapi_check_upn = bool, None, false
b833e0
 
b833e0
 [sudo]
b833e0
 # sudo service
b833e0
@@ -201,6 +202,7 @@ full_name_format = str, None, false
b833e0
 re_expression = str, None, false
b833e0
 auto_private_groups = str, None, false
b833e0
 pam_gssapi_services = str, None, false
b833e0
+pam_gssapi_check_upn = bool, None, false
b833e0
 
b833e0
 #Entry cache timeouts
b833e0
 entry_cache_user_timeout = int, None, false
b833e0
diff --git a/src/db/sysdb_subdomains.c b/src/db/sysdb_subdomains.c
b833e0
index bfc6df0f5..03ba12164 100644
b833e0
--- a/src/db/sysdb_subdomains.c
b833e0
+++ b/src/db/sysdb_subdomains.c
b833e0
@@ -254,6 +254,18 @@ check_subdom_config_file(struct confdb_ctx *confdb,
b833e0
         goto done;
b833e0
     }
b833e0
 
b833e0
+    /* allow to set pam_gssapi_check_upn */
b833e0
+    ret = confdb_get_string(confdb, subdomain, sd_conf_path,
b833e0
+                            CONFDB_PAM_GSSAPI_CHECK_UPN,
b833e0
+                            subdomain->parent->gssapi_check_upn,
b833e0
+                            &subdomain->gssapi_check_upn);
b833e0
+    if (ret != EOK) {
b833e0
+        DEBUG(SSSDBG_OP_FAILURE,
b833e0
+              "Failed to get %s option for the subdomain: %s\n",
b833e0
+              CONFDB_PAM_GSSAPI_CHECK_UPN, subdomain->name);
b833e0
+        goto done;
b833e0
+    }
b833e0
+
b833e0
     ret = EOK;
b833e0
 done:
b833e0
     talloc_free(tmp_ctx);
b833e0
diff --git a/src/man/sssd.conf.5.xml b/src/man/sssd.conf.5.xml
b833e0
index db9dd4677..d637e2eaa 100644
b833e0
--- a/src/man/sssd.conf.5.xml
b833e0
+++ b/src/man/sssd.conf.5.xml
b833e0
@@ -1735,6 +1735,31 @@ pam_gssapi_services = sudo, sudo-i
b833e0
                         </para>
b833e0
                     </listitem>
b833e0
                 </varlistentry>
b833e0
+                <varlistentry>
b833e0
+                    <term>pam_gssapi_check_upn</term>
b833e0
+                    <listitem>
b833e0
+                        <para>
b833e0
+                            If True, SSSD will require that the Kerberos user
b833e0
+                            principal that successfully authenticated through
b833e0
+                            GSSAPI can be associated with the user who is being
b833e0
+                            authenticated. Authentication will fail if the check
b833e0
+                            fails.
b833e0
+                        </para>
b833e0
+                        <para>
b833e0
+                            If False, every user that is able to obtained
b833e0
+                            required service ticket will be authenticated.
b833e0
+                        </para>
b833e0
+                        <para>
b833e0
+                            Note: This option can also be set per-domain which
b833e0
+                            overwrites the value in [pam] section. It can also
b833e0
+                            be set for trusted domain which overwrites the value
b833e0
+                            in the domain section.
b833e0
+                        </para>
b833e0
+                        <para>
b833e0
+                            Default: True
b833e0
+                        </para>
b833e0
+                    </listitem>
b833e0
+                </varlistentry>
b833e0
             </variablelist>
b833e0
         </refsect2>
b833e0
 
b833e0
@@ -3810,6 +3835,7 @@ ldap_user_extra_attrs = phone:telephoneNumber
b833e0
             <para>ad_site,</para>
b833e0
             <para>use_fully_qualified_names</para>
b833e0
             <para>pam_gssapi_services</para>
b833e0
+            <para>pam_gssapi_check_upn</para>
b833e0
         <para>
b833e0
             For more details about these options see their individual description
b833e0
             in the manual page.
b833e0
diff --git a/src/responder/pam/pamsrv.c b/src/responder/pam/pamsrv.c
b833e0
index 0492569c7..0db2824ff 100644
b833e0
--- a/src/responder/pam/pamsrv.c
b833e0
+++ b/src/responder/pam/pamsrv.c
b833e0
@@ -348,6 +348,15 @@ static int pam_process_init(TALLOC_CTX *mem_ctx,
b833e0
         }
b833e0
     }
b833e0
 
b833e0
+    ret = confdb_get_bool(pctx->rctx->cdb, CONFDB_PAM_CONF_ENTRY,
b833e0
+                          CONFDB_PAM_GSSAPI_CHECK_UPN, true,
b833e0
+                          &pctx->gssapi_check_upn);
b833e0
+    if (ret != EOK) {
b833e0
+        DEBUG(SSSDBG_FATAL_FAILURE, "Failed to read %s [%d]: %s\n",
b833e0
+              CONFDB_PAM_GSSAPI_CHECK_UPN, ret, sss_strerror(ret));
b833e0
+        goto done;
b833e0
+    }
b833e0
+
b833e0
     /* The responder is initialized. Now tell it to the monitor. */
b833e0
     ret = sss_monitor_service_init(rctx, rctx->ev, SSS_BUS_PAM,
b833e0
                                    SSS_PAM_SBUS_SERVICE_NAME,
b833e0
diff --git a/src/responder/pam/pamsrv.h b/src/responder/pam/pamsrv.h
b833e0
index 730dee288..bf4dd75b0 100644
b833e0
--- a/src/responder/pam/pamsrv.h
b833e0
+++ b/src/responder/pam/pamsrv.h
b833e0
@@ -65,6 +65,7 @@ struct pam_ctx {
b833e0
 
b833e0
     /* List of PAM services that are allowed to authenticate with GSSAPI. */
b833e0
     char **gssapi_services;
b833e0
+    bool gssapi_check_upn;
b833e0
 };
b833e0
 
b833e0
 struct pam_auth_req {
b833e0
-- 
b833e0
2.21.3
b833e0