-
Notifications
You must be signed in to change notification settings - Fork 69
feat: Verify passphrase before provision new one #1136
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
Merged
Merged
Changes from all commits
Commits
Show all changes
2 commits
Select commit
Hold shift + click to select a range
File filter
Filter by extension
Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
There are no files selected for viewing
This file contains hidden or 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 hidden or 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 hidden or 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 |
|---|---|---|
| @@ -1,4 +1,38 @@ | ||
| - name: Save disk encryption key into a file as an example (in production use a hardware security module) | ||
| - name: Ensure 'cryptsetup' utility is installed | ||
|
Contributor
Author
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. Nice to have this check |
||
| ansible.builtin.package: | ||
| name: cryptsetup | ||
| state: present | ||
| when: disk_encryption_key is defined | ||
|
|
||
| - name: 'Register encrypted file system' | ||
| stat: | ||
| path: /cryptfs_file_sparse.img | ||
| get_checksum: False | ||
| register: encryptedFileSystemPostCheck | ||
| when: disk_encryption_key is defined | ||
|
|
||
| - name: Check if Disk encryption key file exists | ||
| ansible.builtin.stat: | ||
| path: /root/disk-encryption-key.txt | ||
| register: encryption_keyfile_stat | ||
| when: disk_encryption_key is defined | ||
|
|
||
| - name: Read existing Disk encryption key | ||
| ansible.builtin.slurp: | ||
| src: /root/disk-encryption-key.txt | ||
| register: existing_disk_encryption_key | ||
| when: | ||
| - disk_encryption_key is defined | ||
| - encryption_keyfile_stat.stat.exists | ||
|
|
||
| - name: Fail if key exists and differs | ||
| ansible.builtin.fail: | ||
| msg: "Disk encryption key on disk does not match ansible variable! GitHub secret ENCRYPTION_KEY was updated!" | ||
| when: | ||
| - encryption_keyfile_stat.stat.exists | ||
| - existing_disk_encryption_key['content'] | b64decode != ("DISK_ENCRYPTION_KEY=" ~ disk_encryption_key ~ "\n") | ||
|
|
||
| - name: Save disk encryption key into a file | ||
| when: disk_encryption_key is defined | ||
| ansible.builtin.copy: | ||
| dest: /root/disk-encryption-key.txt | ||
|
|
@@ -8,6 +42,23 @@ | |
| content: | | ||
| DISK_ENCRYPTION_KEY={{ disk_encryption_key }} | ||
|
|
||
| - name: Ensure destination directory exists | ||
| ansible.builtin.file: | ||
| path: /opt/opencrvs/scripts/cryptfs | ||
| state: directory | ||
| mode: '0755' | ||
| owner: root | ||
| group: root | ||
| recurse: yes | ||
|
|
||
| - name: Install k8s-help script | ||
| copy: | ||
| src: ../cryptfs/decrypt.sh | ||
| dest: "/opt/opencrvs/scripts/cryptfs/decrypt.sh" | ||
| owner: "{{ ansible_user }}" | ||
| group: 'application' | ||
| mode: '0755' | ||
|
|
||
| - name: Copy reboot.service systemd file. Must decrypt disk on reboot | ||
| ansible.builtin.copy: | ||
| dest: /etc/systemd/system/reboot.service | ||
|
|
@@ -28,7 +79,6 @@ | |
| - encryptedFileSystemPostCheck.stat.exists | ||
|
|
||
| - name: 'Setup systemd to mount encrypted folder' | ||
| when: disk_encryption_key is defined | ||
| shell: systemctl daemon-reload && systemctl enable reboot.service | ||
| when: | ||
| - disk_encryption_key is defined | ||
|
|
||
26 changes: 26 additions & 0 deletions
26
infrastructure/server-setup/tasks/validate-data-partition.yml
This file contains hidden or 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,26 @@ | ||
| - name: Verify LUKS disk encryption key | ||
| when: disk_encryption_key is defined | ||
| block: | ||
| - name: Backup LUKS header | ||
| shell: | | ||
| loop_device=$(losetup -j /cryptfs_file_sparse.img | cut -d: -f1) | ||
| rm -vf /tmp/luks-header.img | ||
| cryptsetup luksHeaderBackup $loop_device --header-backup-file /tmp/luks-header.img | ||
|
|
||
| - name: Test disk encryption key for LUKS header | ||
| when: disk_encryption_key is defined | ||
| shell: 'echo "{{ disk_encryption_key }}" | cryptsetup -d - luksOpen /tmp/luks-header.img test --test-passphrase' | ||
| register: luks_test | ||
|
|
||
| - name: Display success message | ||
| debug: | ||
| msg: "✓ LUKS passphrase test successful - the disk encryption key is valid: {{ luks_test.stdout }}" | ||
| rescue: | ||
| - name: DO NOT REBOOT the SERVER | ||
| fail: | ||
| msg: | | ||
| {% if luks_test.rc == 2 and 'No key available with this passphrase' in luks_test.stderr -%} | ||
| LUKS passphrase test failed: Please make sure your key in GitHub secret is correct. Otherwise system will not be able to decrypt /data. MAKE SURE DATA BACKUP IS RESTORABLE BEFORE SERVER REBOOT. | ||
| {%- else -%} | ||
| cryptsetup error (RC: {{ luks_test.rc }}) - {{ luks_test.stderr | default('Unknown error') }} | ||
| {%- endif %} |
Oops, something went wrong.
Add this suggestion to a batch that can be applied as a single commit.
This suggestion is invalid because no changes were made to the code.
Suggestions cannot be applied while the pull request is closed.
Suggestions cannot be applied while viewing a subset of changes.
Only one suggestion per line can be applied in a batch.
Add this suggestion to a batch that can be applied as a single commit.
Applying suggestions on deleted lines is not supported.
You must change the existing code in this line in order to create a valid suggestion.
Outdated suggestions cannot be applied.
This suggestion has been applied or marked resolved.
Suggestions cannot be applied from pending reviews.
Suggestions cannot be applied on multi-line comments.
Suggestions cannot be applied while the pull request is queued to merge.
Suggestion cannot be applied right now. Please check back later.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
This validation step should be executed for
data-partitionand fordecrypt-on-boot