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

Updated VPA admission-controller to have adjustable minimum TLS version and TLS ciphers #6625

Merged
merged 1 commit into from
Mar 19, 2024
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
2 changes: 2 additions & 0 deletions vertical-pod-autoscaler/pkg/admission-controller/README.md
Original file line number Diff line number Diff line change
Expand Up @@ -32,6 +32,8 @@ up the changes: ```sudo systemctl restart kubelet.service```
for pods on their creation & updates.
1. You can specify a path for it to register as a part of the installation process
by setting `--register-by-url=true` and passing `--webhook-address` and `--webhook-port`.
1. You can specify a minimum TLS version with `--min-tls-version` with acceptable values being `tls1_2` (default), or `tls1_3`.
1. You can also specify a comma or colon separated list of ciphers for the server to use with `--tls-ciphers` if `--min-tls-version` is set to `tls1_2`.

## Implementation

Expand Down
35 changes: 33 additions & 2 deletions vertical-pod-autoscaler/pkg/admission-controller/config.go
Original file line number Diff line number Diff line change
Expand Up @@ -19,6 +19,8 @@ package main
import (
"context"
"crypto/tls"
"fmt"
"strings"
"time"

admissionregistration "k8s.io/api/admissionregistration/v1"
Expand All @@ -31,14 +33,43 @@ const (
webhookConfigName = "vpa-webhook-config"
)

func configTLS(serverCert, serverKey []byte) *tls.Config {
func configTLS(serverCert, serverKey []byte, minTlsVersion, ciphers string) *tls.Config {
var tlsVersion uint16
var ciphersuites []uint16
reverseCipherMap := make(map[string]uint16)
sCert, err := tls.X509KeyPair(serverCert, serverKey)
if err != nil {
klog.Fatal(err)
}

for _, c := range tls.CipherSuites() {
reverseCipherMap[c.Name] = c.ID
}
for _, c := range strings.Split(strings.ReplaceAll(ciphers, ",", ":"), ":") {
cipher, ok := reverseCipherMap[c]
if ok {
ciphersuites = append(ciphersuites, cipher)
}
}
if len(ciphersuites) == 0 {
ciphersuites = nil
}

switch minTlsVersion {
case "":
fallthrough
case "tls1_2":
tlsVersion = tls.VersionTLS12
case "tls1_3":
tlsVersion = tls.VersionTLS13
default:
klog.Fatal(fmt.Errorf("Unable to determine value for --min-tls-version (%s), must be either tls1_2 or tls1_3", minTlsVersion))
}

return &tls.Config{
MinVersion: tls.VersionTLS12,
MinVersion: tlsVersion,
Certificates: []tls.Certificate{sCert},
CipherSuites: ciphersuites,
}
}

Expand Down
4 changes: 3 additions & 1 deletion vertical-pod-autoscaler/pkg/admission-controller/main.go
Original file line number Diff line number Diff line change
Expand Up @@ -59,6 +59,8 @@ var (
tlsCertFile: flag.String("tls-cert-file", "/etc/tls-certs/serverCert.pem", "Path to server certificate PEM file."),
tlsPrivateKey: flag.String("tls-private-key", "/etc/tls-certs/serverKey.pem", "Path to server certificate key PEM file."),
}
ciphers = flag.String("tls-ciphers", "", "A comma-separated or colon-separated list of ciphers to accept. Only works when min-tls-version is set to tls1_2.")
minTlsVersion = flag.String("min-tls-version", "tls1_2", "The minimum TLS version to accept. Must be set to either tls1_2 (default) or tls1_3.")

port = flag.Int("port", 8000, "The port to listen on.")
address = flag.String("address", ":8944", "The address to expose Prometheus metrics.")
Expand Down Expand Up @@ -131,7 +133,7 @@ func main() {
})
server := &http.Server{
Addr: fmt.Sprintf(":%d", *port),
TLSConfig: configTLS(certs.serverCert, certs.serverKey),
TLSConfig: configTLS(certs.serverCert, certs.serverKey, *minTlsVersion, *ciphers),
}
url := fmt.Sprintf("%v:%v", *webhookAddress, *webhookPort)
go func() {
Expand Down
Loading