Fixes attempt to create rules with members when category is all.

Current implementation of hbacrule and sudorule allow for a new rule
creation script to be partialy successful when a member is provided and
the respective member category is set to `all` (either users, hosts,
services, commands, and their group counterparts).

Since the creation of the rule is independent of the adittion of members,
the rule is succesfully created, but member addition fails, leaving with
a created rule that has no members on it.

This patch fixes both modules by verifying if user, host, service or
commands (and groups of members) are being added if the corresponding
category is set to `all`, when the state is `present` and the action is
not `member`. If so, it fails before the rule is created.
This commit is contained in:
Rafael Guterres Jeffman
2020-05-29 15:19:12 -03:00
parent 44af47d93a
commit cf54d139c2
4 changed files with 149 additions and 2 deletions

View File

@@ -109,6 +109,60 @@
register: result
failed_when: result.changed
- name: Ensure `user` cannot be added if usercategory is `all`.
ipahbacrule:
ipaadmin_password: SomeADMINpassword
name: allusers
user: shouldfail01
usercategory: "all"
register: result
failed_when: not result.failed or "Users cannot be added when user category='all'" not in result.msg
- name: Ensure `group` cannot be added if usercategory is `all`.
ipahbacrule:
ipaadmin_password: SomeADMINpassword
name: allusers
group: shouldfail01
usercategory: "all"
register: result
failed_when: not result.failed or "Users cannot be added when user category='all'" not in result.msg
- name: Ensure `host` cannot be added if hostcategory is `all`.
ipahbacrule:
ipaadmin_password: SomeADMINpassword
name: allusers
host: host.shouldfail.com
hostcategory: "all"
register: result
failed_when: not result.failed or "Hosts cannot be added when host category='all'" not in result.msg
- name: Ensure `hostgroup` cannot be added if hostcategory is `all`.
ipahbacrule:
ipaadmin_password: SomeADMINpassword
name: allusers
hostgroup: shouldfail_hostgroup
hostcategory: "all"
register: result
failed_when: not result.failed or "Hosts cannot be added when host category='all'" not in result.msg
- name: Ensure `hbacsvc` cannot be added if hbacsvccategory is `all`.
ipahbacrule:
ipaadmin_password: SomeADMINpassword
name: allusers
hbacsvc: "HTTP/fail.example.com"
servicecategory: "all"
register: result
failed_when: not result.failed or "Services cannot be added when service category='all'" not in result.msg
- name: Ensure `hbacsvcgroup` cannot be added if hbacsvccategory is `all`.
ipahbacrule:
ipaadmin_password: SomeADMINpassword
name: allusers
hbacsvcgroup: shouldfail_svcgroup
servicecategory: "all"
register: result
failed_when: not result.failed or "Services cannot be added when service category='all'" not in result.msg
- name: Ensure HBAC rules are absent
ipahbacrule:
ipaadmin_password: SomeADMINpassword