Blame SOURCES/ansible-freeipa-0.1.12-Fixes-password-behavior-on-Vault-module_rhbz#1839200.patch

c235c4
From 3e5c54d4fdb10deda9b7e4deaf2c537b132711c9 Mon Sep 17 00:00:00 2001
c235c4
From: Rafael Guterres Jeffman <rjeffman@redhat.com>
c235c4
Date: Fri, 31 Jul 2020 11:30:51 -0300
c235c4
Subject: [PATCH] Fix identification of existing vault type.
c235c4
c235c4
In some scenarios, the value of the vault type is returned as a tuple,
c235c4
rather than a string, this made some changes to existing vault to fail.
c235c4
With this change, the vault type is correctly retrieved, if it was not
c235c4
provided by the user.
c235c4
---
c235c4
 plugins/modules/ipavault.py | 4 +++-
c235c4
 1 file changed, 3 insertions(+), 1 deletion(-)
c235c4
c235c4
diff --git a/plugins/modules/ipavault.py b/plugins/modules/ipavault.py
c235c4
index 6a3c73e..8562ff7 100644
c235c4
--- a/plugins/modules/ipavault.py
c235c4
+++ b/plugins/modules/ipavault.py
c235c4
@@ -494,8 +494,10 @@ def check_encryption_params(module, state, action, vault_type, salt,
c235c4
                             new_password, new_password_file, res_find):
c235c4
     vault_type_invalid = []
c235c4
 
c235c4
-    if res_find is not None:
c235c4
+    if vault_type is None and res_find is not None:
c235c4
         vault_type = res_find['ipavaulttype']
c235c4
+        if isinstance(vault_type, (tuple, list)):
c235c4
+            vault_type = vault_type[0]
c235c4
 
c235c4
     if vault_type == "standard":
