Commit Graph

375 Commits

Author SHA1 Message Date
Rafael Guterres Jeffman
d81994475e Deprecate FreeIPABaseModule in favor of IPAAnsibleModule.
This patch add several deprecate warnings to FreeIPABaseModule, and
creates adapters to ease conversion of client classes to
IPAAnsibleModule.

There is no 'ipa_commands' management in IPAAnsibleModule, as 'command's
is a list of tuples containing '(command, name, args)', and should be
managed by the module itself. Commands with no arguments should use an
empty dictionary as 'args'.

The 'ipa_run' method should be replaced by:

```
exit_args = {}
ipaapi_context = self.params_get("ipaapi_context")
with self.ipa_connect(context=ipaapi_context):
    self.check_ipa_params()
    self.define_ipa_commands()
    changed = self.execute_ipa_commands(
                self.ipa_commands,
                result_handler=my_custom_handler,
                exit_args=exit_args
            )
self.exit_json(changed=changed, **exit_args)
```

The 'process_command_result' method should be changed to a result
handler:

```
def my_result_handler(self, result, command, name, args, exit_args):
    """Process command result.""'
```

Use of 'ipa_params' should be replaced by IPAAnsibleModule.params_get.
If 'get_ipa_command_args' is used, then the mapping can be created with
class IPAParamMapping (formelly AnsibleFreeIPAParams), which also
enables the same property-like usage of 'ipa_params':

```
param_mapping = IPAParamMapping(module, mapping)
```

The goal is to have all ansible-freeipa modules using the same codebase,
reducing code duplication, and allowing better object composition, for
example, with the IPAParamMapping class.
2021-11-16 15:51:55 -03:00
Thomas Woerner
d6eaf91225 Merge pull request #670 from rjeffman/ipapermission_fixes
ipaprivilege: Fix permissions handling.
2021-11-12 13:19:41 +01:00
Thomas Woerner
cb95248ef5 Merge pull request #665 from rjeffman/fix_sudorule_idempotency
sudorule: Fix runas with external users and groups.
2021-11-12 13:09:58 +01:00
Rafael Guterres Jeffman
22f31d02f2 sudorule: Fix runas with external users and groups.
When setting 'runasuser' or 'runasgroup' for a sudorule, either IPA or
external users and groups can be used, but only IPA users and groups
were being searched for when modifying the attributes, making this task
not idempotent if an external group or user was used..

This patch fixes this issue by comparing users and groups to the IPA
and external setting.

The IPA CLI commands are slightly confusing, as the sudorule-add and
sudorule-mod display separate options for internal and external users
and groups, but these options are deprecated and do not work anymore,
in favor of sudorule-add-runasuser and sudorule-add-runasgroup, which
don't diferentiate between internal and external users, from the CLI
user perspective.
2021-11-03 15:49:09 -03:00
Rafael Guterres Jeffman
0757bfee0a ipaprivilege: Fix module execution in check_mode.
This patch removes the custom command result handler in favor of the
IPAAnsibleModule default member handler and fixes creation of add and
del lists of permissions, fixing the behavior of the moudule execution
when 'check_mode: yes'.
2021-10-26 11:37:07 -03:00
Rafael Guterres Jeffman
1eff04a09a ipaprivilege: fix creation of add/del lists for permissions.
A wrong parameter 'member_permission' was being used to obtain the
existing permissions, and was changed to 'memberof_permission'.
2021-10-26 09:43:13 -03:00
Rafael Guterres Jeffman
f43831407b ipaservice: Fix idempotent behavior for principal aliases.
When creating the lists to add/remove principal aliases, if the realm
was not specified, the alias would be used as it did not matched the
existing one, which has the realm part.

This patch fixes the add/del list creation by adding the current API
realm to each alias that does not have the realm part and then use
this modified list to be compared against the existing principal list.

