Blame SOURCES/0010-Set-passwordgracelimit-to-match-global-policy-on-group-pw-policies_rhbz#2115475.patch

ee765b
From 434620ee342ac4767beccec647a318bfa7743dfa Mon Sep 17 00:00:00 2001
ee765b
From: Rob Crittenden <rcritten@redhat.com>
ee765b
Date: Thu, 18 Aug 2022 08:21:58 -0400
ee765b
Subject: [PATCH] doc: Update LDAP grace period design with default values
ee765b
ee765b
New group password policies will get -1 (unlimited) on creation
ee765b
by default.
ee765b
ee765b
Existing group password policies will remain untouched and
ee765b
those created prior will be treated as no BIND allowed.
ee765b
ee765b
Fixes: https://pagure.io/freeipa/issue/9212
ee765b
ee765b
Signed-off-by: Rob Crittenden <rcritten@redhat.com>
ee765b
Reviewed-By: Florence Blanc-Renaud <frenaud@redhat.com>
ee765b
---
ee765b
 doc/designs/ldap_grace_period.md | 17 ++++++++++++++++-
ee765b
 1 file changed, 16 insertions(+), 1 deletion(-)
ee765b
ee765b
diff --git a/doc/designs/ldap_grace_period.md b/doc/designs/ldap_grace_period.md
ee765b
index 4b9db3424..e26aedda9 100644
ee765b
--- a/doc/designs/ldap_grace_period.md
ee765b
+++ b/doc/designs/ldap_grace_period.md
ee765b
@@ -51,7 +51,22 @@ The basic flow is:
ee765b
 
ee765b
 On successful password reset (by anyone) reset the user's passwordGraceUserTime to 0.
ee765b
 
ee765b
-The default value on install/upgrade will be -1 to retail existing behavior.
ee765b
+Range values for passwordgracelimit are:
ee765b
+
ee765b
+-1 : password grace checking is disabled
ee765b
+ 0 : no grace BIND are allowed at all post-expiration
ee765b
+ 1..MAXINT: the number of BIND allowed post-expiration
ee765b
+
ee765b
+The default value for the global policy on install/upgrade will be -1 to
ee765b
+retain existing behavior.
ee765b
+
ee765b
+New group password policies will default to -1 to retain previous
ee765b
+behavior.
ee765b
+
ee765b
+Existing group policies with no grace limit set are updated to use
ee765b
+the default unlimited value, -1. This is done because lack of value in
ee765b
+LDAP is treated as 0 so any existing group policies would not allow
ee765b
+post-expiration BIND so this will avoid confusion.
ee765b
 
ee765b
 The per-user attempts will not be replicated.
ee765b
 
ee765b
-- 
ee765b
2.37.2
ee765b
ee765b
From 497a57e7a6872fa30d1855a1d91a455bfdbf9300 Mon Sep 17 00:00:00 2001
ee765b
From: Rob Crittenden <rcritten@redhat.com>
ee765b
Date: Thu, 4 Aug 2022 12:04:22 -0400
ee765b
Subject: [PATCH] Set default gracelimit on group password policies to -1
ee765b
ee765b
This will retain previous behavior of unlimited LDAP BIND
ee765b
post-expiration.
ee765b
ee765b
Fixes: https://pagure.io/freeipa/issue/9212
ee765b
ee765b
Signed-off-by: Rob Crittenden <rcritten@redhat.com>
ee765b
Reviewed-By: Florence Blanc-Renaud <frenaud@redhat.com>
ee765b
---
ee765b
 API.txt                                      | 2 +-
ee765b
 ipaserver/plugins/pwpolicy.py                | 2 ++
ee765b
 ipatests/test_xmlrpc/test_pwpolicy_plugin.py | 2 ++
ee765b
 3 files changed, 5 insertions(+), 1 deletion(-)
ee765b
ee765b
diff --git a/API.txt b/API.txt
ee765b
index 5ba9add13..d7ea74f08 100644
ee765b
--- a/API.txt
ee765b
+++ b/API.txt
ee765b
@@ -4075,7 +4075,7 @@ option: Int('krbpwdlockoutduration?', cli_name='lockouttime')
ee765b
 option: Int('krbpwdmaxfailure?', cli_name='maxfail')
