You can not select more than 25 topics Topics must start with a letter or number, can include dashes ('-') and can be up to 35 characters long.

134 lines
5.5 KiB

  1. ---
  2. - import_tasks: sync_kube_master_certs.yml
  3. when: inventory_hostname in groups['kube-master']
  4. - import_tasks: sync_kube_node_certs.yml
  5. when: inventory_hostname in groups['k8s-cluster']
  6. # Issue admin certs to kube-master hosts
  7. - include_tasks: ../../../vault/tasks/shared/issue_cert.yml
  8. vars:
  9. issue_cert_common_name: "admin"
  10. issue_cert_copy_ca: "{{ item == kube_admin_certs_needed|first }}"
  11. issue_cert_file_group: "{{ kube_cert_group }}"
  12. issue_cert_file_owner: kube
  13. issue_cert_hosts: "{{ groups['kube-master'] }}"
  14. issue_cert_path: "{{ item }}"
  15. issue_cert_role: kube-master
  16. issue_cert_url: "{{ hostvars[groups.vault|first]['vault_leader_url'] }}"
  17. issue_cert_mount_path: "{{ kube_vault_mount_path }}"
  18. with_items: "{{ kube_admin_certs_needed|d([]) }}"
  19. when: inventory_hostname in groups['kube-master']
  20. - name: gen_certs_vault | Set fact about certificate alt names
  21. set_fact:
  22. kube_cert_alt_names: >-
  23. {{
  24. groups['kube-master'] +
  25. ['kubernetes.default.svc.'+cluster_name, 'kubernetes.default.svc', 'kubernetes.default', 'kubernetes'] +
  26. ['localhost']
  27. }}
  28. run_once: true
  29. - name: gen_certs_vault | Add external load balancer domain name to certificate alt names
  30. set_fact:
  31. kube_cert_alt_names: "{{ kube_cert_alt_names + [apiserver_loadbalancer_domain_name] }}"
  32. when: loadbalancer_apiserver is defined
  33. run_once: true
  34. # Issue master components certs to kube-master hosts
  35. - include_tasks: ../../../vault/tasks/shared/issue_cert.yml
  36. vars:
  37. issue_cert_common_name: "kubernetes"
  38. issue_cert_alt_names: "{{ kube_cert_alt_names }}"
  39. issue_cert_file_group: "{{ kube_cert_group }}"
  40. issue_cert_file_owner: kube
  41. issue_cert_hosts: "{{ groups['kube-master'] }}"
  42. issue_cert_run_once: true
  43. issue_cert_ip_sans: >-
  44. [
  45. {%- for host in groups['kube-master'] -%}
  46. "{{ hostvars[host]['ansible_default_ipv4']['address'] }}",
  47. {%- if hostvars[host]['ip'] is defined -%}
  48. "{{ hostvars[host]['ip'] }}",
  49. {%- endif -%}
  50. {%- endfor -%}
  51. {%- if supplementary_addresses_in_ssl_keys is defined -%}
  52. {%- for ip_item in supplementary_addresses_in_ssl_keys -%}
  53. "{{ ip_item }}",
  54. {%- endfor -%}
  55. {%- endif -%}
  56. "127.0.0.1","::1","{{ kube_apiserver_ip }}"
  57. ]
  58. issue_cert_path: "{{ item }}"
  59. issue_cert_role: kube-master
  60. issue_cert_url: "{{ hostvars[groups.vault|first]['vault_leader_url'] }}"
  61. issue_cert_mount_path: "{{ kube_vault_mount_path }}"
  62. with_items: "{{ kube_master_components_certs_needed|d([]) }}"
  63. when: inventory_hostname in groups['kube-master']
  64. notify: set secret_changed
  65. # Issue node certs to k8s-cluster nodes
  66. - include_tasks: ../../../vault/tasks/shared/issue_cert.yml
  67. vars:
  68. # Need to strip out the 'node-' prefix from the cert name so it can be used
  69. # with the node authorization plugin ( CN matches kubelet node name )
  70. issue_cert_common_name: "system:node:{{ item.rsplit('/', 1)[1].rsplit('.', 1)[0] | regex_replace('^node-', '') }}"
  71. issue_cert_copy_ca: "{{ item == kube_node_certs_needed|first }}"
  72. issue_cert_file_group: "{{ kube_cert_group }}"
  73. issue_cert_file_owner: kube
  74. issue_cert_hosts: "{{ groups['k8s-cluster'] }}"
  75. issue_cert_path: "{{ item }}"
  76. issue_cert_role: kube-node
  77. issue_cert_url: "{{ hostvars[groups.vault|first]['vault_leader_url'] }}"
  78. issue_cert_mount_path: "{{ kube_vault_mount_path }}"
  79. with_items: "{{ kube_node_certs_needed|d([]) }}"
  80. when: inventory_hostname in groups['k8s-cluster']
  81. # Issue proxy certs to k8s-cluster nodes
  82. - include_tasks: ../../../vault/tasks/shared/issue_cert.yml
  83. vars:
  84. issue_cert_common_name: "system:kube-proxy"
  85. issue_cert_copy_ca: "{{ item == kube_proxy_certs_needed|first }}"
  86. issue_cert_file_group: "{{ kube_cert_group }}"
  87. issue_cert_file_owner: kube
  88. issue_cert_hosts: "{{ groups['k8s-cluster'] }}"
  89. issue_cert_path: "{{ item }}"
  90. issue_cert_role: kube-proxy
  91. issue_cert_url: "{{ hostvars[groups.vault|first]['vault_leader_url'] }}"
  92. issue_cert_mount_path: "{{ kube_vault_mount_path }}"
  93. with_items: "{{ kube_proxy_certs_needed|d([]) }}"
  94. when: inventory_hostname in groups['k8s-cluster']
  95. # Issue front proxy cert to kube-master hosts
  96. - include_tasks: ../../../vault/tasks/shared/issue_cert.yml
  97. vars:
  98. issue_cert_common_name: "front-proxy-client"
  99. issue_cert_copy_ca: "{{ item == kube_front_proxy_clients_certs_needed|first }}"
  100. issue_cert_ca_filename: front-proxy-ca.pem
  101. issue_cert_alt_names: "{{ kube_cert_alt_names }}"
  102. issue_cert_file_group: "{{ kube_cert_group }}"
  103. issue_cert_file_owner: kube
  104. issue_cert_hosts: "{{ groups['kube-master'] }}"
  105. issue_cert_ip_sans: >-
  106. [
  107. {%- for host in groups['kube-master'] -%}
  108. "{{ hostvars[host]['ansible_default_ipv4']['address'] }}",
  109. {%- if hostvars[host]['ip'] is defined -%}
  110. "{{ hostvars[host]['ip'] }}",
  111. {%- endif -%}
  112. {%- endfor -%}
  113. {%- if supplementary_addresses_in_ssl_keys is defined -%}
  114. {%- for ip_item in supplementary_addresses_in_ssl_keys -%}
  115. "{{ ip_item }}",
  116. {%- endfor -%}
  117. {%- endif -%}
  118. "127.0.0.1","::1","{{ kube_apiserver_ip }}"
  119. ]
  120. issue_cert_path: "{{ item }}"
  121. issue_cert_role: front-proxy-client
  122. issue_cert_url: "{{ hostvars[groups.vault|first]['vault_leader_url'] }}"
  123. issue_cert_mount_path: "{{ kube_vault_mount_path }}"
  124. with_items: "{{ kube_front_proxy_clients_certs_needed|d([]) }}"
  125. when: inventory_hostname in groups['kube-master']
  126. notify: set secret_changed