Skip to content
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

Add spec.api.bindAddress configuration #1038

Closed
wants to merge 4 commits into from
Closed

Conversation

gakio12
Copy link
Contributor

@gakio12 gakio12 commented Jul 30, 2021

Should a new bindAddress option be created and change documentation for the existing address option, or should the existing address option's behavior be changed to match the existing documentation?

The later I can see causing some issues with existing setups, bindAddress is probably the safest route. Currently the default for bindAddress is "0.0.0.0", which is the default kube-api-server uses if the --bind-address flag isn't used.

Issue
Fixes #957

What this PR Includes
Adds the ability to define a bindAddress for the kube-api-server.

@jnummelin
Copy link
Member

I'd prefer to use separate bindAddress option as more safe route for this

@gakio12 gakio12 marked this pull request as ready for review September 7, 2021 21:29
@gakio12 gakio12 requested a review from a team as a code owner September 7, 2021 21:29
@gakio12 gakio12 changed the title [WIP] Add spec.api.bindAddress configuration Add spec.api.bindAddress configuration Sep 7, 2021
@jnummelin
Copy link
Member

@gakio12 seems there's some unit test failures

@trawler
Copy link
Contributor

trawler commented Oct 5, 2021

Hey @gakio12 please rebase with the current code updates. Thanks!

@jnummelin
Copy link
Member

The PR is marked as stale since no activity has been recorded in 30 days

@gakio12
Copy link
Contributor Author

gakio12 commented Nov 7, 2021

@jnummelin Is there anything more I need to do on this PR? I want to make sure I am not missing anything.


func (a *APISpec) getAPIServerAddress(address string) string {
switch address {
case "0.0.0.0":
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

this is logically wrong, "0.0.0.0" means we want to listen on all interfaces available, while "localhost" means listening only on loopback iface. What it the logic behind that decision?

Copy link
Contributor Author

@gakio12 gakio12 Nov 30, 2021

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

The reason it is "0.0.0.0" here is because without specifying an interface (as the current version of k0s does), the kube-apiserver listens on 0.0.0.0. So the default is "0.0.0.0" to allow the functionality to remain the same as previous versions.

The reason we return "localhost" in getAPIServerAddress follows the same reason as the above, k0s uses a hardcoded "localhost" in the kubeconfig and other certs for the kube-apiserver in the current released version.

With this change, it keeps the default functionality of k0s, while allowing someone to change the bind address and still have the certs and kubeconfig be correct (a kubeconfig pointing at "localhost" when the kube-apiserver is listening on 192.168.1.1 doesn't work).

I'll add that logically, if a server is listening on 0.0.0.0, "localhost" would be an accurate response, since you can't connect to 0.0.0.0 directly. With that said, I can see how getAPIServerAddress can be confused with a getAPIServerBindAddress, whereas the former is the address used to connect to the APIServer, not the address it is binding to.

Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

since you can't connect to 0.0.0.0 directly

well, it turns out that one actually can do that as in many (most?) languages connecting to 0.0.0.0 actually means connecting to localhost. Now that this address is used for kube components which are all Golang, I think it should work if they connect to 0.0.0.0.

For reference: https://cs.opensource.google/go/go/+/refs/tags/go1.17.3:src/net/ipsock_posix.go;l=137-143

With this in mind, everything should work if we use the bind address as the address for other components to connect to the API, right?

Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Huh, I was not aware of that. That is good to know! Since this string is used for health checks and a kubeconfig, an easy test is to take an existing cluster and change the kubeconfig to point to 0.0.0.0. The certificate will have to be signed with 0.0.0.0 as well, since "localhost" resolves to 127.0.0.1. Just doing that quick test I outlined, I got the expected certificate error.

I'll do a bit more testing on this and see if this logic can be removed while maintaining how k0s currently functions.

Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

@gakio12 hello! do you have any updates on the issue?

Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

@Soider Apologies for the delay on this, I am expecting to be able to work on this in the next few weeks. I have the changes in place locally, but I have lost my test environment the last two months, so was unable to test (apart from time constraints).

Copy link

@ocraviotto ocraviotto Jan 28, 2022

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

My 2 cents here: the actual meaning of "0.0.0.0" depends on how it is used. When used to bind, it means all (or any) interfaces, but when used as a client, it means "this" host (or even more strongly, an "unspecified" address, and as pointed above, is interpreted to mean "localhost" or the loopback interface, at least in various cases (including the apiserver self client)
So IMHO, although the address does seem to work (albeit with a failure as it's not in the cert SAN), it seems better to me to keep the old behavior and use "localhost" in this case.

@ocraviotto
Copy link

@gakio12 Just curious, are you still planning to work on this? I'd need this to make my setup work as well, so was simply wondering what your plans were to decide on whether to wait. (Among other things, this would then need an addition to k0sctl to allow setting the BindAddress per controller etc.)

@gakio12
Copy link
Contributor Author

gakio12 commented Jan 27, 2022

@ocraviotto Yes, I am planning to commit the changes proposed in the next few weeks now that I have gained some free time (and got my environment back).

@github-actions
Copy link
Contributor

github-actions bot commented Mar 4, 2022

The PR is marked as stale since no activity has been recorded in 30 days

@github-actions github-actions bot added the Stale label Mar 4, 2022
@github-actions
Copy link
Contributor

The PR is marked as stale since no activity has been recorded in 30 days

@github-actions github-actions bot added Stale and removed Stale labels May 10, 2023
@github-actions
Copy link
Contributor

The PR is marked as stale since no activity has been recorded in 30 days

@github-actions github-actions bot added Stale and removed Stale labels Jun 10, 2023
@github-actions
Copy link
Contributor

The PR is marked as stale since no activity has been recorded in 30 days

@github-actions github-actions bot added Stale and removed Stale labels Jul 11, 2023
@github-actions
Copy link
Contributor

The PR is marked as stale since no activity has been recorded in 30 days

@github-actions github-actions bot added Stale and removed Stale labels Aug 12, 2023
@github-actions
Copy link
Contributor

The PR is marked as stale since no activity has been recorded in 30 days

@github-actions github-actions bot added the Stale label Sep 12, 2023
@kke
Copy link
Contributor

kke commented Sep 13, 2023

This has been open for quite a while.

@github-actions github-actions bot removed the Stale label Sep 13, 2023
@github-actions
Copy link
Contributor

The PR is marked as stale since no activity has been recorded in 30 days

@github-actions github-actions bot added Stale and removed Stale labels Oct 14, 2023
Copy link
Contributor

The PR is marked as stale since no activity has been recorded in 30 days

@github-actions github-actions bot added Stale and removed Stale labels Nov 14, 2023
Copy link
Contributor

The PR is marked as stale since no activity has been recorded in 30 days

@pschichtel
Copy link
Contributor

@kke I rebased this PR and submitted as #3824.

Copy link
Contributor

github-actions bot commented Jan 5, 2024

This pull request has merge conflicts that need to be resolved.

@twz123 twz123 closed this Jan 12, 2024
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Projects
None yet
Development

Successfully merging this pull request may close these issues.

Changing "bind-address" of kube-api
9 participants