forked from k0sproject/k0s
-
Notifications
You must be signed in to change notification settings - Fork 0
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Use proper certs for controller manager and scheduler
Don't rely on the self-signed ones. Add the loopback IP to the SAN list. Move the private getLoopbackIP function used by NLLB to k0s's internal net package, so that it can be used from multiple places. Also, configure the appropriate cipher suites and minimal TLS version. Signed-off-by: Tom Wieczorek <[email protected]>
- Loading branch information
Showing
7 changed files
with
172 additions
and
47 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,54 @@ | ||
/* | ||
Copyright 2024 k0s authors | ||
Licensed under the Apache License, Version 2.0 (the "License"); | ||
you may not use this file except in compliance with the License. | ||
You may obtain a copy of the License at | ||
http://www.apache.org/licenses/LICENSE-2.0 | ||
Unless required by applicable law or agreed to in writing, software | ||
distributed under the License is distributed on an "AS IS" BASIS, | ||
WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. | ||
See the License for the specific language governing permissions and | ||
limitations under the License. | ||
*/ | ||
|
||
package net | ||
|
||
import ( | ||
"context" | ||
"fmt" | ||
"net" | ||
) | ||
|
||
// Resolves the preferred loopback IP address for this machine. | ||
// | ||
// Performs a DNS lookup for "localhost" and returns the first address that is | ||
// recognized as a loopback address. Returns an error if the DNS lookup fails | ||
// (e.g. due to context cancellation) or the lookup didn't return a loopback | ||
// address. In that case, a sane default loopback address is returned. | ||
// | ||
// Example usage: | ||
// | ||
// ip, err := LookupLoopbackIP(ctx) | ||
// if err != nil { | ||
// fmt.Fprintln(os.Stderr, "Failed to find loopback IP, falling back to", ip.String(), "-", err) | ||
// } | ||
// // ... use ip somehow | ||
func LookupLoopbackIP(ctx context.Context) (net.IP, error) { | ||
localIPs, err := net.DefaultResolver.LookupIPAddr(ctx, "localhost") | ||
if err != nil { | ||
err = fmt.Errorf("failed to resolve localhost: %w", err) | ||
} else { | ||
for _, addr := range localIPs { | ||
if addr.IP.IsLoopback() { | ||
return addr.IP, nil | ||
} | ||
} | ||
|
||
err = fmt.Errorf("no loopback IPs found for localhost: %v", localIPs) | ||
} | ||
|
||
return net.IP{127, 0, 0, 1}, err | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Oops, something went wrong.