c235c4
         vault_type_invalid = ['public_key', 'public_key_file', 'password',
c235c4
-- 
c235c4
2.26.2
c235c4
c235c4
From d52364bac923f2935b948882d5825e7488b0e9cf Mon Sep 17 00:00:00 2001
c235c4
From: Rafael Guterres Jeffman <rjeffman@redhat.com>
c235c4
Date: Fri, 31 Jul 2020 11:32:36 -0300
c235c4
Subject: [PATCH] Fix random salt generation.
c235c4
c235c4
The generation of a random salt, when one was not provided, was in the
c235c4
wrong place and being generated too late to be used properly. Also, the
c235c4
generation of the value was duplicated.
c235c4
---
c235c4
 plugins/modules/ipavault.py | 13 +++++--------
c235c4
 1 file changed, 5 insertions(+), 8 deletions(-)
c235c4
c235c4
diff --git a/plugins/modules/ipavault.py b/plugins/modules/ipavault.py
c235c4
index 8562ff7..dffd972 100644
c235c4
--- a/plugins/modules/ipavault.py
c235c4
+++ b/plugins/modules/ipavault.py
c235c4
@@ -768,7 +768,12 @@ def main():
c235c4
                             commands.append([name, "vault_mod_internal", args])
c235c4
 
c235c4
                     else:
c235c4
+                        if vault_type == 'symmetric' \
c235c4
+                           and 'ipavaultsalt' not in args:
c235c4
+                            args['ipavaultsalt'] = os.urandom(32)
c235c4
+
c235c4
                         commands.append([name, "vault_add_internal", args])
c235c4
+
c235c4
                         if vault_type != 'standard' and vault_data is None:
c235c4
                             vault_data = ''
c235c4
 
c235c4
@@ -826,14 +831,6 @@ def main():
c235c4
                         commands.append(
c235c4
                             [name, 'vault_remove_owner', owner_del_args])
c235c4
 
c235c4
-                    if vault_type == 'symmetric' \
c235c4
-                       and 'ipavaultsalt' not in args:
c235c4
-                        args['ipavaultsalt'] = os.urandom(32)
c235c4
-
c235c4
-                    if vault_type == 'symmetric' \
c235c4
-                       and 'ipavaultsalt' not in args:
c235c4
-                        args['ipavaultsalt'] = os.urandom(32)
c235c4
-
c235c4
                 elif action in "member":
c235c4
                     # Add users and groups
c235c4
                     if any([users, groups, services]):
c235c4
-- 
c235c4
2.26.2
c235c4
c235c4
From daee6a6c744a740329ca231a277229567619e10c Mon Sep 17 00:00:00 2001
c235c4
From: Rafael Guterres Jeffman <rjeffman@redhat.com>
c235c4
Date: Fri, 31 Jul 2020 11:33:47 -0300
c235c4
Subject: [PATCH] Fix verification of parameters for modifying `salt`
c235c4
 attribute.
c235c4
c235c4
When modifying an existing vault to change the value of `salt`, the
c235c4
password must also change. It is fine to "change" the password to the
c235c4
same value, thus only changing the salt value.
c235c4
---
c235c4
 plugins/modules/ipavault.py | 10 ++++++++++
c235c4
 1 file changed, 10 insertions(+)
c235c4
c235c4
diff --git a/plugins/modules/ipavault.py b/plugins/modules/ipavault.py
c235c4
index dffd972..a608e64 100644
c235c4
--- a/plugins/modules/ipavault.py
c235c4
+++ b/plugins/modules/ipavault.py
c235c4
@@ -517,6 +517,16 @@ def check_encryption_params(module, state, action, vault_type, salt,
c235c4
             module.fail_json(
c235c4
                 msg="Cannot modify password of inexistent vault.")
c235c4
 
c235c4
+        if (
c235c4
+            salt is not None
c235c4
+            and not(
c235c4
+                any([password, password_file])
c235c4
+                and any([new_password, new_password_file])
c235c4
+            )
c235c4
+        ):
c235c4
+            module.fail_json(
c235c4
+                msg="Vault `salt` can only change when changing the password.")
c235c4
+
c235c4
     if vault_type == "asymmetric":
c235c4
         vault_type_invalid = [
c235c4
             'password', 'password_file', 'new_password', 'new_password_file'
c235c4
-- 
c235c4
2.26.2
c235c4
c235c4
From 4ef4e706b79fdbb43e462b1a7130fc2cad5894b2 Mon Sep 17 00:00:00 2001
c235c4
From: Rafael Guterres Jeffman <rjeffman@redhat.com>
c235c4
Date: Fri, 31 Jul 2020 11:42:13 -0300
c235c4
Subject: [PATCH] Modify tests to verify password was changed correctly.
c235c4
c235c4
Modify and add tests to verify that a password change has the correct
c235c4
effect on ipavault.
c235c4
---
c235c4
 tests/vault/test_vault_symmetric.yml | 36 ++++++++++++++++++----------
c235c4
 1 file changed, 23 insertions(+), 13 deletions(-)
c235c4
c235c4
diff --git a/tests/vault/test_vault_symmetric.yml b/tests/vault/test_vault_symmetric.yml
c235c4
index bedc221..9294331 100644
c235c4
--- a/tests/vault/test_vault_symmetric.yml
c235c4
+++ b/tests/vault/test_vault_symmetric.yml
c235c4
@@ -178,6 +178,15 @@
c235c4
     register: result
c235c4
     failed_when: result.vault.data != 'Hello World.' or result.changed
c235c4
 
c235c4
+  - name: Retrieve data from symmetric vault, with wrong password.
c235c4
+    ipavault:
c235c4
+      ipaadmin_password: SomeADMINpassword
c235c4
+      name: symvault
c235c4
+      password: SomeWRONGpassword
c235c4
+      state: retrieved
c235c4
+    register: result
c235c4
+    failed_when: not result.failed or "Invalid credentials" not in result.msg
c235c4
+
c235c4
   - name: Change vault password.
c235c4
     ipavault:
c235c4
       ipaadmin_password: SomeADMINpassword
c235c4
@@ -187,43 +196,44 @@
c235c4
     register: result
c235c4
     failed_when: not result.changed
c235c4
 
c235c4
-  - name: Retrieve data from symmetric vault, with wrong password.
c235c4
+  - name: Retrieve data from symmetric vault, with new password.
c235c4
     ipavault:
c235c4
       ipaadmin_password: SomeADMINpassword
c235c4
       name: symvault
c235c4
-      password: SomeVAULTpassword
c235c4
+      password: SomeNEWpassword
c235c4
       state: retrieved
c235c4
     register: result
c235c4
-    failed_when: not result.failed or "Invalid credentials" not in result.msg
c235c4
+    failed_when: result.data != 'Hello World.' or result.changed
c235c4
 
c235c4
-  - name: Change vault password, with wrong `old_password`.
c235c4
+  - name: Retrieve data from symmetric vault, with old password.
c235c4
     ipavault:
c235c4
       ipaadmin_password: SomeADMINpassword
c235c4
       name: symvault
c235c4
       password: SomeVAULTpassword
c235c4
-      new_password: SomeNEWpassword
c235c4
+      state: retrieved
c235c4
     register: result
c235c4
     failed_when: not result.failed or "Invalid credentials" not in result.msg
c235c4
 
c235c4
-  - name: Retrieve data from symmetric vault, with new password.
c235c4
+  - name: Change symmetric vault salt, changing password
c235c4
     ipavault:
c235c4
       ipaadmin_password: SomeADMINpassword
c235c4
       name: symvault
c235c4
       password: SomeNEWpassword
c235c4
-      state: retrieved
c235c4
+      new_password: SomeVAULTpassword
c235c4
+      salt: AAAAAAAAAAAAAAAAAAAAAAA=
c235c4
     register: result
c235c4
-    failed_when: result.vault.data != 'Hello World.' or result.changed
c235c4
+    failed_when: not result.changed
c235c4
 
c235c4
-  - name: Try to add vault with multiple passwords.
c235c4
+  - name: Change symmetric vault salt, without changing password
c235c4
     ipavault:
c235c4
       ipaadmin_password: SomeADMINpassword
c235c4
-      name: inexistentvault
c235c4
+      name: symvault
c235c4
       password: SomeVAULTpassword
c235c4
-      password_file: "{{ ansible_env.HOME }}/password.txt"
c235c4
+      new_password: SomeVAULTpassword
c235c4
+      salt: MTIzNDU2Nzg5MDEyMzQ1Ngo=
c235c4
     register: result
c235c4
-    failed_when: not result.failed or "parameters are mutually exclusive" not in result.msg
c235c4
+    failed_when: not result.changed
c235c4
 
c235c4
-  - name: Try to add vault with multiple new passwords.
c235c4
     ipavault:
c235c4
       ipaadmin_password: SomeADMINpassword
c235c4
       name: inexistentvault
c235c4
-- 
c235c4
2.26.2
c235c4
c235c4
From 8ca282e276477b52d0850d4c01feb3d8e7a5be6d Mon Sep 17 00:00:00 2001
c235c4
From: Rafael Guterres Jeffman <rjeffman@redhat.com>
c235c4
Date: Fri, 31 Jul 2020 11:44:33 -0300
c235c4
Subject: [PATCH] Modified and added tests to verify correct `salt` update
c235c4
 behavior.
c235c4
c235c4
---
c235c4
 tests/vault/test_vault_symmetric.yml | 35 ++++++++++++++++++++++++----
c235c4
 1 file changed, 31 insertions(+), 4 deletions(-)
c235c4
c235c4
diff --git a/tests/vault/test_vault_symmetric.yml b/tests/vault/test_vault_symmetric.yml
c235c4
index 9294331..1604a01 100644
c235c4
--- a/tests/vault/test_vault_symmetric.yml
c235c4
+++ b/tests/vault/test_vault_symmetric.yml
c235c4
@@ -234,14 +234,41 @@
c235c4
     register: result
c235c4
     failed_when: not result.changed
c235c4
 
c235c4
+  - name: Try to change symmetric vault salt, without providing any password
c235c4
     ipavault:
c235c4
       ipaadmin_password: SomeADMINpassword
c235c4
-      name: inexistentvault
c235c4
-      password: SomeVAULTpassword
c235c4
+      name: symvault
c235c4
+      salt: MTIzNDU2Nzg5MDEyMzQ1Ngo=
c235c4
+    register: result
c235c4
+    failed_when: not result.failed and  "Vault `salt` can only change when changing the password." not in result.msg
c235c4
+
c235c4
+  - name: Try to change symmetric vault salt, without providing `password`
c235c4
+    ipavault:
c235c4
+      ipaadmin_password: SomeADMINpassword
c235c4
+      name: symvault
c235c4
+      salt: MTIzNDU2Nzg5MDEyMzQ1Ngo=
c235c4
       new_password: SomeVAULTpassword
c235c4
-      new_password_file: "{{ ansible_env.HOME }}/password.txt"
c235c4
     register: result
c235c4
-    failed_when: not result.failed or "parameters are mutually exclusive" not in result.msg
c235c4
+    failed_when: not result.failed and  "Vault `salt` can only change when changing the password." not in result.msg
c235c4
+
c235c4
+  - name: Try to change symmetric vault salt, without providing `new_password`
c235c4
+    ipavault:
c235c4
+      ipaadmin_password: SomeADMINpassword
c235c4
+      name: symvault
c235c4
+      salt: MTIzNDU2Nzg5MDEyMzQ1Ngo=
c235c4
+      password: SomeVAULTpassword
c235c4
+    register: result
c235c4
+    failed_when: not result.failed and  "Vault `salt` can only change when changing the password." not in result.msg
c235c4
+
c235c4
+  - name: Try to change symmetric vault salt, using wrong password.
c235c4
+    ipavault:
c235c4
+      ipaadmin_password: SomeADMINpassword
c235c4
+      name: symvault
c235c4
+      password: SomeWRONGpassword
c235c4
+      new_password: SomeWRONGpassword
c235c4
+      salt: MDEyMzQ1Njc4OTAxMjM0NQo=
c235c4
+    register: result
c235c4
+    failed_when: not result.failed
c235c4
 
c235c4
   - name: Ensure symmetric vault is absent
c235c4
     ipavault:
c235c4
-- 
c235c4
2.26.2
c235c4
c235c4
From 3c2700f68beade3513e0e44415d8eb4fb23026e8 Mon Sep 17 00:00:00 2001
c235c4
From: Rafael Guterres Jeffman <rjeffman@redhat.com>
c235c4
Date: Fri, 14 Aug 2020 10:43:30 -0300
c235c4
Subject: [PATCH] Fixed Vault return value usage from `data` to `vault.data`.
c235c4
c235c4
A test was failing due to use of old ipavault module return structure
c235c4
and some places on the documentation were alse referring to it. All
c235c4
ocurrences were fixed.
c235c4
---
c235c4
 README-vault.md                      | 2 +-
c235c4
 plugins/modules/ipavault.py          | 2 +-
c235c4
 tests/vault/test_vault_symmetric.yml | 2 +-
c235c4
 3 files changed, 3 insertions(+), 3 deletions(-)
c235c4
c235c4
diff --git a/README-vault.md b/README-vault.md
c235c4
index 91d311d..e7a31a2 100644
c235c4
--- a/README-vault.md
c235c4
+++ b/README-vault.md
c235c4
@@ -197,7 +197,7 @@ Example playbook to make sure vault is absent:
c235c4
       state: absent
c235c4
     register: result
c235c4
   - debug:
c235c4
-      msg: "{{ result.data }}"
c235c4
+      msg: "{{ result.vault.data }}"
c235c4
 ```
c235c4
 
c235c4
 Variables
c235c4
diff --git a/plugins/modules/ipavault.py b/plugins/modules/ipavault.py
c235c4
index a608e64..8060976 100644
c235c4
--- a/plugins/modules/ipavault.py
c235c4
+++ b/plugins/modules/ipavault.py
c235c4
@@ -243,7 +243,7 @@ EXAMPLES = """
c235c4
     state: retrieved
c235c4
   register: result
c235c4
 - debug:
c235c4
-    msg: "{{ result.data }}"
c235c4
+    msg: "{{ result.vault.data }}"
c235c4
 
c235c4
 # Change password of a symmetric vault
c235c4
 - ipavault:
c235c4
diff --git a/tests/vault/test_vault_symmetric.yml b/tests/vault/test_vault_symmetric.yml
c235c4
index 1604a01..5394c71 100644
c235c4
--- a/tests/vault/test_vault_symmetric.yml
c235c4
+++ b/tests/vault/test_vault_symmetric.yml
c235c4
@@ -203,7 +203,7 @@
c235c4
       password: SomeNEWpassword
c235c4
       state: retrieved
c235c4
     register: result
c235c4
-    failed_when: result.data != 'Hello World.' or result.changed
c235c4
+    failed_when: result.vault.data != 'Hello World.' or result.changed
c235c4
 
c235c4
   - name: Retrieve data from symmetric vault, with old password.
c235c4
     ipavault:
c235c4
-- 
c235c4
2.26.2
c235c4