This change also allows the use of the whole list in a single call to
the IPA API to add/remove the principals, instead of a call for every
one item in the list.
2021-10-25 16:15:16 -03:00
Rafael Guterres Jeffman
0fac277ec8 vault: Use IPAAnsibleModule method to validate arguments.
Use the IPAAnsibleModule.params_fail_if_used method to validate
arguments provided by user.
2021-10-01 09:50:00 -03:00
Rafael Guterres Jeffman
2ec65e91df user: Use IPAAnsibleModule method to validate arguments.
Use the IPAAnsibleModule.params_fail_if_used method to validate
arguments provided by user.
2021-10-01 09:50:00 -03:00
Rafael Guterres Jeffman
5a67aa7714 sudorule: Use IPAAnsibleModule method to validate arguments.
Use the IPAAnsibleModule.params_fail_if_used method to validate
arguments provided by user.
2021-10-01 09:50:00 -03:00
Rafael Guterres Jeffman
14c9f308d8 sudocmdgroup: Use IPAAnsibleModule method to validate arguments.
Use the IPAAnsibleModule.params_fail_if_used method to validate
arguments provided by user.
2021-10-01 09:50:00 -03:00
Rafael Guterres Jeffman
7f80a3f140 sudocmd: Use IPAAnsibleModule method to validate arguments.
Use the IPAAnsibleModule.params_fail_if_used method to validate
arguments provided by user.
2021-10-01 09:50:00 -03:00
Rafael Guterres Jeffman
81672bdf62 service: Use IPAAnsibleModule method to validate arguments.
Use the IPAAnsibleModule.params_fail_if_used method to validate
arguments provided by user.
2021-10-01 09:50:00 -03:00
Rafael Guterres Jeffman
f9851f0a33 server: Use IPAAnsibleModule method to validate arguments.
Use the IPAAnsibleModule.params_fail_if_used method to validate
arguments provided by user.
2021-10-01 09:50:00 -03:00
Rafael Guterres Jeffman
970d6c12da selfservice: Use IPAAnsibleModule method to validate arguments.
Use the IPAAnsibleModule.params_fail_if_used method to validate
arguments provided by user.
2021-10-01 09:50:00 -03:00
Rafael Guterres Jeffman
1ae2c1eb39 role: Use IPAAnsibleModule method to validate arguments.
Use the IPAAnsibleModule.params_fail_if_used method to validate
arguments provided by user.
2021-10-01 09:50:00 -03:00
Rafael Guterres Jeffman
efa67303ac pwpolicy: Use IPAAnsibleModule method to validate arguments.
Use the IPAAnsibleModule.params_fail_if_used method to validate
arguments provided by user.
2021-10-01 09:50:00 -03:00
Rafael Guterres Jeffman
08f9259295 privilege: Use IPAAnsibleModule method to validate arguments.
Use the IPAAnsibleModule.params_fail_if_used method to validate
arguments provided by user.
2021-10-01 09:50:00 -03:00
Rafael Guterres Jeffman
53defc9eec permission: Use IPAAnsibleModule method to validate arguments.
Use the IPAAnsibleModule.params_fail_if_used method to validate
arguments provided by user.
2021-10-01 09:50:00 -03:00
Rafael Guterres Jeffman
fc3f64f0f1 location: Use IPAAnsibleModule method to validate arguments.
Use the IPAAnsibleModule.params_fail_if_used method to validate
arguments provided by user.
2021-10-01 09:50:00 -03:00
Rafael Guterres Jeffman
9bf2def20b hostgroup: Use IPAAnsibleModule method to validate arguments.
Use the IPAAnsibleModule.params_fail_if_used method to validate
arguments provided by user.
2021-10-01 09:50:00 -03:00
Rafael Guterres Jeffman
c497c8c4e1 host: Use IPAAnsibleModule method to validate arguments.
Use the IPAAnsibleModule.params_fail_if_used method to validate
arguments provided by user.
2021-10-01 09:50:00 -03:00
Rafael Guterres Jeffman
952f62cd83 hbacsvcgroup: Use IPAAnsibleModule method to validate arguments.
Use the IPAAnsibleModule.params_fail_if_used method to validate
arguments provided by user.
2021-10-01 09:50:00 -03:00
Rafael Guterres Jeffman
43d1a06b86 hbacsvc: Use IPAAnsibleModule method to validate arguments.
Use the IPAAnsibleModule.params_fail_if_used method to validate
arguments provided by user.
2021-10-01 09:50:00 -03:00
Rafael Guterres Jeffman
7564250614 hbacrule: Use IPAAnsibleModule method to validate arguments.
Use the IPAAnsibleModule.params_fail_if_used method to validate
arguments provided by user.
2021-10-01 09:50:00 -03:00
Rafael Guterres Jeffman
602f3a0ff3 group: Use IPAAnsibleModule method to validate arguments.
Use the IPAAnsibleModule.params_fail_if_used method to validate
arguments provided by user.
2021-10-01 09:50:00 -03:00
Rafael Guterres Jeffman
089400dbd0 dnszone: Use IPAAnsibleModule method to validate arguments.
Use the IPAAnsibleModule.params_fail_if_used method to validate
arguments provided by user.
2021-10-01 09:50:00 -03:00
Rafael Guterres Jeffman
6f7b514e02 dnsrecord: Use IPAAnsibleModule method to validate arguments.
Use the IPAAnsibleModule.params_fail_if_used method to validate
arguments provided by user.
2021-10-01 09:50:00 -03:00
Rafael Guterres Jeffman
67282b1a6a dnsforwardzone: Use IPAAnsibleModule method to validate arguments.
Use the IPAAnsibleModule.params_fail_if_used method to validate
arguments provided by user.
2021-10-01 09:50:00 -03:00
Rafael Guterres Jeffman
f34337962d dnsconfig: : Use IPAAnsibleModule method to validate arguments.
Use the IPAAnsibleModule.params_fail_if_used method to validate
arguments provided by user.
2021-10-01 09:50:00 -03:00
Rafael Guterres Jeffman
06ccc70c39 delegation: Use IPAAnsibleModule method to validate arguments.
Use the IPAAnsibleModule.params_fail_if_used method to validate
arguments provided by user.
2021-10-01 09:50:00 -03:00
Rafael Guterres Jeffman
23e38fae27 automember: Use IPAAnsibleModule method to validate arguments.
Use the IPAAnsibleModule.params_fail_if_used method to validate
arguments provided by user.
2021-10-01 09:50:00 -03:00
Rafael Guterres Jeffman
742799f3e9 Merge pull request #647 from t-woerner/ipaserver-readme-present-doc-enhancement
server: Express inability to deploy a server in example doc strings
2021-09-30 09:20:43 -03:00
Rafael Guterres Jeffman
1054bdd0e3 Fix ansible-lint E206 (var-spacing) on all test and example playbooks. 2021-09-29 15:49:00 -03:00
Rafael Guterres Jeffman
7e0624d836 ipavault: Allow execution of plugin in client host.
Update vault README file and add tests for executing plugin with
`ipaapi_context` set to `client`.