ee765b
 option: Int('krbpwdmindiffchars?', cli_name='minclasses')
ee765b
 option: Int('krbpwdminlength?', cli_name='minlength')
ee765b
-option: Int('passwordgracelimit?', cli_name='gracelimit', default=-1)
ee765b
+option: Int('passwordgracelimit?', autofill=True, cli_name='gracelimit', default=-1)
ee765b
 option: Flag('raw', autofill=True, cli_name='raw', default=False)
ee765b
 option: Str('setattr*', cli_name='setattr')
ee765b
 option: Str('version?')
ee765b
diff --git a/ipaserver/plugins/pwpolicy.py b/ipaserver/plugins/pwpolicy.py
ee765b
index 4428aede2..f4ebffd5c 100644
ee765b
--- a/ipaserver/plugins/pwpolicy.py
ee765b
+++ b/ipaserver/plugins/pwpolicy.py
ee765b
@@ -408,6 +408,7 @@ class pwpolicy(LDAPObject):
ee765b
             minvalue=-1,
ee765b
             maxvalue=Int.MAX_UINT32,
ee765b
             default=-1,
ee765b
+            autofill=True,
ee765b
         ),
ee765b
     )
ee765b
 
ee765b
@@ -539,6 +540,7 @@ class pwpolicy_add(LDAPCreate):
ee765b
             keys[-1], krbpwdpolicyreference=dn,
ee765b
             cospriority=options.get('cospriority')
ee765b
         )
ee765b
+
ee765b
         return dn
ee765b
 
ee765b
     def post_callback(self, ldap, dn, entry_attrs, *keys, **options):
ee765b
diff --git a/ipatests/test_xmlrpc/test_pwpolicy_plugin.py b/ipatests/test_xmlrpc/test_pwpolicy_plugin.py
ee765b
index 8eee69c18..fc785223b 100644
ee765b
--- a/ipatests/test_xmlrpc/test_pwpolicy_plugin.py
ee765b
+++ b/ipatests/test_xmlrpc/test_pwpolicy_plugin.py
ee765b
@@ -387,6 +387,7 @@ class test_pwpolicy_mod_cospriority(Declarative):
ee765b
                     krbpwdhistorylength=[u'10'],
ee765b
                     krbpwdmindiffchars=[u'3'],
ee765b
                     krbpwdminlength=[u'8'],
ee765b
+                    passwordgracelimit=[u'-1'],
ee765b
                     objectclass=objectclasses.pwpolicy,
ee765b
                 ),
ee765b
                 summary=None,
ee765b
@@ -417,6 +418,7 @@ class test_pwpolicy_mod_cospriority(Declarative):
ee765b
                     krbpwdhistorylength=[u'10'],
ee765b
                     krbpwdmindiffchars=[u'3'],
ee765b
                     krbpwdminlength=[u'8'],
ee765b
+                    passwordgracelimit=[u'-1'],
ee765b
                 ),
ee765b
                 summary=None,
ee765b
                 value=u'ipausers',
ee765b
-- 
ee765b
2.37.2
ee765b
ee765b
From a4ddaaf3048c4e8d78a1807af7266ee40ab3a30b Mon Sep 17 00:00:00 2001
ee765b
From: Rob Crittenden <rcritten@redhat.com>
ee765b
Date: Thu, 4 Aug 2022 12:04:41 -0400
ee765b
Subject: [PATCH] Set default on group pwpolicy with no grace limit in upgrade
ee765b
ee765b
If an existing group policy lacks a password grace limit
ee765b
update it to -1 on upgrade.
ee765b
ee765b
Fixes: https://pagure.io/freeipa/issue/9212
ee765b
ee765b
Signed-off-by: Rob Crittenden <rcritten@redhat.com>
ee765b
Reviewed-By: Florence Blanc-Renaud <frenaud@redhat.com>
ee765b
---
ee765b
 .../updates/90-post_upgrade_plugins.update    |  1 +
ee765b
 ipaserver/install/plugins/update_pwpolicy.py  | 66 +++++++++++++++++++
ee765b
 2 files changed, 67 insertions(+)
