Skip to content

Add advertise-address to SANs before generating apiserver cert - #14516

Merged
brandond merged 1 commit into
k3s-io:mainfrom
somaz94:fix/advertise-address-apiserver-sans
Aug 14, 2026
Merged

brandond merged 1 commit into
k3s-io:mainfrom
somaz94:fix/advertise-address-apiserver-sans

Conversation

@somaz94

@somaz94 somaz94 commented Aug 14, 2026

Copy link
Copy Markdown
Contributor

Proposed Changes

Move the advertise-address SAN append so it runs before PrepareServer, which is what generates the apiserver serving certificate.

The block sat 79 lines after PrepareServer, so by the time the address was appended the certificate had already been issued without it. That is why --advertise-address stopped showing up in serving-kube-apiserver.crt.

On the concern raised in the issue about Tailscale: agent startup no longer changes AdvertiseIP after this point. Every assignment to it lives in pkg/cli/server/server.go (lines 179, 526, 537, 546, 551) and all of them complete before PrepareServer at line 555. The VPN block that sets it from Tailscale is at line 518, also before. Outside this file AdvertiseIP is only read, in pkg/daemons/control/server.go:230-231. vpn.GetInfoFromExecutor() reads from executor.Get(), which #14000 made an explicit setup step that runs before anything else, so it does not depend on agent.Run having started.

I also updated the comment, which described the old ordering constraint.

Types of Changes

Bugfix.

Verification

Start a server with an advertise address and check the cert:

k3s server --advertise-address=11.11.22.22
openssl x509 -in /var/lib/rancher/k3s/server/tls/serving-kube-apiserver.crt -noout -text | grep 11.11.22.22

After this change the address is present in the Subject Alternative Name list. The reporter ran the same check on v1.36.3-rc1+k3s1 and the grep found nothing there.

Testing

Added a case to the existing --advertise-address startup integration test that checks the address landed in the apiserver serving cert SANs. It follows the same steps the issue reporter used.

Ran the startup suite locally against a binary built from this branch:

Ran 27 of 60 Specs in 382.652 seconds

The when a server with different IPs is created group passed, including the new spec. One unrelated spec (when a server with different data-dir is created) failed in my setup with a cert trust error, an artifact of running the suite in a container with a persistent /var/lib/rancher volume rather than on a clean runner.

Linked Issues

Issue: #14473
Related refactors: #14000, and commit fb658b4

User-Facing Change

Fixed the apiserver serving certificate not including the value of --advertise-address in its subject alternative names.

Further Comments

I used Claude Code while preparing this PR, for the source audit of AdvertiseIP assignments and for a first draft of the test case. I went through the change and ran the startup integration suite against a binary built from this branch before opening this.

Signed-off-by: somaz <genius5711@gmail.com>
@somaz94
somaz94 marked this pull request as ready for review August 14, 2026 08:03
@somaz94
somaz94 requested a review from a team as a code owner August 14, 2026 08:03
@codecov

codecov Bot commented Aug 14, 2026

Copy link
Copy Markdown

Codecov Report

✅ All modified and coverable lines are covered by tests.
✅ Project coverage is 51.50%. Comparing base (866d743) to head (336ff66).

Additional details and impacted files
@@            Coverage Diff             @@
##             main   #14516      +/-   ##
==========================================
+ Coverage   51.41%   51.50%   +0.08%     
==========================================
  Files         197      197              
  Lines       15766    15766              
==========================================
+ Hits         8106     8120      +14     
+ Misses       6368     6359       -9     
+ Partials     1292     1287       -5     
Flag Coverage Δ
e2etests 41.48% <100.00%> (+0.01%) ⬆️
inttests 39.16% <0.00%> (+0.06%) ⬆️
unittests 25.32% <0.00%> (+0.08%) ⬆️

Flags with carried forward coverage won't be shown. Click here to find out more.

☔ View full report in Codecov by Harness.
📢 Have feedback on the report? Share it here.

🚀 New features to boost your workflow:
  • ❄️ Test Analytics: Detect flaky tests, report on failures, and find test suite problems.

@brandond
brandond merged commit 44c693d into k3s-io:main Aug 14, 2026
60 checks passed
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

3 participants