A new test playbook can be found at:

    tests/vault/test_vault_client_context.yml

As `ipavault` only works in client context, an error is raised if it
is explicitly executed in a server context.
2021-09-28 19:16:11 -03:00
Rafael Guterres Jeffman
a599f4ad87 ipapermission: Allow execution of plugin in client host.
Update permission README file and add tests for executing plugin with
`ipaapi_context` set to `client`.

A new test playbook can be found at:

    tests/permission/test_permission_client_context.yml

The new test file can be executed in a FreeIPA client host that is
not a server. In this case, it should be defined in the `ipaclients`
group, in the inventory file.

Due to differences in data returned when running in a client context,
some values had to be modified so that comparision works and an
unnecessary call to IPA API is executed.
2021-09-28 10:19:43 -03:00
Rafael Guterres Jeffman
cf7b197a1f ipadnszone: Allow execution of plugin in client host.
Update dnszone README file and add tests for executing plugin with
`ipaapi_context` set to `client`.

A new test playbook can be found at:

    tests/dnszone/test_dnszone_client_context.yml

The new test file can be executed in a FreeIPA client host that is
not a server. In this case, it should be defined in the `ipaclients`
group, in the inventory file.

Due to differences in data returned when running in a client context,
verification if zone is active had to be modified.
2021-09-28 10:19:43 -03:00
Rafael Guterres Jeffman
da45d74f75 ipadnsforwardzone: Allow execution of plugin in client host.
Update dnsforwardzone README file and add tests for executing plugin with
`ipaapi_context` set to `client`.

