luks_device: allow passphrases to contain newlines (#844)

* luks_device: allow passphrases to contain newlines

This is useful when passing binary keyfiles from an ansible vault, as
it removes the restriction that the binary data cannot contain newlines.
The only exception is adding a new key to an existing container, as in
that case the two passphrases are separated by a new line.

* add integration tests and a changelog fragment

* attempt to also make luks_add_key work with passphrases containing
newlines

* use a deterministic method to generate keyfile 3, improve changelog
formatting

* add licence and copyright to keyfile3.txt to satisfy CI
This commit is contained in:
ilia-kats
2025-02-09 14:24:16 +01:00
committed by GitHub
parent cb6edf1a5f
commit 2433fdab98
7 changed files with 134 additions and 7 deletions

Binary file not shown.

View File

@@ -0,0 +1,3 @@
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
SPDX-FileCopyrightText: Ansible Project

View File

@@ -0,0 +1,7 @@
# 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
generated with:
dd if=/dev/zero of=/dev/stdout bs=1 count=4096 | openssl enc -aes-256-ctr -pass pass:1234 -nosalt

View File

@@ -0,0 +1,105 @@
---
# 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 with keyfile3
luks_device:
device: "{{ cryptfile_device }}"
state: closed
passphrase: "{{ keyfile3 }}"
passphrase_encoding: base64
type: luks2
pbkdf:
iteration_time: 0.1
algorithm: argon2i
memory: 1000
parallel: 1
sector_size: 1024
become: true
ignore_errors: true
register: create_passphrase_1
- name: Create with keyfile3 (without argon2i)
luks_device:
device: "{{ cryptfile_device }}"
state: closed
passphrase: "{{ keyfile3 }}"
passphrase_encoding: base64
pbkdf:
iteration_time: 0.1
become: true
when: create_passphrase_1 is failed
- name: Open with keyfile3
luks_device:
device: "{{ cryptfile_device }}"
state: opened
passphrase: "{{ keyfile3 }}"
passphrase_encoding: base64
become: true
ignore_errors: true
register: open_try
- assert:
that:
- open_try is not failed
- name: Close
luks_device:
device: "{{ cryptfile_device }}"
state: closed
become: true
- name: Try to open with passphrase1
luks_device:
device: "{{ cryptfile_device }}"
state: opened
passphrase: "{{ cryptfile_passphrase1 }}"
become: true
ignore_errors: true
register: open_try
- assert:
that:
- open_try is failed
- name: Give access to passphrase1
luks_device:
device: "{{ cryptfile_device }}"
state: closed
passphrase: "{{ keyfile3 }}"
passphrase_encoding: base64
new_passphrase: "{{ cryptfile_passphrase1 | b64encode }}"
pbkdf:
iteration_time: 0.1
become: true
- name: Remove access for keyfile3
luks_device:
device: "{{ cryptfile_device }}"
state: closed
remove_passphrase: "{{ keyfile3 }}"
passphrase_encoding: base64
become: true
- name: Try to open with keyfile3
luks_device:
device: "{{ cryptfile_device }}"
state: opened
passphrase: "{{ keyfile3 }}"
become: true
ignore_errors: true
register: open_try
- assert:
that:
- open_try is failed
- name: Open with passphrase1
luks_device:
device: "{{ cryptfile_device }}"
state: opened
passphrase: "{{ cryptfile_passphrase1 }}"
become: true
ignore_errors: true
register: open_try
- assert:
that:
- open_try is not failed

View File

@@ -0,0 +1,6 @@
---
# 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
keyfile3: "{{ lookup('ansible.builtin.file', 'keyfile3', lstrip=False, rstrip=False) | b64encode }}"