Add ssl to vault
This commit is contained in:
parent
41c9283eb1
commit
add2a72c0a
4 changed files with 58 additions and 5 deletions
|
@ -20,7 +20,7 @@
|
||||||
group: consul
|
group: consul
|
||||||
mode: 0755
|
mode: 0755
|
||||||
|
|
||||||
- name: ensure consul config dir
|
- name: ensure consul certs dir
|
||||||
file:
|
file:
|
||||||
path: /etc/consul.d/certs/
|
path: /etc/consul.d/certs/
|
||||||
state: directory
|
state: directory
|
||||||
|
@ -42,7 +42,7 @@
|
||||||
args:
|
args:
|
||||||
executable: /bin/bash
|
executable: /bin/bash
|
||||||
environment:
|
environment:
|
||||||
VAULT_ADDR: http://ivyking.minhas.io:8200
|
VAULT_ADDR: http://vault.service.masked.name:8200
|
||||||
VAULT_TOKEN: "{{ lookup('file', lookup('env', 'HOME') + '/.vault-token') }}"
|
VAULT_TOKEN: "{{ lookup('file', lookup('env', 'HOME') + '/.vault-token') }}"
|
||||||
VAULT_FORMAT: json
|
VAULT_FORMAT: json
|
||||||
register: cert_data
|
register: cert_data
|
||||||
|
|
|
@ -7,3 +7,8 @@
|
||||||
systemd:
|
systemd:
|
||||||
name: vault
|
name: vault
|
||||||
state: restarted
|
state: restarted
|
||||||
|
|
||||||
|
- name: reload_vault
|
||||||
|
systemd:
|
||||||
|
name: vault
|
||||||
|
state: reloaded
|
||||||
|
|
|
@ -29,6 +29,55 @@
|
||||||
group: root
|
group: root
|
||||||
notify: daemon_reload
|
notify: daemon_reload
|
||||||
|
|
||||||
|
- name: ensure vault certs dir
|
||||||
|
file:
|
||||||
|
path: /etc/vault.d/certs/
|
||||||
|
state: directory
|
||||||
|
owner: vault
|
||||||
|
group: vault
|
||||||
|
mode: 0755
|
||||||
|
|
||||||
|
- name: check if server cert is expiring in the next 5 days
|
||||||
|
shell: "openssl x509 -checkend 432000 -noout -in /etc/vault.d/certs/vault.pem"
|
||||||
|
args:
|
||||||
|
executable: /bin/bash
|
||||||
|
failed_when: False
|
||||||
|
check_mode: False
|
||||||
|
changed_when: False
|
||||||
|
register: exp
|
||||||
|
|
||||||
|
- name: get cert
|
||||||
|
shell: "vault write pki_int/issue/{{ vault_pki_policy }} common_name=vault.service.{{ consul_domain }} alt_names=vault.service.{{ main_dc_name }}.{{ consul_domain }} ttl=43200m"
|
||||||
|
args:
|
||||||
|
executable: /bin/bash
|
||||||
|
environment:
|
||||||
|
VAULT_ADDR: http://vault.service.masked.name:8200
|
||||||
|
VAULT_TOKEN: "{{ lookup('file', lookup('env', 'HOME') + '/.vault-token') }}"
|
||||||
|
VAULT_FORMAT: json
|
||||||
|
register: cert_data
|
||||||
|
when: exp.rc != 0
|
||||||
|
notify: reload_vault
|
||||||
|
|
||||||
|
- name: write cert data to server
|
||||||
|
copy:
|
||||||
|
content: "{{ item.content }}"
|
||||||
|
dest: "/etc/vault.d/certs/{{ item.path }}"
|
||||||
|
mode: '{{ item.mode }}'
|
||||||
|
owner: vault
|
||||||
|
group: vault
|
||||||
|
when: cert_data.changed
|
||||||
|
loop:
|
||||||
|
- {
|
||||||
|
content: "{{ (cert_data.stdout | from_json).data.certificate }}",
|
||||||
|
path: "vault.pem",
|
||||||
|
mode: "0755"
|
||||||
|
}
|
||||||
|
- {
|
||||||
|
content: "{{ (cert_data.stdout | from_json).data.private_key }}",
|
||||||
|
path: "vault.key",
|
||||||
|
mode: "0600"
|
||||||
|
}
|
||||||
|
|
||||||
- name: template vault config
|
- name: template vault config
|
||||||
template:
|
template:
|
||||||
src: templates/vault.hcl.j2
|
src: templates/vault.hcl.j2
|
||||||
|
|
|
@ -1,9 +1,8 @@
|
||||||
ui = true
|
ui = true
|
||||||
listener "tcp" {
|
listener "tcp" {
|
||||||
address = "0.0.0.0:8200"
|
address = "0.0.0.0:8200"
|
||||||
tls_disable = true
|
tls_cert_file = "/etc/vault.d/certs/vault.pem"
|
||||||
# tls_cert_file = "/path/to/fullchain.pem"
|
tls_key_file = "/etc/vault.d/certs/vault.key"
|
||||||
# tls_key_file = "/path/to/privkey.pem"
|
|
||||||
}
|
}
|
||||||
storage "consul" {
|
storage "consul" {
|
||||||
address = "localhost:8500"
|
address = "localhost:8500"
|
||||||
|
|
Loading…
Reference in a new issue