luks_device: fix remove_keyslot not working when set to 0 and duplicate keys (#710)

* luks_device: fix remove_keyslot not working when set to 0

* luks_device: fix module outputting 'ok' when trying to add a key that is already present in another keyslot

* luks_device: fix breaking unit tests

* luks_device: Duplicate key test case code cleanup

* luks_device: Fix testing of LUKS passphrases when only testing one key slot

* luks_device: Fix testing of LUKS passphrases when only testing one key slot

* luks_device: Add changelog fragment for PR #710

* luks_device: Update changlog fragment
This commit is contained in:
Steffen Gufler
2024-02-11 12:23:21 +01:00
committed by GitHub
parent d1a229c255
commit 51591891d3
5 changed files with 87 additions and 2 deletions

View File

@@ -176,3 +176,31 @@
- kill_luks_slot4_idem is not changed
- kill_luks_slot4_idem_check is not changed
- "'Key Slot 4: DISABLED' in luks_header_slot4_removed.stdout or not '4: luks' in luks_header_slot4_removed.stdout"
- name: Add key in slot 0
luks_device:
device: "{{ cryptfile_device }}"
state: present
keyfile: "{{ remote_tmp_dir }}/keyfile2"
new_keyfile: "{{ remote_tmp_dir }}/keyfile1"
new_keyslot: 0
pbkdf:
iteration_time: 0.1
become: true
register: add_luks_slot0
- name: Remove key in slot 0
luks_device:
device: "{{ cryptfile_device }}"
keyfile: "{{ remote_tmp_dir }}/keyfile2"
remove_keyslot: 0
become: true
register: kill_luks_slot0
- name: Dump luks header
command: "cryptsetup luksDump {{ cryptfile_device }}"
become: true
register: luks_header_slot0_removed
- assert:
that:
- add_luks_slot0 is changed
- kill_luks_slot0 is changed
- "'Key Slot 0: DISABLED' in luks_header_slot0_removed.stdout or not '0: luks' in luks_header_slot0_removed.stdout"

View File

@@ -0,0 +1,40 @@
---
# Copyright (c) Ansible Project
# GNU General Public License v3.0+ (see LICENSES/GPL-3.0-or-later.txt or https://www.gnu.org/licenses/gpl-3.0.txt)
# SPDX-License-Identifier: GPL-3.0-or-later
- name: Create new luks
luks_device:
device: "{{ cryptfile_device }}"
state: present
keyfile: "{{ remote_tmp_dir }}/keyfile1"
pbkdf:
iteration_time: 0.1
become: true
- name: Add new keyslot with same keyfile (check)
luks_device:
device: "{{ cryptfile_device }}"
state: present
new_keyslot: 1
keyfile: "{{ remote_tmp_dir }}/keyfile1"
new_keyfile: "{{ remote_tmp_dir }}/keyfile1"
become: true
ignore_errors: true
check_mode: true
register: keyslot_duplicate_check
- name: Add new keyslot with same keyfile
luks_device:
device: "{{ cryptfile_device }}"
state: present
new_keyslot: 1
keyfile: "{{ remote_tmp_dir }}/keyfile1"
new_keyfile: "{{ remote_tmp_dir }}/keyfile1"
become: true
ignore_errors: true
register: keyslot_duplicate
- assert:
that:
- keyslot_duplicate_check is failed
- "'Trying to add key that is already present in another slot' in keyslot_duplicate_check.msg"
- keyslot_duplicate is failed
- "'Trying to add key that is already present in another slot' in keyslot_duplicate.msg"

View File

@@ -275,6 +275,7 @@ def test_luks_add_key(device, keyfile, passphrase, new_keyfile, new_passphrase,
module.params["passphrase"] = passphrase
module.params["new_keyfile"] = new_keyfile
module.params["new_passphrase"] = new_passphrase
module.params["new_keyslot"] = None
module.params["state"] = state
module.params["label"] = label