Skip to content

Commit 4630686

Browse files
committed
#1122 Deployer secrets handling
1 parent e331f2b commit 4630686

40 files changed

Lines changed: 240 additions & 379 deletions
Lines changed: 12 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,12 @@
1+
---
2+
- name: Exchange Hashicorp Vault token
3+
community.hashi_vault.vault_token_create:
4+
url: "{{ VAULT_URL | default(vault.vault_url) }}"
5+
auth_method: token
6+
token: '{{ VAULT_PASSWORD }}'
7+
ttl: 24h
8+
orphan: True
9+
register: _hashicorp_vault_token_create
10+
11+
- set_fact:
12+
_hashicorp_ephemeral_token: "{{ _hashicorp_vault_token_create.login.auth.client_token }}"
Lines changed: 15 additions & 13 deletions
Original file line numberDiff line numberDiff line change
@@ -1,17 +1,19 @@
11
---
2-
# - name: Load yaml files for vault configuration
3-
# include_vars:
4-
# dir: "{{ config_dir }}/config"
5-
# files_matching: '.*\.yaml$'
6-
7-
- name: Read vault config
8-
include_tasks: read-vault-config.yml
9-
when: vault | default({}) != {}
10-
112
- set_fact:
12-
vault_type: "file-vault"
13-
when: vault_type is not defined
3+
vault: "{{ _vault_default }}"
4+
when: vault | default({}) == {}
145

156
- set_fact:
16-
vault_authentication_type: "none"
17-
when: vault_authentication_type is not defined
7+
vault: "{{ vault | combine({'vault_authentication_type':'none'}) }}"
8+
when: vault.vault_authentication_type is not defined
9+
10+
- fail:
11+
msg: "For hashicorp-vault, either vault_url must be specified in the vault configuration, or VAULT_URL environment variable must be set"
12+
when:
13+
- vault.vault_type == 'hashicorp-vault'
14+
- (VAULT_URL | default(vault.vault_url) | default(''))== ''
15+
16+
- include_tasks: hashicorp-exchange-token.yml
17+
when:
18+
- vault.vault_type == 'hashicorp-vault'
19+
- vault.vault_exchange_token | default(False) | bool
Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,2 @@
1+
_vault_default:
2+
vault_type: file-vault

automation-roles/10-validation/validate-variables-destroy/tasks/main.yml

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -2,8 +2,8 @@
22
- name: Validate mandatory variables are defined
33
assert:
44
that:
5-
- vault_type is defined
6-
- vault_authentication_type is defined
5+
- vault.vault_type is defined
6+
- vault.vault_authentication_type is defined
77
- cloud_platform is defined
88

99
- name: Validate cloud_platform is supported

automation-roles/10-validation/validate-variables/tasks/main.yml

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -2,8 +2,8 @@
22
- name: Validate mandatory variables are defined
33
assert:
44
that:
5-
- vault_type is defined
6-
- vault_authentication_type is defined
5+
- vault.vault_type is defined
6+
- vault.vault_authentication_type is defined
77
- cloud_platform is defined
88

99
- name: Validate cloud_platform is supported

automation-roles/99-generic/vault/vault-connect/tasks/connect-ansible-vault.yml

Lines changed: 9 additions & 9 deletions
Original file line numberDiff line numberDiff line change
@@ -2,27 +2,27 @@
22
- name: Validate mandatory variables for Ansible Vault
33
assert:
44
that:
5-
- vault_password_file is defined
6-
- vault_password_file != ''
5+
- vault.vault_password_file is defined
6+
- vault.vault_password_file != ''
77
fail_msg: "vault_password_file must be defined for ansible-vault type"
88

99
- name: Check if Ansible Vault password file exists
1010
stat:
11-
path: "{{ vault_password_file }}"
12-
register: vault_password_file_stat
11+
path: "{{ vault.vault_password_file }}"
12+
register: _vault_password_file_stat
1313

1414
- name: Fail if Ansible Vault password file does not exist
1515
fail:
16-
msg: "Ansible Vault password file {{ vault_password_file }} does not exist"
17-
when: not vault_password_file_stat.stat.exists
16+
msg: "Ansible Vault password file {{ vault.vault_password_file }} does not exist"
17+
when: not _vault_password_file_stat.stat.exists
1818

1919
- name: Validate Ansible Vault password file is readable
2020
assert:
2121
that:
22-
- vault_password_file_stat.stat.readable
23-
fail_msg: "Ansible Vault password file {{ vault_password_file }} is not readable"
22+
- _vault_password_file_stat.stat.readable
23+
fail_msg: "Ansible Vault password file {{ vault.vault_password_file }} is not readable"
2424

2525
- name: Successfully connected to Ansible Vault
2626
debug:
27-
msg: "Successfully validated Ansible Vault password file: {{ vault_password_file }}"
27+
msg: "Successfully validated Ansible Vault password file: {{ vault.vault_password_file }}"
2828

Lines changed: 17 additions & 17 deletions
Original file line numberDiff line numberDiff line change
@@ -1,59 +1,59 @@
11
---
22

33
- name: Validate vault_type is supported
4-
fail: msg="Vault type {{ vault_type }} only support values {{ supported_vault_types }} "
5-
when: "vault_type not in supported_vault_types"
4+
fail: msg="Vault type {{ vault.vault_type }} only support values {{ supported_vault_types }} "
5+
when: vault.vault_type not in supported_vault_types
66

