Browse Source
refactor vault role (#2733)
refactor vault role (#2733)
* Move front-proxy-client certs back to kube mount We want the same CA for all k8s certs * Refactor vault to use a third party module The module adds idempotency and reduces some of the repetitive logic in the vault role Requires ansible-modules-hashivault on ansible node and hvac on the vault hosts themselves Add upgrade test scenario Remove bootstrap-os tags from tasks * fix upgrade issues * improve unseal logic * specify ca and fix etcd check * Fix initialization check bump machine sizepull/2765/head
committed by
GitHub
No known key found for this signature in database
GPG Key ID: 4AEE18F83AFDEB23
49 changed files with 436 additions and 374 deletions
Unified View
Diff Options
-
17.gitlab-ci.yml
-
6requirements.txt
-
1roles/bootstrap-os/tasks/bootstrap-ubuntu.yml
-
4roles/dnsmasq/tasks/main.yml
-
2roles/download/defaults/main.yml
-
2roles/etcd/defaults/main.yml
-
3roles/kubernetes/master/defaults/main.yml
-
7roles/kubernetes/master/templates/manifests/kube-apiserver.manifest.j2
-
20roles/kubernetes/node/defaults/main.yml
-
1roles/kubernetes/preinstall/tasks/set_facts.yml
-
3roles/kubernetes/secrets/defaults/main.yml
-
2roles/kubernetes/secrets/tasks/gen_certs_script.yml
-
2roles/kubernetes/secrets/tasks/gen_certs_vault.yml
-
2roles/kubernetes/secrets/tasks/main.yml
-
68roles/vault/defaults/main.yml
-
50roles/vault/handlers/main.yml
-
3roles/vault/tasks/bootstrap/create_mounts.yml
-
2roles/vault/tasks/bootstrap/create_roles.yml
-
2roles/vault/tasks/bootstrap/gen_vault_certs.yml
-
20roles/vault/tasks/bootstrap/main.yml
-
31roles/vault/tasks/bootstrap/start_vault_temp.yml
-
2roles/vault/tasks/bootstrap/sync_etcd_certs.yml
-
12roles/vault/tasks/bootstrap/sync_secrets.yml
-
17roles/vault/tasks/bootstrap/sync_vault_certs.yml
-
2roles/vault/tasks/cluster/binary.yml
-
15roles/vault/tasks/cluster/configure.yml
-
5roles/vault/tasks/cluster/create_mounts.yml
-
2roles/vault/tasks/cluster/create_roles.yml
-
46roles/vault/tasks/cluster/init.yml
-
18roles/vault/tasks/cluster/main.yml
-
35roles/vault/tasks/cluster/systemd.yml
-
27roles/vault/tasks/cluster/unseal.yml
-
5roles/vault/tasks/main.yml
-
28roles/vault/tasks/shared/auth_backend.yml
-
15roles/vault/tasks/shared/cert_auth_mount.yml
-
5roles/vault/tasks/shared/check_etcd.yml
-
42roles/vault/tasks/shared/check_vault.yml
-
30roles/vault/tasks/shared/config_ca.yml
-
66roles/vault/tasks/shared/create_role.yml
-
6roles/vault/tasks/shared/find_leader.yml
-
31roles/vault/tasks/shared/gen_ca.yml
-
19roles/vault/tasks/shared/gen_userpass.yml
-
74roles/vault/tasks/shared/issue_cert.yml
-
35roles/vault/tasks/shared/pki_mount.yml
-
1roles/vault/tasks/shared/sync.yml
-
1roles/vault/tasks/shared/sync_file.yml
-
6roles/vault/templates/docker.service.j2
-
4roles/vault/templates/rkt.service.j2
-
13tests/files/gce_coreos-vault-upgrade.yml
@ -1,4 +1,6 @@ |
|||||
pbr>=1.6 |
|
||||
ansible>=2.4.0 |
ansible>=2.4.0 |
||||
netaddr |
|
||||
jinja2>=2.9.6 |
jinja2>=2.9.6 |
||||
|
netaddr |
||||
|
pbr>=1.6 |
||||
|
ansible-modules-hashivault>=3.9.4 |
||||
|
hvac |
@ -1,4 +1,3 @@ |
|||||
--- |
--- |
||||
kube_cert_group: kube-cert |
kube_cert_group: kube-cert |
||||
kube_vault_mount_path: kube |
|
||||
front_proxy_vault_mount_path: front-proxy |
|
||||
|
kube_vault_mount_path: "/kube" |
@ -0,0 +1,50 @@ |
|||||
|
--- |
||||
|
- name: restart vault |
||||
|
command: /bin/true |
||||
|
notify: |
||||
|
- restart vault service |
||||
|
- set facts about local Vault health |
||||
|
- unseal vault |
||||
|
|
||||
|
- name: wait for vault up |
||||
|
uri: |
||||
|
url: "{{ vault_leader_url | default('https://localhost:8200') }}/v1/sys/health" |
||||
|
headers: "{{ vault_client_headers }}" |
||||
|
status_code: "{{ vault_successful_http_codes | join(',') }}" |
||||
|
register: vault_health_check |
||||
|
until: vault_health_check|succeeded |
||||
|
retries: 10 |
||||
|
delay: "{{ retry_stagger | random + 3 }}" |
||||
|
run_once: yes |
||||
|
notify: set facts about local Vault health |
||||
|
|
||||
|
- name: wait for vault up nowait |
||||
|
uri: |
||||
|
url: "{{ vault_leader_url | default('https://localhost:8200') }}/v1/sys/health" |
||||
|
headers: "{{ vault_client_headers }}" |
||||
|
status_code: "{{ vault_successful_http_codes | join(',') }}" |
||||
|
register: vault_health_check |
||||
|
run_once: yes |
||||
|
failed_when: false |
||||
|
notify: set facts about local Vault health |
||||
|
|
||||
|
- name: set facts about local Vault health |
||||
|
set_fact: |
||||
|
vault_is_running: "{{ vault_health_check.get('status', '-1') in vault_successful_http_codes }}" |
||||
|
vault_cluster_is_initialized: "{{ vault_health_check.get('json', {}).get('initialized', false) }}" |
||||
|
vault_is_sealed: "{{ vault_health_check.get('json', {}).get('sealed', true) }}" |
||||
|
|
||||
|
- name: restart vault service |
||||
|
systemd: |
||||
|
daemon_reload: true |
||||
|
enabled: yes |
||||
|
name: vault |
||||
|
state: restarted |
||||
|
|
||||
|
- name: unseal vault |
||||
|
hashivault_unseal: |
||||
|
url: "{{ vault_leader_url | default('https://localhost:8200') }}" |
||||
|
token: "{{ vault_root_token }}" |
||||
|
ca_cert: "{{ vault_cert_dir }}/ca.pem" |
||||
|
keys: "{{ item }}" |
||||
|
with_items: "{{ vault_unseal_keys|default([]) }}" |
@ -1,12 +1,13 @@ |
|||||
--- |
--- |
||||
- include_tasks: ../shared/create_mount.yml |
- include_tasks: ../shared/create_mount.yml |
||||
vars: |
vars: |
||||
create_mount_path: "{{ item.name }}" |
|
||||
|
create_mount_path: "/{{ item.name }}" |
||||
create_mount_default_lease_ttl: "{{ item.default_lease_ttl }}" |
create_mount_default_lease_ttl: "{{ item.default_lease_ttl }}" |
||||
create_mount_max_lease_ttl: "{{ item.max_lease_ttl }}" |
create_mount_max_lease_ttl: "{{ item.max_lease_ttl }}" |
||||
create_mount_description: "{{ item.description }}" |
create_mount_description: "{{ item.description }}" |
||||
create_mount_cert_dir: "{{ item.cert_dir }}" |
create_mount_cert_dir: "{{ item.cert_dir }}" |
||||
create_mount_config_ca_needed: "{{ item.config_ca }}" |
create_mount_config_ca_needed: "{{ item.config_ca }}" |
||||
with_items: |
with_items: |
||||
|
- "{{ vault_pki_mounts.userpass|combine({'config_ca': not vault_ca_cert_needed}) }}" |
||||
- "{{ vault_pki_mounts.vault|combine({'config_ca': not vault_ca_cert_needed}) }}" |
- "{{ vault_pki_mounts.vault|combine({'config_ca': not vault_ca_cert_needed}) }}" |
||||
- "{{ vault_pki_mounts.etcd|combine({'config_ca': not vault_etcd_ca_cert_needed}) }}" |
- "{{ vault_pki_mounts.etcd|combine({'config_ca': not vault_etcd_ca_cert_needed}) }}" |
@ -1,14 +1,13 @@ |
|||||
--- |
--- |
||||
- include_tasks: ../shared/create_mount.yml |
- include_tasks: ../shared/create_mount.yml |
||||
vars: |
vars: |
||||
create_mount_path: "{{ item.name }}" |
|
||||
|
create_mount_path: "/{{ item.name }}" |
||||
create_mount_default_lease_ttl: "{{ item.default_lease_ttl }}" |
create_mount_default_lease_ttl: "{{ item.default_lease_ttl }}" |
||||
create_mount_max_lease_ttl: "{{ item.max_lease_ttl }}" |
create_mount_max_lease_ttl: "{{ item.max_lease_ttl }}" |
||||
create_mount_description: "{{ item.description }}" |
create_mount_description: "{{ item.description }}" |
||||
create_mount_cert_dir: "{{ item.cert_dir }}" |
create_mount_cert_dir: "{{ item.cert_dir }}" |
||||
create_mount_config_ca_needed: item.name != vault_pki_mounts.kube.name and item.name != vault_pki_mounts.front_proxy.name |
|
||||
|
create_mount_config_ca_needed: item.name != vault_pki_mounts.kube.name |
||||
with_items: |
with_items: |
||||
- "{{ vault_pki_mounts.vault }}" |
- "{{ vault_pki_mounts.vault }}" |
||||
- "{{ vault_pki_mounts.etcd }}" |
- "{{ vault_pki_mounts.etcd }}" |
||||
- "{{ vault_pki_mounts.kube }}" |
- "{{ vault_pki_mounts.kube }}" |
||||
- "{{ vault_pki_mounts.front_proxy }}" |
|
@ -1,25 +1,16 @@ |
|||||
--- |
--- |
||||
|
|
||||
- name: cluster/unseal | Current sealed state |
- name: cluster/unseal | Current sealed state |
||||
debug: " Sealed? {{vault_is_sealed}}" |
|
||||
|
debug: |
||||
|
msg: "Sealed? {{ vault_is_sealed }}" |
||||
|
|
||||
- name: cluster/unseal | Unseal Vault |
- name: cluster/unseal | Unseal Vault |
||||
uri: |
|
||||
url: "https://localhost:{{ vault_port }}/v1/sys/unseal" |
|
||||
headers: "{{ vault_headers }}" |
|
||||
method: POST |
|
||||
body_format: json |
|
||||
body: |
|
||||
key: "{{ item }}" |
|
||||
|
hashivault_unseal: |
||||
|
url: "https://localhost:{{ vault_port }}/" |
||||
|
token: "{{ vault_root_token }}" |
||||
|
ca_cert: "{{ vault_cert_dir }}/ca.pem" |
||||
|
keys: "{{ item }}" |
||||
|
no_log: true |
||||
with_items: "{{ vault_unseal_keys|default([]) }}" |
with_items: "{{ vault_unseal_keys|default([]) }}" |
||||
|
notify: wait for vault up |
||||
when: vault_is_sealed |
when: vault_is_sealed |
||||
|
|
||||
- name: cluster/unseal | Wait until server is ready |
|
||||
uri: |
|
||||
url: "https://localhost:{{ vault_port }}/v1/sys/health" |
|
||||
headers: "{{ vault_headers }}" |
|
||||
method: HEAD |
|
||||
status_code: 200, 429 |
|
||||
register: vault_node_ready |
|
||||
until: vault_node_ready|succeeded |
|
||||
retries: 5 |
|
@ -1,20 +1,10 @@ |
|||||
--- |
--- |
||||
- name: shared/auth_backend | Test if the auth backend exists |
|
||||
uri: |
|
||||
url: "{{ vault_leader_url }}/v1/sys/auth/{{ auth_backend_path }}/tune" |
|
||||
headers: "{{ vault_headers }}" |
|
||||
validate_certs: false |
|
||||
ignore_errors: true |
|
||||
register: vault_auth_backend_check |
|
||||
|
|
||||
- name: shared/auth_backend | Add the cert auth backend if needed |
|
||||
uri: |
|
||||
url: "{{ vault_leader_url }}/v1/sys/auth/{{ auth_backend_path }}" |
|
||||
headers: "{{ vault_headers }}" |
|
||||
method: POST |
|
||||
body_format: json |
|
||||
body: |
|
||||
description: "{{ auth_backend_description|d('') }}" |
|
||||
type: "{{ auth_backend_type }}" |
|
||||
status_code: 204 |
|
||||
when: vault_auth_backend_check|failed |
|
||||
|
- name: shared/auth_backend | Enable auth backend {{ auth_backend_path }} |
||||
|
hashivault_auth_enable: |
||||
|
url: "{{ vault_leader_url }}" |
||||
|
token: "{{ vault_root_token }}" |
||||
|
ca_cert: "{{ vault_cert_dir }}/ca.pem" |
||||
|
name: "{{ auth_backend_type }}" |
||||
|
mount_point: "{{ auth_backend_path }}" |
||||
|
description: "{{ auth_backend_description|d('') }}" |
||||
|
register: result |
@ -1,35 +1,38 @@ |
|||||
--- |
--- |
||||
- name: "bootstrap/gen_ca | Ensure cert_dir {{ gen_ca_cert_dir }} exists" |
|
||||
|
- name: "bootstrap/gen_ca | Ensure cert_dir {{ gen_ca_cert_dir }} exists on necessary hosts" |
||||
file: |
file: |
||||
mode: 0755 |
mode: 0755 |
||||
path: "{{ gen_ca_cert_dir }}" |
path: "{{ gen_ca_cert_dir }}" |
||||
state: directory |
state: directory |
||||
|
delegate_to: "{{ item }}" |
||||
|
with_items: "{{ (groups[gen_ca_copy_group|default('vault')]) | union(groups['vault']) }}" |
||||
|
|
||||
- name: "bootstrap/gen_ca | Generate {{ gen_ca_mount_path }} root CA" |
- name: "bootstrap/gen_ca | Generate {{ gen_ca_mount_path }} root CA" |
||||
uri: |
|
||||
url: "{{ vault_leader_url }}/v1/{{ gen_ca_mount_path }}/root/generate/exported" |
|
||||
headers: "{{ gen_ca_vault_headers }}" |
|
||||
method: POST |
|
||||
body_format: json |
|
||||
body: "{{ gen_ca_vault_options }}" |
|
||||
status_code: 200,204 |
|
||||
register: vault_ca_gen |
|
||||
delegate_to: "{{ groups.vault|first }}" |
|
||||
|
hashivault_write: |
||||
|
url: "{{ vault_leader_url }}" |
||||
|
token: "{{ vault_root_token }}" |
||||
|
ca_cert: "{{ vault_cert_dir }}/ca.pem" |
||||
|
secret: "{{ gen_ca_mount_path }}/root/generate/exported" |
||||
|
data: "{{ gen_ca_vault_options }}" |
||||
run_once: true |
run_once: true |
||||
|
no_log: true |
||||
|
register: vault_ca_gen |
||||
|
|
||||
- name: "bootstrap/gen_ca | Copy {{ gen_ca_mount_path }} root CA cert locally" |
- name: "bootstrap/gen_ca | Copy {{ gen_ca_mount_path }} root CA cert locally" |
||||
copy: |
copy: |
||||
content: "{{ hostvars[groups.vault|first]['vault_ca_gen']['json']['data']['certificate'] }}" |
|
||||
|
content: "{{ vault_ca_gen['data']['data']['certificate'] }}" |
||||
dest: "{{ gen_ca_cert_dir }}/ca.pem" |
dest: "{{ gen_ca_cert_dir }}/ca.pem" |
||||
mode: 0644 |
mode: 0644 |
||||
when: vault_ca_gen.status == 200 |
|
||||
|
when: '"data" in vault_ca_gen.keys()' |
||||
|
delegate_to: "{{ item }}" |
||||
|
with_items: "{{ (groups[gen_ca_copy_group|default('vault')]) | union(groups['vault']) }}" |
||||
|
|
||||
|
|
||||
- name: "bootstrap/gen_ca | Copy {{ gen_ca_mount_path }} root CA key to necessary hosts" |
- name: "bootstrap/gen_ca | Copy {{ gen_ca_mount_path }} root CA key to necessary hosts" |
||||
copy: |
copy: |
||||
content: "{{ hostvars[groups.vault|first]['vault_ca_gen']['json']['data']['private_key'] }}" |
|
||||
|
content: "{{ vault_ca_gen['data']['data']['private_key']}}" |
||||
dest: "{{ gen_ca_cert_dir }}/ca-key.pem" |
dest: "{{ gen_ca_cert_dir }}/ca-key.pem" |
||||
mode: 0640 |
mode: 0640 |
||||
when: vault_ca_gen.status == 200 |
|
||||
|
when: '"data" in vault_ca_gen.keys()' |
||||
delegate_to: "{{ item }}" |
delegate_to: "{{ item }}" |
||||
with_items: "{{ (groups[gen_ca_copy_group|default('vault')]) | union(groups['vault']) }}" |
with_items: "{{ (groups[gen_ca_copy_group|default('vault')]) | union(groups['vault']) }}" |
@ -1,27 +1,12 @@ |
|||||
--- |
--- |
||||
- name: "shared/mount | Test if {{ pki_mount_path }} PKI mount exists" |
|
||||
uri: |
|
||||
url: "{{ vault_leader_url }}/v1/sys/mounts/{{ pki_mount_path }}/tune" |
|
||||
headers: "{{ vault_headers }}" |
|
||||
ignore_errors: true |
|
||||
register: vault_pki_mount_check |
|
||||
|
|
||||
- name: shared/mount | Set pki mount type |
|
||||
set_fact: |
|
||||
mount_options: "{{ pki_mount_options | combine({'type': 'pki'}) }}" |
|
||||
when: vault_pki_mount_check|failed |
|
||||
|
|
||||
- name: shared/mount | Mount {{ pki_mount_path }} PKI mount if needed |
|
||||
uri: |
|
||||
url: "{{ vault_leader_url }}/v1/sys/mounts/{{ pki_mount_path }}" |
|
||||
headers: "{{ vault_headers }}" |
|
||||
method: POST |
|
||||
body_format: json |
|
||||
body: "{{ mount_options|d() }}" |
|
||||
status_code: 204 |
|
||||
when: vault_pki_mount_check|failed |
|
||||
|
|
||||
- name: shared/mount | Unset mount options |
|
||||
set_fact: |
|
||||
mount_options: {} |
|
||||
when: vault_pki_mount_check|failed |
|
||||
|
- name: shared/mount | Enable {{ pki_mount_path }} PKI mount |
||||
|
hashivault_secret_enable: |
||||
|
url: "{{ vault_leader_url }}" |
||||
|
token: "{{ vault_root_token }}" |
||||
|
ca_cert: "{{ vault_cert_dir }}/ca.pem" |
||||
|
name: "{{ pki_mount_path }}" |
||||
|
backend: "pki" |
||||
|
config: "{{ pki_mount_options }}" |
||||
|
register: secret_enable_result |
||||
|
failed_when: 'secret_enable_result.rc !=0 and "existing mount" not in secret_enable_result.msg' |
@ -0,0 +1,13 @@ |
|||||
|
# Instance settings |
||||
|
cloud_machine_type: "n1-standard-4" |
||||
|
cloud_image_family: coreos-stable |
||||
|
cloud_region: us-central1-b |
||||
|
mode: aio |
||||
|
|
||||
|
# Instance settings |
||||
|
bootstrap_os: coreos |
||||
|
cert_management: vault |
||||
|
kube_network_plugin: flannel |
||||
|
deploy_netchecker: true |
||||
|
kubedns_min_replicas: 1 |
||||
|
cloud_provider: gce |
Write
Preview
Loading…
Cancel
Save