|
|
8e1ca3 |
From 1bb4ff9ed2313fb3c2bd1418258c5bcec557b6a5 Mon Sep 17 00:00:00 2001
|
|
|
8e1ca3 |
From: Rob Crittenden <rcritten@redhat.com>
|
|
|
8e1ca3 |
Date: Thu, 21 Jul 2022 09:28:46 -0400
|
|
|
8e1ca3 |
Subject: [PATCH] Disabling gracelimit does not prevent LDAP binds
|
|
|
8e1ca3 |
|
|
|
8e1ca3 |
Originally the code treated 0 as disabled. This was
|
|
|
8e1ca3 |
changed during the review process to -1 but one remnant
|
|
|
8e1ca3 |
was missed effetively allowing gracelimit 0 to also mean
|
|
|
8e1ca3 |
disabled.
|
|
|
8e1ca3 |
|
|
|
8e1ca3 |
Add explicit tests for testing with gracelimit = 0 and
|
|
|
8e1ca3 |
gracelimit = -1.
|
|
|
8e1ca3 |
|
|
|
8e1ca3 |
Also remove some extranous "str(self.master.domain.basedn)"
|
|
|
8e1ca3 |
lines from some of the tests.
|
|
|
8e1ca3 |
|
|
|
8e1ca3 |
Fixes: https://pagure.io/freeipa/issue/9206
|
|
|
8e1ca3 |
|
|
|
8e1ca3 |
Signed-off-by: Rob Crittenden <rcritten@redhat.com>
|
|
|
8e1ca3 |
Reviewed-By: Francisco Trivino <ftrivino@redhat.com>
|
|
|
8e1ca3 |
---
|
|
|
8e1ca3 |
.../ipa-graceperiod/ipa_graceperiod.c | 2 +-
|
|
|
8e1ca3 |
ipatests/test_integration/test_pwpolicy.py | 55 ++++++++++++++++++-
|
|
|
8e1ca3 |
2 files changed, 53 insertions(+), 4 deletions(-)
|
|
|
8e1ca3 |
|
|
|
8e1ca3 |
diff --git a/daemons/ipa-slapi-plugins/ipa-graceperiod/ipa_graceperiod.c b/daemons/ipa-slapi-plugins/ipa-graceperiod/ipa_graceperiod.c
|
|
|
8e1ca3 |
index a3f57cb4bd7a2a66d70fae98cca0f62a8f0c017f..345e1dee7d163167373ca82dedb1e827f0e1bc8c 100644
|
|
|
8e1ca3 |
--- a/daemons/ipa-slapi-plugins/ipa-graceperiod/ipa_graceperiod.c
|
|
|
8e1ca3 |
+++ b/daemons/ipa-slapi-plugins/ipa-graceperiod/ipa_graceperiod.c
|
|
|
8e1ca3 |
@@ -479,7 +479,7 @@ static int ipagraceperiod_preop(Slapi_PBlock *pb)
|
|
|
8e1ca3 |
if (pwresponse_requested) {
|
|
|
8e1ca3 |
slapi_pwpolicy_make_response_control(pb, -1, grace_limit - grace_user_time , -1);
|
|
|
8e1ca3 |
}
|
|
|
8e1ca3 |
- } else if ((grace_limit > 0) && (grace_user_time >= grace_limit)) {
|
|
|
8e1ca3 |
+ } else if (grace_user_time >= grace_limit) {
|
|
|
8e1ca3 |
LOG_TRACE("%s password is expired and out of grace limit\n", dn);
|
|
|
8e1ca3 |
errstr = "Password is expired.\n";
|
|
|
8e1ca3 |
ret = LDAP_INVALID_CREDENTIALS;
|
|
|
8e1ca3 |
diff --git a/ipatests/test_integration/test_pwpolicy.py b/ipatests/test_integration/test_pwpolicy.py
|
|
|
8e1ca3 |
index 6d66982848ac5a0061b47d30fad022be055c93e4..41d6e9070a90c2bde7b3182ad6ecf1a923bba203 100644
|
|
|
8e1ca3 |
--- a/ipatests/test_integration/test_pwpolicy.py
|
|
|
8e1ca3 |
+++ b/ipatests/test_integration/test_pwpolicy.py
|
|
|
8e1ca3 |
@@ -36,7 +36,7 @@ class TestPWPolicy(IntegrationTest):
|
|
|
8e1ca3 |
cls.master.run_command(['ipa', 'group-add-member', POLICY,
|
|
|
8e1ca3 |
'--users', USER])
|
|
|
8e1ca3 |
cls.master.run_command(['ipa', 'pwpolicy-add', POLICY,
|
|
|
8e1ca3 |
- '--priority', '1'])
|
|
|
8e1ca3 |
+ '--priority', '1', '--gracelimit', '-1'])
|
|
|
8e1ca3 |
cls.master.run_command(['ipa', 'passwd', USER],
|
|
|
8e1ca3 |
stdin_text='{password}\n{password}\n'.format(
|
|
|
8e1ca3 |
password=PASSWORD
|
|
|
8e1ca3 |
@@ -265,7 +265,6 @@ class TestPWPolicy(IntegrationTest):
|
|
|
8e1ca3 |
|
|
|
8e1ca3 |
def test_graceperiod_expired(self):
|
|
|
8e1ca3 |
"""Test the LDAP bind grace period"""
|
|
|
8e1ca3 |
- str(self.master.domain.basedn)
|
|
|
8e1ca3 |
dn = "uid={user},cn=users,cn=accounts,{base_dn}".format(
|
|
|
8e1ca3 |
user=USER, base_dn=str(self.master.domain.basedn))
|
|
|
8e1ca3 |
|
|
|
8e1ca3 |
@@ -308,7 +307,6 @@ class TestPWPolicy(IntegrationTest):
|
|
|
8e1ca3 |
|
|
|
8e1ca3 |
def test_graceperiod_not_replicated(self):
|
|
|
8e1ca3 |
"""Test that the grace period is reset on password reset"""
|
|
|
8e1ca3 |
- str(self.master.domain.basedn)
|
|
|
8e1ca3 |
dn = "uid={user},cn=users,cn=accounts,{base_dn}".format(
|
|
|
8e1ca3 |
user=USER, base_dn=str(self.master.domain.basedn))
|
|
|
8e1ca3 |
|
|
|
8e1ca3 |
@@ -341,3 +339,54 @@ class TestPWPolicy(IntegrationTest):
|
|
|
8e1ca3 |
)
|
|
|
8e1ca3 |
assert 'passwordgraceusertime: 0' in result.stdout_text.lower()
|
|
|
8e1ca3 |
self.reset_password(self.master)
|
|
|
8e1ca3 |
+
|
|
|
8e1ca3 |
+ def test_graceperiod_zero(self):
|
|
|
8e1ca3 |
+ """Test the LDAP bind with zero grace period"""
|
|
|
8e1ca3 |
+ dn = "uid={user},cn=users,cn=accounts,{base_dn}".format(
|
|
|
8e1ca3 |
+ user=USER, base_dn=str(self.master.domain.basedn))
|
|
|
8e1ca3 |
+
|
|
|
8e1ca3 |
+ self.master.run_command(
|
|
|
8e1ca3 |
+ ["ipa", "pwpolicy-mod", POLICY, "--gracelimit", "0", ],
|
|
|
8e1ca3 |
+ )
|
|
|
8e1ca3 |
+
|
|
|
8e1ca3 |
+ # Resetting the password will mark it as expired
|
|
|
8e1ca3 |
+ self.reset_password(self.master)
|
|
|
8e1ca3 |
+
|
|
|
8e1ca3 |
+ # Now grace is done and binds should fail.
|
|
|
8e1ca3 |
+ result = self.master.run_command(
|
|
|
8e1ca3 |
+ ["ldapsearch", "-e", "ppolicy", "-D", dn,
|
|
|
8e1ca3 |
+ "-w", PASSWORD, "-b", dn], raiseonerr=False
|
|
|
8e1ca3 |
+ )
|
|
|
8e1ca3 |
+ assert result.returncode == 49
|
|
|
8e1ca3 |
+
|
|
|
8e1ca3 |
+ assert 'Password is expired' in result.stderr_text
|
|
|
8e1ca3 |
+ assert 'Password expired, 0 grace logins remain' in result.stderr_text
|
|
|
8e1ca3 |
+
|
|
|
8e1ca3 |
+ def test_graceperiod_disabled(self):
|
|
|
8e1ca3 |
+ """Test the LDAP bind with grace period disabled (-1)"""
|
|
|
8e1ca3 |
+ str(self.master.domain.basedn)
|
|
|
8e1ca3 |
+ dn = "uid={user},cn=users,cn=accounts,{base_dn}".format(
|
|
|
8e1ca3 |
+ user=USER, base_dn=str(self.master.domain.basedn))
|
|
|
8e1ca3 |
+
|
|
|
8e1ca3 |
+ # This can fail if gracelimit is already -1 so ignore it
|
|
|
8e1ca3 |
+ self.master.run_command(
|
|
|
8e1ca3 |
+ ["ipa", "pwpolicy-mod", POLICY, "--gracelimit", "-1",],
|
|
|
8e1ca3 |
+ raiseonerr=False,
|
|
|
8e1ca3 |
+ )
|
|
|
8e1ca3 |
+
|
|
|
8e1ca3 |
+ # Ensure the password is expired
|
|
|
8e1ca3 |
+ self.reset_password(self.master)
|
|
|
8e1ca3 |
+
|
|
|
8e1ca3 |
+ result = self.kinit_as_user(self.master, PASSWORD, PASSWORD)
|
|
|
8e1ca3 |
+
|
|
|
8e1ca3 |
+ for _i in range(0, 10):
|
|
|
8e1ca3 |
+ result = self.master.run_command(
|
|
|
8e1ca3 |
+ ["ldapsearch", "-e", "ppolicy", "-D", dn,
|
|
|
8e1ca3 |
+ "-w", PASSWORD, "-b", dn]
|
|
|
8e1ca3 |
+ )
|
|
|
8e1ca3 |
+
|
|
|
8e1ca3 |
+ # With graceperiod disabled it should not increment
|
|
|
8e1ca3 |
+ result = tasks.ldapsearch_dm(
|
|
|
8e1ca3 |
+ self.master, dn, ['passwordgraceusertime',],
|
|
|
8e1ca3 |
+ )
|
|
|
8e1ca3 |
+ assert 'passwordgraceusertime: 0' in result.stdout_text.lower()
|
|
|
8e1ca3 |
--
|
|
|
8e1ca3 |
2.37.2
|
|
|
8e1ca3 |
|