77
- name: Validate vault_authentication_type is supported
8-
fail: msg="Vault Authentication type (vault_authentication_type) only support values {{ supported_vault_authentication_types }} "
9-
when: "vault_authentication_type not in supported_vault_authentication_types"
8+
fail: msg="Vault Authentication type (vault_authentication_type) only supports values {{ supported_vault_authentication_types }} "
9+
when: vault.vault_authentication_type not in supported_vault_authentication_types
1010

1111
- name: Login to Hashicorp vault
1212
block:
1313
- name: Validate mandatory variables are defined
1414
assert:
1515
that:
16-
- vault_type is defined
17-
- vault_authentication_type is defined
16+
- vault.vault_type is defined
17+
- vault.vault_authentication_type is defined
1818
- debug:
19-
msg: "Hashicorp Vault URL: {{ vault_url }}"
20-
when: "vault_type == 'hashicorp-vault'"
19+
msg: "Hashicorp Vault URL: {{ VAULT_URL | default(vault.vault_url) }}"
20+
when: vault.vault_type == 'hashicorp-vault'
2121

2222
- name: Login to IBMCloud vault
2323
block:
2424

2525
- name: Validate mandatory variables are defined
2626
assert:
2727
that:
28-
- vault_type is defined
29-
- vault_authentication_type is defined
28+
- vault.vault_type is defined
29+
- vault.vault_authentication_type is defined
3030

3131
- include_tasks: connect-ibmcloud.yml
3232
vars:
33-
ibmcloud_vault_address: "{{ vault_url }}"
33+
ibmcloud_vault_address: "{{ vault.vault_url }}"
3434
ibmcloud_api_key: "{{ vault_api_key }}"
3535
ibmcloud_vault_group: "{{ vault_secret_group }}"
36-
when: "vault_type == 'ibmcloud-vault'"
36+
when: vault.vault_type == 'ibmcloud-vault'
3737

3838
- name: Login to file vault
3939
block:
4040
- name: No login to file fault needed
4141
debug:
4242
msg: File vault directory is {{ status_dir }}/vault
43-
when: "vault_type == 'file-vault'"
43+
when: vault.vault_type == 'file-vault'
4444

4545
- name: Login to Ansible vault
4646
block:
4747

4848
- name: Validate mandatory variables are defined
4949
assert:
5050
that:
51-
- vault_type is defined
52-
- vault_authentication_type is defined
51+
- vault.vault_type is defined
52+
- vault.vault_authentication_type is defined
5353

5454
- include_tasks: connect-ansible-vault.yml
55-
when: vault_authentication_type == 'password-file'
56-
when: "vault_type == 'ansible-vault'"
55+
when: vault.vault_authentication_type == 'password-file'
56+
when: vault.vault_type == 'ansible-vault'
5757

5858
- set_fact:
5959
vault_login_success: "true"

automation-roles/99-generic/vault/vault-delete-secret/tasks/delete-secret-file.yml

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -8,12 +8,12 @@
88
- name: Check that vault file {{ secret_group }} exists
99
stat:
1010
path: "{{ status_dir }}/vault/{{ secret_group }}"
11-
register: vault_file_details
11+
register: _vault_file_details
1212

1313
- name: Fail if the secret file was not found
1414
fail:
1515
msg: "File {{ status_dir }}/vault/{{ secret_group }} does not exist"
16-
when: not vault_file_details.stat.exists
16+
when: not v_ault_file_details.stat.exists
1717

1818
- name: Add or replace secret in file {{ status_dir }}/vault/{{ secret_group }}
1919
lineinfile:

automation-roles/99-generic/vault/vault-delete-secret/tasks/delete-secret-hashicorp-api-key.yml

Lines changed: 0 additions & 16 deletions
This file was deleted.

automation-roles/99-generic/vault/vault-delete-secret/tasks/delete-secret-hashicorp-certificate.yml

Lines changed: 8 additions & 12 deletions
Original file line numberDiff line numberDiff line change
@@ -8,15 +8,11 @@
88
- VAULT_CERT_CERT_FILE is defined
99
- hashicorp_secret_name_path is defined
1010

11-
- name: Delete the secret
12-
shell: |
13-
vault kv delete \
14-
-ca-cert={{ VAULT_CERT_CA_FILE }} \
15-
-client-cert={{ VAULT_CERT_CERT_FILE }} \
16-
-client-key={{ VAULT_CERT_KEY_FILE }} \
17-
-address={{ hashicorp_vault_address }} \
18-
{{ hashicorp_secret_name_path }}
19-
20-
- name: Successfully deleted secret
21-
debug:
22-
msg: "Secret {{ hashicorp_secret_name_path }} deleted..."
11+
- name: Delete secret {{ hashicorp_secret_name_path }}
12+
community.hashi_vault.vault_kv2_delete:
13+
url: "{{ hashicorp_vault_address }}"
14+
path: "{{ hashicorp_secret_name_path }}"
15+
auth_method: cert
16+
ca_cert: "{{ VAULT_CERT_CA_FILE }}"
17+
cert_auth_private_key: "{{ VAULT_CERT_KEY_FILE }}"
18+
cert_auth_public_key: "{{ VAULT_CERT_CERT_FILE }}"

0 commit comments

Comments
 (0)