-
Notifications
You must be signed in to change notification settings - Fork 35
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Merge pull request #28 from micxer/auto-unlock
Auto-load encryption keys on boot
- Loading branch information
Showing
5 changed files
with
65 additions
and
0 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,36 @@ | ||
--- | ||
- name: Encryption keys | Get encrypted pools | ||
ansible.builtin.set_fact: | ||
zfs_encrypted_pools: >- | ||
{{ zfs_pools | selectattr('options', 'search', 'keylocation') | map(attribute='name') | list }} | ||
when: zfs_create_pools | ||
|
||
- name: Encryption keys | Get encrypted datasets | ||
ansible.builtin.set_fact: | ||
zfs_encrypted_datasets: >- | ||
{{ zfs_filesystems | selectattr('keylocation', 'defined') | map('combine', {'dataset_name': '{{ pool }}/{{name}}'}) | ||
| map(attribute='dataset_name') | list }} | ||
when: zfs_create_filesystems | ||
|
||
- name: Encryption keys | Create key-load service unit file | ||
ansible.builtin.template: | ||
src: etc/systemd/system/[email protected] | ||
dest: /etc/systemd/system/[email protected] | ||
owner: root | ||
group: root | ||
mode: "0644" | ||
when: zfs_encrypted_pools or zfs_encrypted_datasets | ||
|
||
- name: Encryption keys | Activate key-load service for encrypted pools | ||
ansible.builtin.systemd_service: | ||
name: zfs-load-key@{{ item }} | ||
enabled: true | ||
loop: "{{ zfs_encrypted_pools }}" | ||
when: zfs_create_pools | ||
|
||
- name: Encryption keys | Activate key-load service for encrypted datasets | ||
ansible.builtin.systemd_service: | ||
name: zfs-load-key@{{ item }} | ||
enabled: true | ||
loop: "{{ zfs_encrypted_datasets }}" | ||
when: zfs_create_filesystems |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,16 @@ | ||
[Unit] | ||
Description=Load encryption keys for zpool | ||
Documentation=man:zfs(8) | ||
DefaultDependencies=no | ||
After=systemd-udev-settle.service | ||
After=systemd-remount-fs.service | ||
After=zfs-import.target | ||
Before=zfs-mount.service | ||
|
||
[Service] | ||
Type=oneshot | ||
RemainAfterExit=yes | ||
ExecStart=/sbin/zfs load-key %i | ||
|
||
[Install] | ||
WantedBy=zfs-mount.service |