Skip to content

Commit

Permalink
feat: use private folder for tls keys and harden perms of generated c…
Browse files Browse the repository at this point in the history
…ert/key when file perm hardening is enabled
  • Loading branch information
lakrass committed Dec 12, 2024
1 parent c643ee7 commit 889771c
Show file tree
Hide file tree
Showing 2 changed files with 16 additions and 3 deletions.
3 changes: 2 additions & 1 deletion defaults/main.yml
Original file line number Diff line number Diff line change
Expand Up @@ -292,7 +292,8 @@ vault_systemd_unit_path: /lib/systemd/system
validate_certs_during_api_reachable_check: true

vault_tls_certs_path: "{{ lookup('env', 'VAULT_TLS_DIR') | default(('/opt/vault/tls' if (vault_install_hashi_repo) else '/etc/vault/tls'), true) }}"
vault_tls_private_path: "{{ lookup('env', 'VAULT_TLS_DIR') | default(('/opt/vault/tls' if (vault_install_hashi_repo) else '/etc/vault/tls'), true) }}"
_vault_tls_private_path: "{{ lookup('env', 'VAULT_TLS_DIR') | default(('/opt/vault/tls' if (vault_install_hashi_repo) else '/etc/vault/tls'), true) }}"
vault_tls_private_path: "{{ _vault_tls_private_path ~ ('/private' if vault_harden_file_perms and vault_tls_copy_keys) }}"
vault_tls_src_files: "{{ lookup('env', 'VAULT_TLS_SRC_FILES') | default(role_path ~ '/files', true) }}"

vault_tls_disable: "{{ lookup('env', 'VAULT_TLS_DISABLE') | default(true, true) }}"
Expand Down
16 changes: 14 additions & 2 deletions tasks/install_hashi_repo.yml
Original file line number Diff line number Diff line change
Expand Up @@ -117,11 +117,23 @@
path: /etc/vault.d/vault.env
when: vault_harden_file_perms

- name: Delete default certs
- name: Harden perms of default cert/key
ansible.builtin.file:
path: "/opt/vault/tls/{{ item }}"
mode: "0400"
with_items:
- tls.crt
- tls.key
when:
- vault_harden_file_perms
- not vault_tls_disable
- not vault_tls_copy_keys

- name: Delete default cert/key
become: true
ansible.builtin.file:
state: absent
path: /opt/vault/tls/{{ item }}
path: "/opt/vault/tls/{{ item }}"
with_items:
- tls.crt
- tls.key
Expand Down

0 comments on commit 889771c

Please sign in to comment.