Skip to content

Commit 4015073

Browse files
committed
ipahbacrule: Fix handling of hbacsvcgroup in members
FreeIPA provides a default hbacsvcgroup named "Sudo", with capital S, that is different from every other hbacsvcgroup, which are all represented by lower case letters. As data from IPA API was not modified, this causes an idempotence error when using different capitalization with the 'hbacsvcgroup' parameter. This patch fixes the issue by using the CaseInsensitive comparator to create the hbacsvcgroup list. Tests were update to make sure a regression is not included in the future.
1 parent de1883f commit 4015073

File tree

2 files changed

+45
-3
lines changed

2 files changed

+45
-3
lines changed

plugins/modules/ipahbacrule.py

Lines changed: 4 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -171,7 +171,7 @@
171171

172172
from ansible.module_utils.ansible_freeipa_module import \
173173
IPAAnsibleModule, compare_args_ipa, gen_add_del_lists, gen_add_list, \
174-
gen_intersection_list, ListOf, Hostname
174+
gen_intersection_list, ListOf, Hostname, CaseInsensitive
175175

176176

177177
def find_hbacrule(module, name):
@@ -398,7 +398,9 @@ def main():
398398

399399
if hbacsvc is not None:
400400
hbacsvc_add, hbacsvc_del = gen_add_del_lists(
401-
hbacsvc, res_find.get("memberservice_hbacsvc"))
401+
hbacsvc, res_find.get("memberservice_hbacsvc"),
402+
attr_datatype=CaseInsensitive()
403+
)
402404

403405
if hbacsvcgroup is not None:
404406
hbacsvcgroup_add, hbacsvcgroup_del = gen_add_del_lists(

tests/hbacrule/test_hbacrule_member_case_insensitive.yml

Lines changed: 41 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -468,11 +468,51 @@
468468
register: result
469469
failed_when: result.changed or result.failed
470470

471+
# Specifically test 'Sudo' and FreeIPA adds a "Sudo" hbacsvcgroup instead of "sudo"
472+
- name: Ensure 'sudo' works as hbacsvcgroup.
473+
ipahbacrule:
474+
ipaadmin_password: SomeADMINpassword
475+
name: "test_sudo"
476+
hbacsvcgroup:
477+
- sudo
478+
register: result
479+
failed_when: not result.changed or result.failed
480+
481+
- name: Ensure 'sudo' works as hbacsvcgroup, again.
482+
ipahbacrule:
483+
ipaadmin_password: SomeADMINpassword
484+
name: "test_sudo"
485+
hbacsvcgroup:
486+
- sudo
487+
register: result
488+
failed_when: result.changed or result.failed
489+
490+
- name: Ensure 'sudo' works as hbacsvcgroup, action member.
491+
ipahbacrule:
492+
ipaadmin_password: SomeADMINpassword
493+
name: "test_sudo"
494+
hbacsvcgroup:
495+
- sudo
496+
action: member
497+
register: result
498+
failed_when: result.changed or result.failed
499+
500+
- name: Ensure 'Sudo' works as hbacsvcgroup, action member.
501+
ipahbacrule:
502+
ipaadmin_password: SomeADMINpassword
503+
name: "test_sudo"
504+
hbacsvcgroup:
505+
- Sudo
506+
register: result
507+
failed_when: result.changed or result.failed
508+
471509
always:
472510
- name: Ensure test hbacrule is absent
473511
ipahbacrule:
474512
ipaadmin_password: SomeADMINpassword
475-
name: testrule
513+
name:
514+
- testrule
515+
- test_sudo
476516
state: absent
477517

478518
- name: Ensure test users are absent

0 commit comments

Comments
 (0)