ipapermission: add version check for bind type 'self'

FreeIPA 4.8.7 has introduced bind type 'self' as a valid value, and
this PR adds checks so the module fails early if the value is used
with an unsupported version.

Tests and documentation have been updated to reflect the changes.
This commit is contained in:
Rafael Guterres Jeffman
2020-11-13 15:26:36 -03:00
parent 2aaabc77c4
commit b6cf3e5f51
3 changed files with 41 additions and 13 deletions

View File

@@ -141,7 +141,7 @@ Variable | Description | Required
`name` \| `cn` | The permission name string. | yes `name` \| `cn` | The permission name string. | yes
`right` \| `ipapermright` | Rights to grant. It can be a list of one or more of `read`, `search`, `compare`, `write`, `add`, `delete`, and `all` default: `all` | no `right` \| `ipapermright` | Rights to grant. It can be a list of one or more of `read`, `search`, `compare`, `write`, `add`, `delete`, and `all` default: `all` | no
`attrs` | All attributes to which the permission applies | no `attrs` | All attributes to which the permission applies | no
`bindtype` \| `ipapermbindruletype` | Bind rule type. It can be one of `permission`, `all`, `self`, or `anonymous` defaults to `permission` for new permissions.| no `bindtype` \| `ipapermbindruletype` | Bind rule type. It can be one of `permission`, `all`, `self`, or `anonymous` defaults to `permission` for new permissions. Bind rule type `self` can only be used on IPA versions 4.8.7 or up.| no
`subtree` \| `ipapermlocation` | Subtree to apply permissions to | no `subtree` \| `ipapermlocation` | Subtree to apply permissions to | no
`filter` \| `extratargetfilter` | Extra target filter | no `filter` \| `extratargetfilter` | Extra target filter | no
`rawfilter` \| `ipapermtargetfilter` | All target filters | no `rawfilter` \| `ipapermtargetfilter` | All target filters | no

View File

@@ -152,7 +152,8 @@ RETURN = """
from ansible.module_utils.basic import AnsibleModule from ansible.module_utils.basic import AnsibleModule
from ansible.module_utils.ansible_freeipa_module import \ from ansible.module_utils.ansible_freeipa_module import \
temp_kinit, temp_kdestroy, valid_creds, api_connect, api_command, \ temp_kinit, temp_kdestroy, valid_creds, api_connect, api_command, \
compare_args_ipa, module_params_get, gen_add_del_lists compare_args_ipa, module_params_get, gen_add_del_lists, \
api_check_ipa_version
import six import six
if six.PY3: if six.PY3:
@@ -336,6 +337,10 @@ def main():
msg="Argument '%s' can not be used with action " msg="Argument '%s' can not be used with action "
"'%s' and state '%s'" % (x, action, state)) "'%s' and state '%s'" % (x, action, state))
if bindtype == "self" and api_check_ipa_version("<", "4.8.7"):
ansible_module.fail_json(
msg="Bindtype 'self' is not supported by your IPA version.")
# Init # Init
changed = False changed = False

View File

@@ -4,13 +4,17 @@
become: true become: true
tasks: tasks:
- include_tasks: ../env_freeipa_facts.yml
# CLEANUP TEST ITEMS # CLEANUP TEST ITEMS
- name: Ensure permission perm-test-1 is absent - name: Ensure permission perm-test-1 is absent
ipapermission: ipapermission:
ipaadmin_password: SomeADMINpassword ipaadmin_password: SomeADMINpassword
name: perm-test-1 name:
- perm-test-1
- perm-test-bindtype-test
- perm-test-renamed
state: absent state: absent
# TESTS # TESTS
@@ -99,16 +103,35 @@
register: result register: result
failed_when: result.changed or result.failed failed_when: result.changed or result.failed
- name: Ensure permission with bindtype 'self' is present, if IPA version >= 4.8.7
ipapermission:
ipaadmin_password: SomeADMINpassword
name: perm-test-bindtype-test
bindtype: self
object_type: host
right: all
when: ipa_version is version('4.8.7', '>=')
register: result
failed_when: not result.changed or result.failed
- name: Fail to set permission perm-test-renamed bindtype to 'self', if IPA version < 4.8.7
ipapermission:
ipaadmin_password: SomeADMINpassword
name: perm-test-bindtype-test
bindtype: self
object_type: host
right: all
when: ipa_version is version('4.8.7', '<')
register: result
failed_when: not result.failed or "Bindtype 'self' is not supported by your IPA version." not in result.msg
# CLEANUP TEST ITEMS # CLEANUP TEST ITEMS
- name: Ensure permission perm-test-1 is absent - name: Ensure permission perm-test-1 is absent
ipapermission: ipapermission:
ipaadmin_password: SomeADMINpassword ipaadmin_password: SomeADMINpassword
name: perm-test-1 name:
state: absent - perm-test-1
- perm-test-bindtype-test
- name: Ensure permission perm-test-renamed is absent - perm-test-renamed
ipapermission:
ipaadmin_password: SomeADMINpassword
name: perm-test-renamed
state: absent state: absent