|
1 | | -- name: Save disk encryption key into a file as an example (in production use a hardware security module) |
| 1 | +- name: Ensure 'cryptsetup' utility is installed |
| 2 | + ansible.builtin.package: |
| 3 | + name: cryptsetup |
| 4 | + state: present |
| 5 | + when: disk_encryption_key is defined |
| 6 | + |
| 7 | +- name: 'Register encrypted file system' |
| 8 | + stat: |
| 9 | + path: /cryptfs_file_sparse.img |
| 10 | + get_checksum: False |
| 11 | + register: encryptedFileSystemPostCheck |
| 12 | + when: disk_encryption_key is defined |
| 13 | + |
| 14 | +- name: Check if Disk encryption key file exists |
| 15 | + ansible.builtin.stat: |
| 16 | + path: /root/disk-encryption-key.txt |
| 17 | + register: encryption_keyfile_stat |
| 18 | + when: disk_encryption_key is defined |
| 19 | + |
| 20 | +- name: Read existing Disk encryption key |
| 21 | + ansible.builtin.slurp: |
| 22 | + src: /root/disk-encryption-key.txt |
| 23 | + register: existing_disk_encryption_key |
| 24 | + when: |
| 25 | + - disk_encryption_key is defined |
| 26 | + - encryption_keyfile_stat.stat.exists |
| 27 | + |
| 28 | +- name: Fail if key exists and differs |
| 29 | + ansible.builtin.fail: |
| 30 | + msg: "Disk encryption key on disk does not match ansible variable! GitHub secret ENCRYPTION_KEY was updated!" |
| 31 | + when: |
| 32 | + - encryption_keyfile_stat.stat.exists |
| 33 | + - existing_disk_encryption_key['content'] | b64decode != ("DISK_ENCRYPTION_KEY=" ~ disk_encryption_key ~ "\n") |
| 34 | + |
| 35 | +- name: Save disk encryption key into a file |
2 | 36 | when: disk_encryption_key is defined |
3 | 37 | ansible.builtin.copy: |
4 | 38 | dest: /root/disk-encryption-key.txt |
|
8 | 42 | content: | |
9 | 43 | DISK_ENCRYPTION_KEY={{ disk_encryption_key }} |
10 | 44 |
|
| 45 | +- name: Ensure destination directory exists |
| 46 | + ansible.builtin.file: |
| 47 | + path: /opt/opencrvs/scripts/cryptfs |
| 48 | + state: directory |
| 49 | + mode: '0755' |
| 50 | + owner: root |
| 51 | + group: root |
| 52 | + recurse: yes |
| 53 | + |
| 54 | +- name: Install k8s-help script |
| 55 | + copy: |
| 56 | + src: ../cryptfs/decrypt.sh |
| 57 | + dest: "/opt/opencrvs/scripts/cryptfs/decrypt.sh" |
| 58 | + owner: "{{ ansible_user }}" |
| 59 | + group: 'application' |
| 60 | + mode: '0755' |
| 61 | + |
11 | 62 | - name: Copy reboot.service systemd file. Must decrypt disk on reboot |
12 | 63 | ansible.builtin.copy: |
13 | 64 | dest: /etc/systemd/system/reboot.service |
|
28 | 79 | - encryptedFileSystemPostCheck.stat.exists |
29 | 80 |
|
30 | 81 | - name: 'Setup systemd to mount encrypted folder' |
31 | | - when: disk_encryption_key is defined |
32 | 82 | shell: systemctl daemon-reload && systemctl enable reboot.service |
33 | 83 | when: |
34 | 84 | - disk_encryption_key is defined |
|
0 commit comments