Skip to content

Commit d6440ce

Browse files
committed
Fix certificate validation when api_endpoint differs from hostname
- Auto-add --tls-san={{ api_endpoint }} when it differs from ansible_hostname - Prevents 'x509: certificate is valid for hostname, not FQDN' errors - Ensures first server generates certificate with all required SANs - Maintains backward compatibility with existing configurations - Fixes HA cluster bootstrap issues when using FQDNs in inventory Closes certificate validation failures in multi-server setups where api_endpoint (FQDN) differs from the detected hostname.
1 parent 5a19438 commit d6440ce

File tree

4 files changed

+6
-3
lines changed

4 files changed

+6
-3
lines changed

roles/k3s_server/defaults/main.yml

Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -9,3 +9,6 @@ server_group: server # noqa var-naming[no-role-prefix]
99
agent_group: agent # noqa var-naming[no-role-prefix]
1010
use_external_database: false # noqa var-naming[no-role-prefix]
1111
extra_server_args: "" # noqa var-naming[no-role-prefix]
12+
# Auto-computed TLS SANs to prevent certificate validation issues
13+
_computed_tls_sans: "{% if api_endpoint is defined and api_endpoint != ansible_hostname %}--tls-san={{ api_endpoint }}{% endif %}"
14+
_final_server_args: "{{ extra_server_args }} {{ _computed_tls_sans }}"

roles/k3s_server/templates/k3s-cluster-init.service.j2

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -25,4 +25,4 @@ Restart=always
2525
RestartSec=5s
2626
ExecStartPre=-/sbin/modprobe br_netfilter
2727
ExecStartPre=-/sbin/modprobe overlay
28-
ExecStart=/usr/local/bin/k3s server --cluster-init --data-dir {{ k3s_server_location }} {{ extra_server_args }}
28+
ExecStart=/usr/local/bin/k3s server --cluster-init --data-dir {{ k3s_server_location }} {{ _final_server_args }}

roles/k3s_server/templates/k3s-ha.service.j2

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -25,4 +25,4 @@ Restart=always
2525
RestartSec=5s
2626
ExecStartPre=-/sbin/modprobe br_netfilter
2727
ExecStartPre=-/sbin/modprobe overlay
28-
ExecStart=/usr/local/bin/k3s server --data-dir {{ k3s_server_location }} --server https://{{ api_endpoint }}:{{ api_port }} {{ extra_server_args }}
28+
ExecStart=/usr/local/bin/k3s server --data-dir {{ k3s_server_location }} --server https://{{ api_endpoint }}:{{ api_port }} {{ _final_server_args }}

roles/k3s_server/templates/k3s-single.service.j2

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -25,4 +25,4 @@ Restart=always
2525
RestartSec=5s
2626
ExecStartPre=-/sbin/modprobe br_netfilter
2727
ExecStartPre=-/sbin/modprobe overlay
28-
ExecStart=/usr/local/bin/k3s server --data-dir {{ k3s_server_location }} {{ extra_server_args }}
28+
ExecStart=/usr/local/bin/k3s server --data-dir {{ k3s_server_location }} {{ _final_server_args }}

0 commit comments

Comments
 (0)