-
Notifications
You must be signed in to change notification settings - Fork 930
Fix certificate validation when api_endpoint differs from hostname #434
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
Conversation
Several things:
Your problem is solved just by setting the |
- 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. Signed-off-by: Guillaume Andre <[email protected]>
d6440ce
to
24ec0ec
Compare
roles/k3s_server/defaults/main.yml
Outdated
# Auto-computed TLS SANs to prevent certificate validation issues | ||
_computed_tls_sans: "{% if api_endpoint is defined and api_endpoint != ansible_hostname %}--tls-san={{ api_endpoint }}{% endif %}" | ||
_final_server_args: "{{ extra_server_args }} {{ _computed_tls_sans }}" |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Move the logic out of these files, we specifically want these to be very simple default files.
Signed-off-by: Guillaume Andre <[email protected]>
Signed-off-by: Guillaume Andre <[email protected]>
Thank you for your feedback and sorry, I had forgotten to push changes. I moved the TLS SAN logic from defaults to tasks using The code also validates that |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Looks good but I want to separate this new tls-san argument from the existing extra_args
. No need to handle injecting the extra_args when we don't have to.
I will wait on merging #442 till after this PR is merged (no need to make you deal with my merge conflict :) |
Applied suggestion from @dereknola Co-authored-by: Derek Nola <[email protected]> Signed-off-by: Guillaume A <[email protected]>
Applied suggestion from @dereknola Co-authored-by: Derek Nola <[email protected]> Signed-off-by: Guillaume A <[email protected]>
Fixes certificate validation failures in multi-server setups where api_endpoint (FQDN) differs from the detected hostname
Problem
When using FQDNs in inventory (e.g.,
server1.example.com
), k3s HA clusters fail to bootstrap because:ansible_hostname
(e.g.,server1
)api_endpoint
(e.g.,server1.example.com
)x509: certificate is valid for server1, not server1.example.com
This occurs when:
api_endpoint
resolves to a different name than the detected hostnameSolution
Automatically add
--tls-san={{ api_endpoint }}
to k3s server arguments whenapi_endpoint
differs fromansible_hostname
.Changes
roles/k3s_server/defaults/main.yml
: Add computed TLS SAN logicroles/k3s_server/templates/*.service.j2
: Use computed server argsLogic
Testing
Verified with:
server1.example.com
→ adds--tls-san=server1.example.com
)server1
→ no additional SAN needed)