A new test playbook can be found at:

    tests/dnsforwardzone/test_dnsforwardzone_client_context.yml

The new test file can be executed in a FreeIPA client host that is
not a server. In this case, it should be defined in the `ipaclients`
group, in the inventory file.

Due to differences in data returned when running ipadnsforwardzone in
a client context, some values had to be modified so that comparision
works, avoiding unnecessary IPA API calls.
2021-09-28 10:19:43 -03:00
Thomas Woerner
6520cdcb1e server: Express inability to deploy a server in example doc strings
The doc strings for the examples have not been good enough to express
that the module is requiring an existing server and that is not able to
deploy a new server.
2021-09-28 10:58:51 +02:00
Rafael Guterres Jeffman
97670e8e46 Merge pull request #640 from t-woerner/group_class_fixes
group: Fix nonposix, posix and external handling and conversions
2021-09-16 16:55:25 -03:00
Thomas Woerner
1f25024396 group: Fix nonposix, posix and external handling and conversions
The nonposix, posix and external parameters need to be mutually
exclusive. external was missing in this list. Only one of the three
parameters can be used.

external can not be set to no/false. This results in an error now.

if nonposix is used, posix is set as not nonposix. The nonposix
parameter is not used within the code anymore..

New tests have been added to tests the addition of users with for
nonposix and posix groups. The tests for the external group is not
active due to the need of an AD.

Fixes: #528 (Error creating nonposix group)
2021-09-16 13:30:34 +02:00
Thomas Woerner
ccb07cbef5 Merge pull request #634 from rjeffman/sudocmd_use_execute_ipa_commands
Use execute_ipa_commands for sudocmd plugins.
2021-09-16 11:14:29 +02:00
Thomas Woerner
3d6bf87187 Merge pull request #637 from rjeffman/ipaconfig_missing_params
config: Fix data returned from module.
2021-09-16 10:20:53 +02:00
Rafael Guterres Jeffman
87de471d97 config: Fix data returned from module.
When retrieving IPA configuration using ipaconfig module, a few
variables were not returning, and some data had the wrong data format.

This patch fix both issues and apply some refactoring, as data was
being retrieved from IPA API in different places using different
methods.
2021-09-15 08:53:39 -03:00
Rafael Guterres Jeffman
1615f59f12 sudocmdgroup: Use execute_ipa_commands
execute_ipa_commands replces the check mode exit, the loop over the
generated commands and also in the member failure handling for modules
with member support.
2021-09-14 14:10:25 -03:00
Rafael Guterres Jeffman
8723aafd4f sudocmdgroup: Reduce addition and deletion of members to changed only
Use gen_add_list and gen_intersection_list for sudocmd member handling,
to reduce the add lists to only the new and del lists only to existing
entries.

This enables to remove the ignores for "already a member" and
"not a member" errors.
2021-09-14 14:10:25 -03:00
Rafael Guterres Jeffman
5175c870f2 config: Remove unused code.
Removed the definition of unused function 'gen_args()' from ipaconfig.
2021-09-14 10:04:36 -03:00
Rafael Guterres Jeffman
ae2f452c60 sudocmd: Use execute_ipa_commands
execute_ipa_commands replces the check mode exit, the loop over the
generated commands and also in the member failure handling for modules
with member support.
2021-09-13 14:13:58 -03:00
Thomas Woerner
8dec9f774b Merge pull request #633 from rjeffman/topology_fix_usage_ipaansiblemodule
Fix documentation and usage of IPAAnsibleModule
2021-09-09 09:54:50 +02:00
Rafael Guterres Jeffman
602446004a ipatopologysuffix: Fix usage of IPAAnsibleModule.
Fix parameters used to IPAAnsibleModule.ipa_command, as a singlo list
was being used instead of a parameter list.
2021-09-09 00:19:59 -03:00