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

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