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

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