Add ssl to vault

This commit is contained in:
Amarpreet Minhas 2020-10-12 21:59:24 -04:00
parent 41c9283eb1
commit add2a72c0a
4 changed files with 58 additions and 5 deletions

View file

@ -20,7 +20,7 @@
group: consul
mode: 0755
- name: ensure consul config dir
- name: ensure consul certs dir
file:
path: /etc/consul.d/certs/
state: directory
@ -42,7 +42,7 @@
args:
executable: /bin/bash
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_FORMAT: json
register: cert_data

View file

@ -7,3 +7,8 @@
systemd:
name: vault
state: restarted
- name: reload_vault
systemd:
name: vault
state: reloaded

View file

@ -29,6 +29,55 @@
group: root
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
template:
src: templates/vault.hcl.j2

View file

@ -1,9 +1,8 @@
ui = true
listener "tcp" {
address = "0.0.0.0:8200"
tls_disable = true
# tls_cert_file = "/path/to/fullchain.pem"
# tls_key_file = "/path/to/privkey.pem"
tls_cert_file = "/etc/vault.d/certs/vault.pem"
tls_key_file = "/etc/vault.d/certs/vault.key"
}
storage "consul" {
address = "localhost:8500"