ee765b
ee765b
diff --git a/install/updates/90-post_upgrade_plugins.update b/install/updates/90-post_upgrade_plugins.update
ee765b
index c7ec71d49..6fe91aa6c 100644
ee765b
--- a/install/updates/90-post_upgrade_plugins.update
ee765b
+++ b/install/updates/90-post_upgrade_plugins.update
ee765b
@@ -26,6 +26,7 @@ plugin: update_ra_cert_store
ee765b
 plugin: update_mapping_Guests_to_nobody
ee765b
 plugin: fix_kra_people_entry
ee765b
 plugin: update_pwpolicy
ee765b
+plugin: update_pwpolicy_grace
ee765b
 
ee765b
 # last
ee765b
 # DNS version 1
ee765b
diff --git a/ipaserver/install/plugins/update_pwpolicy.py b/ipaserver/install/plugins/update_pwpolicy.py
ee765b
index dca44ce43..4185f0343 100644
ee765b
--- a/ipaserver/install/plugins/update_pwpolicy.py
ee765b
+++ b/ipaserver/install/plugins/update_pwpolicy.py
ee765b
@@ -78,3 +78,69 @@ class update_pwpolicy(Updater):
ee765b
                 return False, []
ee765b
 
ee765b
         return False, []
ee765b
+
ee765b
+
ee765b
+@register()
ee765b
+class update_pwpolicy_grace(Updater):
ee765b
+    """
ee765b
+    Ensure all group policies have a grace period set.
ee765b
+    """
ee765b
+
ee765b
+    def execute(self, **options):
ee765b
+        ldap = self.api.Backend.ldap2
ee765b
+
ee765b
+        base_dn = DN(('cn', self.api.env.realm), ('cn', 'kerberos'),
ee765b
+                     self.api.env.basedn)
ee765b
+        search_filter = (
ee765b
+            "(&(objectClass=krbpwdpolicy)(!(passwordgracelimit=*)))"
ee765b
+        )
ee765b
+
ee765b
+        while True:
ee765b
+            # Run the search in loop to avoid issues when LDAP limits are hit
ee765b
+            # during update
ee765b
+
ee765b
+            try:
ee765b
+                (entries, truncated) = ldap.find_entries(
ee765b
+                    search_filter, ['objectclass'], base_dn, time_limit=0,
ee765b
+                    size_limit=0)
ee765b
+
ee765b
+            except errors.EmptyResult:
ee765b
+                logger.debug("update_pwpolicy: no policies without "
ee765b
+                             "passwordgracelimit set")
ee765b
+                return False, []
ee765b
+
ee765b
+            except errors.ExecutionError as e:
ee765b
+                logger.error("update_pwpolicy: cannot retrieve list "
ee765b
+                             "of policies missing passwordgracelimit: %s", e)
ee765b
+                return False, []
ee765b
+
ee765b
+            logger.debug("update_pwpolicy: found %d "
ee765b
+                         "policies to update, truncated: %s",
ee765b
+                         len(entries), truncated)
ee765b
+
ee765b
+            error = False
ee765b
+
ee765b
+            for entry in entries:
ee765b
+                # Set unlimited BIND by default
ee765b
+                entry['passwordgracelimit'] = -1
ee765b
+                try:
ee765b
+                    ldap.update_entry(entry)
ee765b
+                except (errors.EmptyModlist, errors.NotFound):
ee765b
+                    pass
ee765b
+                except errors.ExecutionError as e:
ee765b
+                    logger.debug("update_pwpolicy: cannot "
ee765b
+                                 "update policy: %s", e)
ee765b
+                    error = True
ee765b
+
ee765b
+            if error:
ee765b
+                # Exit loop to avoid infinite cycles
ee765b
+                logger.error("update_pwpolicy: error(s) "
ee765b
+                             "detected during pwpolicy update")
ee765b
+                return False, []
ee765b
+
ee765b
+            elif not truncated:
ee765b
+                # All affected entries updated, exit the loop
ee765b
+                logger.debug("update_pwpolicy: all policies updated")
ee765b
+                return False, []
ee765b
+
ee765b
+        return False, []
ee765b
-- 
ee765b
2.37.2
ee765b