summaryrefslogtreecommitdiff
path: root/roles/kubernetes/addons/node-feature-discovery/tasks/tls-worker.yml
diff options
context:
space:
mode:
Diffstat (limited to 'roles/kubernetes/addons/node-feature-discovery/tasks/tls-worker.yml')
-rw-r--r--roles/kubernetes/addons/node-feature-discovery/tasks/tls-worker.yml79
1 files changed, 79 insertions, 0 deletions
diff --git a/roles/kubernetes/addons/node-feature-discovery/tasks/tls-worker.yml b/roles/kubernetes/addons/node-feature-discovery/tasks/tls-worker.yml
new file mode 100644
index 00000000..888c0872
--- /dev/null
+++ b/roles/kubernetes/addons/node-feature-discovery/tasks/tls-worker.yml
@@ -0,0 +1,79 @@
+---
+- name: create certs directory for nfd-worker
+ file:
+ path: /etc/kubernetes/node-feature-discovery/certs
+ state: directory
+ owner: nobody
+ group: root
+ mode: 0500
+
+- name: install CA certificate
+ copy:
+ content: "{{ node_feature_discovery_ca_certificate.content | b64decode }}"
+ dest: /etc/kubernetes/node-feature-discovery/certs/ca.crt
+
+- name: create private key for worker certificate
+ openssl_privatekey:
+ path: /etc/kubernetes/node-feature-discovery/certs/tls.key
+ type: RSA
+ size: 4096
+ owner: nobody
+ group: root
+ mode: 0400
+
+- name: create signing request for worker certificate
+ openssl_csr:
+ path: /etc/kubernetes/node-feature-discovery/certs/tls.csr
+ privatekey_path: /etc/kubernetes/node-feature-discovery/certs/tls.key
+ CN: "{{ kubernetes_node_name }}"
+ key_usage:
+ - digitalSignature
+ key_usage_critical: yes
+ extended_key_usage:
+ - clientAuth
+ extended_key_usage_critical: yes
+ basic_constraints:
+ - 'CA:FALSE'
+ basic_constraints_critical: yes
+
+- name: slurp CSR for worker certificate
+ slurp:
+ src: /etc/kubernetes/node-feature-discovery/certs/tls.csr
+ register: node_feature_discovery_worker_csr
+
+- name: check if worker certificate already exists
+ stat:
+ path: /etc/kubernetes/node-feature-discovery/certs/tls.crt
+ register: node_feature_discovery_worker_certificate_stat
+
+- name: read worker certificate validity
+ when: node_feature_discovery_worker_certificate_stat.stat.exists
+ openssl_certificate_info:
+ path: /etc/kubernetes/node-feature-discovery/certs/tls.crt
+ valid_at:
+ ten_years: '+3650d'
+ register: node_feature_discovery_worker_certificate_info
+
+- name: slurp existing worker certificate
+ when: node_feature_discovery_worker_certificate_stat.stat.exists
+ slurp:
+ src: /etc/kubernetes/node-feature-discovery/certs/tls.crt
+ register: node_feature_discovery_worker_certificate_current
+
+- name: generate worker certificate
+ delegate_to: "{{ groups['_kubernetes_primary_controlplane_node_'] | first }}"
+ community.crypto.x509_certificate_pipe:
+ content: "{{ node_feature_discovery_worker_certificate_current.content | default('') | b64decode }}"
+ csr_content: "{{ node_feature_discovery_worker_csr.content | b64decode }}"
+ provider: ownca
+ ownca_path: /etc/kubernetes/addons/node-feature-discovery/ca/crt.pem
+ ownca_privatekey_path: /etc/kubernetes/addons/node-feature-discovery/ca/key.pem
+ ownca_digest: sha256
+ ownca_not_after: "+18250d" ## 50 years
+ force: "{{ node_feature_discovery_worker_certificate_stat.stat.exists and (not node_feature_discovery_worker_certificate_info.valid_at.ten_years) }}"
+ register: node_feature_discovery_worker_cert
+
+- name: store worker certificate
+ copy:
+ content: "{{ node_feature_discovery_worker_cert.certificate }}"
+ dest: /etc/kubernetes/node-feature-discovery/certs/tls.crt