luks_device: add sector_size option (#193)

* Add sector_size option to luks_device.

* Trying to improve error handling.

* Improve error handling.
pull/198/head
Felix Fontein 2021-03-02 22:02:31 +01:00 committed by GitHub
parent ea889ce2ad
commit a1897fd3b1
No known key found for this signature in database
GPG Key ID: 4AEE18F83AFDEB23
3 changed files with 19 additions and 4 deletions

View File

@ -0,0 +1,2 @@
minor_changes:
- "luks_device - allow to specify sector size for LUKS2 containers with new ``sector_size`` parameter (https://github.com/ansible-collections/community.crypto/pull/193)."

View File

@ -211,6 +211,12 @@ options:
run in parallel. run in parallel.
- This is not used for PBKDF2, but only for the Argon PBKDFs. - This is not used for PBKDF2, but only for the Argon PBKDFs.
type: int type: int
sector_size:
description:
- "This option allows the user to specify the sector size (in bytes) used for LUKS2 containers."
- "Will only be used on container creation."
type: int
version_added: '1.5.0'
requirements: requirements:
- "cryptsetup" - "cryptsetup"
@ -452,7 +458,7 @@ class CryptHandler(Handler):
if pbkdf['parallel'] is not None: if pbkdf['parallel'] is not None:
options.extend(['--pbkdf-parallel', str(pbkdf['parallel'])]) options.extend(['--pbkdf-parallel', str(pbkdf['parallel'])])
def run_luks_create(self, device, keyfile, passphrase, keysize, cipher, hash_, pbkdf): def run_luks_create(self, device, keyfile, passphrase, keysize, cipher, hash_, sector_size, pbkdf):
# create a new luks container; use batch mode to auto confirm # create a new luks container; use batch mode to auto confirm
luks_type = self._module.params['type'] luks_type = self._module.params['type']
label = self._module.params['label'] label = self._module.params['label']
@ -471,6 +477,8 @@ class CryptHandler(Handler):
options.extend(['--hash', hash_]) options.extend(['--hash', hash_])
if pbkdf is not None: if pbkdf is not None:
self._add_pbkdf_options(options, pbkdf) self._add_pbkdf_options(options, pbkdf)
if sector_size is not None:
options.extend(['--sector-size', str(sector_size)])
args = [self._cryptsetup_bin, 'luksFormat'] args = [self._cryptsetup_bin, 'luksFormat']
args.extend(options) args.extend(options)
@ -759,6 +767,7 @@ def run_module():
), ),
mutually_exclusive=[('iteration_time', 'iteration_count')], mutually_exclusive=[('iteration_time', 'iteration_count')],
), ),
sector_size=dict(type='int'),
) )
mutually_exclusive = [ mutually_exclusive = [
@ -806,6 +815,7 @@ def run_module():
module.params['keysize'], module.params['keysize'],
module.params['cipher'], module.params['cipher'],
module.params['hash'], module.params['hash'],
module.params['sector_size'],
module.params['pbkdf'], module.params['pbkdf'],
) )
except ValueError as e: except ValueError as e:

View File

@ -4,19 +4,22 @@
device: "{{ cryptfile_device }}" device: "{{ cryptfile_device }}"
state: closed state: closed
passphrase: "{{ cryptfile_passphrase1 }}" passphrase: "{{ cryptfile_passphrase1 }}"
type: luks2
pbkdf: pbkdf:
iteration_time: 0.1 iteration_time: 0.1
algorithm: argon2i algorithm: argon2i
memory: 1000 memory: 1000
parallel: 1 parallel: 1
sector_size: 1024
become: yes become: yes
ignore_errors: yes ignore_errors: yes
register: create_passphrase_1 register: create_passphrase_1
- name: Make sure that the previous task only fails because the LUKS version used cannot handle the PBKDF parameters - name: Make sure that the previous task only fails if LUKS2 is not supported
assert: assert:
that: that:
- create_passphrase_1 is not failed or 'Failed to set pbkdf parameters' in create_passphrase_1.msg - "'Unknown option --type' in create_passphrase_1.msg"
when: create_passphrase_1 is failed
- name: Create with passphrase1 (without argon2i) - name: Create with passphrase1 (without argon2i)
luks_device: luks_device:
@ -26,7 +29,7 @@
pbkdf: pbkdf:
iteration_time: 0.1 iteration_time: 0.1
become: yes become: yes
when: create_passphrase_1 is failed and 'Failed to set pbkdf parameters' in create_passphrase_1.msg when: create_passphrase_1 is failed
- name: Open with passphrase1 - name: Open with passphrase1
luks_device: luks_device: