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

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