Skip to content

Commit

Permalink
Merge pull request #151 from slintes/disable-http2-0.5
Browse files Browse the repository at this point in the history
[release-0.5] Disable HTTP/2
  • Loading branch information
slintes authored Oct 20, 2023
2 parents a75829f + 9f600cd commit 07c3843
Show file tree
Hide file tree
Showing 230 changed files with 15,538 additions and 5,966 deletions.
30 changes: 2 additions & 28 deletions api/v1alpha1/selfnoderemediationconfig_webhook.go
Original file line number Diff line number Diff line change
Expand Up @@ -18,19 +18,12 @@ package v1alpha1

import (
"fmt"
"time"

"k8s.io/apimachinery/pkg/runtime"
"os"
"path/filepath"
ctrl "sigs.k8s.io/controller-runtime"
logf "sigs.k8s.io/controller-runtime/pkg/log"
"sigs.k8s.io/controller-runtime/pkg/webhook"
"time"
)

const (
webhookCertDir = "/apiserver.local.config/certificates"
webhookCertName = "apiserver.crt"
webhookKeyName = "apiserver.key"
)

// fields names
Expand Down Expand Up @@ -63,25 +56,6 @@ type field struct {
var selfNodeRemediationConfigLog = logf.Log.WithName("selfnoderemediationconfig-resource")

func (r *SelfNodeRemediationConfig) SetupWebhookWithManager(mgr ctrl.Manager) error {

// check if OLM injected certs
certs := []string{filepath.Join(webhookCertDir, webhookCertName), filepath.Join(webhookCertDir, webhookKeyName)}
certsInjected := true
for _, fname := range certs {
if _, err := os.Stat(fname); err != nil {
certsInjected = false
break
}
}
if certsInjected {
server := mgr.GetWebhookServer()
server.CertDir = webhookCertDir
server.CertName = webhookCertName
server.KeyName = webhookKeyName
} else {
selfNodeRemediationConfigLog.Info("OLM injected certs for webhooks not found")
}

return ctrl.NewWebhookManagedBy(mgr).
For(r).
Complete()
Expand Down
2 changes: 1 addition & 1 deletion config/default/manager_auth_proxy_patch.yaml
Original file line number Diff line number Diff line change
Expand Up @@ -10,7 +10,7 @@ spec:
spec:
containers:
- name: kube-rbac-proxy
image: gcr.io/kubebuilder/kube-rbac-proxy:v0.8.0
image: quay.io/brancz/kube-rbac-proxy:v0.14.4
args:
- "--secure-listen-address=0.0.0.0:8443"
- "--upstream=http://127.0.0.1:8080/"
Expand Down
19 changes: 10 additions & 9 deletions go.mod
Original file line number Diff line number Diff line change
Expand Up @@ -12,8 +12,8 @@ require (
github.com/openshift/machine-config-operator v0.0.1-0.20201023110058-6c8bd9b2915c
github.com/pkg/errors v0.9.1
golang.org/x/sys v0.13.0
google.golang.org/grpc v1.40.0
google.golang.org/protobuf v1.28.0
google.golang.org/grpc v1.56.3
google.golang.org/protobuf v1.30.0
k8s.io/api v0.25.14
k8s.io/apiextensions-apiserver v0.24.2
k8s.io/apimachinery v0.26.0-alpha.0.0.20231013002525-fdcfc2723dc8
Expand All @@ -23,7 +23,8 @@ require (
)

require (
cloud.google.com/go v0.97.0 // indirect
cloud.google.com/go/compute v1.19.1 // indirect
cloud.google.com/go/compute/metadata v0.2.3 // indirect
github.com/Azure/go-autorest v14.2.0+incompatible // indirect
github.com/Azure/go-autorest/autorest v0.11.27 // indirect
github.com/Azure/go-autorest/autorest/adal v0.9.20 // indirect
Expand All @@ -35,7 +36,7 @@ require (
github.com/PuerkitoBio/purell v1.1.1 // indirect
github.com/PuerkitoBio/urlesc v0.0.0-20170810143723-de5bf2ad4578 // indirect
github.com/beorn7/perks v1.0.1 // indirect
github.com/cespare/xxhash/v2 v2.1.2 // indirect
github.com/cespare/xxhash/v2 v2.2.0 // indirect
github.com/davecgh/go-spew v1.1.1 // indirect
github.com/emicklei/go-restful/v3 v3.8.0 // indirect
github.com/evanphx/json-patch v4.12.0+incompatible // indirect
Expand All @@ -47,9 +48,9 @@ require (
github.com/gogo/protobuf v1.3.2 // indirect
github.com/golang-jwt/jwt/v4 v4.2.0 // indirect
github.com/golang/groupcache v0.0.0-20210331224755-41bb18bfe9da // indirect
github.com/golang/protobuf v1.5.2 // indirect
github.com/golang/protobuf v1.5.3 // indirect
github.com/google/gnostic v0.5.7-v3refs // indirect
github.com/google/go-cmp v0.5.8 // indirect
github.com/google/go-cmp v0.5.9 // indirect
github.com/google/gofuzz v1.1.0 // indirect
github.com/google/uuid v1.3.0 // indirect
github.com/huandu/xstrings v1.3.2 // indirect
Expand Down Expand Up @@ -77,14 +78,14 @@ require (
go.uber.org/zap v1.19.1 // indirect
golang.org/x/crypto v0.14.0 // indirect
golang.org/x/net v0.17.0 // indirect
golang.org/x/oauth2 v0.0.0-20211104180415-d3ed0bb246c8 // indirect
golang.org/x/sync v0.0.0-20210220032951-036812b2e83c // indirect
golang.org/x/oauth2 v0.7.0 // indirect
golang.org/x/sync v0.1.0 // indirect
golang.org/x/term v0.13.0 // indirect
golang.org/x/text v0.13.0 // indirect
golang.org/x/time v0.0.0-20220210224613-90d013bbcef8 // indirect
gomodules.xyz/jsonpatch/v2 v2.2.0 // indirect
google.golang.org/appengine v1.6.7 // indirect
google.golang.org/genproto v0.0.0-20220107163113-42d7afdf6368 // indirect
google.golang.org/genproto v0.0.0-20230410155749-daa745c078e1 // indirect
gopkg.in/inf.v0 v0.9.1 // indirect
gopkg.in/tomb.v1 v1.0.0-20141024135613-dd632973f1e7 // indirect
gopkg.in/yaml.v2 v2.4.0 // indirect
Expand Down
82 changes: 20 additions & 62 deletions go.sum

Large diffs are not rendered by default.

55 changes: 51 additions & 4 deletions main.go
Original file line number Diff line number Diff line change
Expand Up @@ -18,8 +18,10 @@ package main

import (
"context"
"crypto/tls"
"flag"
"os"
"path/filepath"
"strconv"
"time"

Expand Down Expand Up @@ -59,6 +61,10 @@ const (
nodeNameEnvVar = "MY_NODE_NAME"
peerHealthDefaultPort = 30001
maxTimeForNoPeersResponse = 30 * time.Second

WebhookCertDir = "/apiserver.local.config/certificates"
WebhookCertName = "apiserver.crt"
WebhookKeyName = "apiserver.key"
)

var (
Expand All @@ -78,12 +84,14 @@ func main() {
var metricsAddr string
var enableLeaderElection bool
var probeAddr string
var enableHTTP2 bool
var isManager bool
flag.StringVar(&metricsAddr, "metrics-bind-address", ":8080", "The address the metric endpoint binds to.")
flag.StringVar(&probeAddr, "health-probe-bind-address", ":8081", "The address the probe endpoint binds to.")
flag.BoolVar(&enableLeaderElection, "leader-elect", false,
"Enable leader election for controller manager. "+
"Enabling this will ensure there is only one active controller manager.")
flag.BoolVar(&enableHTTP2, "enable-http2", false, "If HTTP/2 should be enabled for the metrics and webhook servers.")
flag.BoolVar(&isManager, "is-manager", false,
"Used to differentiate between the self node remediation agents that runs in a daemonset to the 'manager' that only"+
"reconciles the config CRD and installs the DS")
Expand All @@ -96,7 +104,9 @@ func main() {
ctrl.SetLogger(zap.New(zap.UseFlagOptions(&opts)))

mgr, err := ctrl.NewManager(ctrl.GetConfigOrDie(), ctrl.Options{
Scheme: scheme,
Scheme: scheme,
// HEADS UP: once controller runtime is updated and this changes to metrics.Options{},
// and in case you configure TLS / SecureServing, disable HTTP/2 in it for mitigating related CVEs!
MetricsBindAddress: metricsAddr,
Port: 9443,
HealthProbeBindAddress: probeAddr,
Expand All @@ -109,7 +119,7 @@ func main() {
}

if isManager {
initSelfNodeRemediationManager(mgr)
initSelfNodeRemediationManager(mgr, enableHTTP2)
} else {
initSelfNodeRemediationAgent(mgr)
}
Expand All @@ -132,9 +142,11 @@ func main() {
}
}

func initSelfNodeRemediationManager(mgr manager.Manager) {
func initSelfNodeRemediationManager(mgr manager.Manager, enableHTTP2 bool) {
setupLog.Info("Starting as a manager that installs the daemonset")

configureWebhookServer(mgr, enableHTTP2)

if err := (&selfnoderemediationv1alpha1.SelfNodeRemediationConfig{}).SetupWebhookWithManager(mgr); err != nil {
setupLog.Error(err, "unable to create webhook", "webhook", "SelfNodeRemediationConfig")
os.Exit(1)
Expand Down Expand Up @@ -278,7 +290,7 @@ func initSelfNodeRemediationAgent(mgr manager.Manager) {

// but the reboot time needs be at least the time we know we need for determining a node issue and trigger the reboot!
// 1. time for determine node issue
minTimeToAssumeNodeRebooted := (apiCheckInterval + apiServerTimeout) * time.Duration(maxErrorThreshold) + maxTimeForNoPeersResponse
minTimeToAssumeNodeRebooted := (apiCheckInterval+apiServerTimeout)*time.Duration(maxErrorThreshold) + maxTimeForNoPeersResponse
// 2. time for asking peers (10% batches + 1st smaller batch)
minTimeToAssumeNodeRebooted += (10 + 1) * (peerDialTimeout + peerRequestTimeout)
// 3. watchdog timeout
Expand Down Expand Up @@ -341,3 +353,38 @@ func newTemplatesIfNotExist(c client.Client) error {
}
return nil
}

func configureWebhookServer(mgr ctrl.Manager, enableHTTP2 bool) {

server := mgr.GetWebhookServer()

// check for OLM injected certs
certs := []string{filepath.Join(WebhookCertDir, WebhookCertName), filepath.Join(WebhookCertDir, WebhookKeyName)}
certsInjected := true
for _, fname := range certs {
if _, err := os.Stat(fname); err != nil {
certsInjected = false
break
}
}
if certsInjected {
server.CertDir = WebhookCertDir
server.CertName = WebhookCertName
server.KeyName = WebhookKeyName
} else {
setupLog.Info("OLM injected certs for webhooks not found")
}

// disable http/2 for mitigating relevant CVEs
if !enableHTTP2 {
server.TLSOpts = append(server.TLSOpts,
func(c *tls.Config) {
c.NextProtos = []string{"http/1.1"}
},
)
setupLog.Info("HTTP/2 for webhooks disabled")
} else {
setupLog.Info("HTTP/2 for webhooks enabled")
}

}
File renamed without changes.
18 changes: 18 additions & 0 deletions vendor/cloud.google.com/go/compute/internal/version.go

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

19 changes: 19 additions & 0 deletions vendor/cloud.google.com/go/compute/metadata/CHANGES.md

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

Loading

0 comments on commit 07c3843

Please sign in to comment.