Skip to content

Commit

Permalink
upgrade to latest dependencies (#1265)
Browse files Browse the repository at this point in the history
bumping knative.dev/reconciler-test 03cc77c...785e0bd:
  > 785e0bd Improve error message when deleting resources (# 618)
  > 7d36fe9 Copy pull secrets to SA for eventshub (# 615)
  > e52650f upgrade to latest dependencies (# 606)
bumping knative.dev/pkg bd99f2f...56bfe0d:
  > 56bfe0d [release-1.11] [CVE-2023-44487] Disable http2 for webhooks (# 2875)
bumping knative.dev/eventing 6a695cb...0dadfd9:
  > 0dadfd9 [release-1.11] Scheduler: fix reserved replicas handling, blocking autoscaler and overcommitted pods (# 7374)
  > c1626f1 [release-1.11] Update dependencies (# 7362)
  > 46cc775 [release-1.11] TLS certificate rotation tests (# 7103) (# 7346)

Signed-off-by: Knative Automation <automation@knative.team>
  • Loading branch information
knative-automation committed Oct 30, 2023
1 parent 5b654fb commit d814f8f
Show file tree
Hide file tree
Showing 17 changed files with 525 additions and 19 deletions.
6 changes: 3 additions & 3 deletions go.mod
Original file line number Diff line number Diff line change
Expand Up @@ -21,10 +21,10 @@ require (
k8s.io/client-go v0.26.5
k8s.io/code-generator v0.26.5
k8s.io/kube-openapi v0.0.0-20221012153701-172d655c2280
knative.dev/eventing v0.38.4
knative.dev/eventing v0.38.5
knative.dev/hack v0.0.0-20230712131415-ddae80293c43
knative.dev/pkg v0.0.0-20231011193800-bd99f2f98be7
knative.dev/reconciler-test v0.0.0-20231010075208-03cc77c11831
knative.dev/pkg v0.0.0-20231023150739-56bfe0dd9626
knative.dev/reconciler-test v0.0.0-20231023114057-785e0bd2d9a2
sigs.k8s.io/controller-runtime v0.14.6
)

Expand Down
12 changes: 6 additions & 6 deletions go.sum
Original file line number Diff line number Diff line change
Expand Up @@ -883,14 +883,14 @@ k8s.io/kube-openapi v0.0.0-20221012153701-172d655c2280 h1:+70TFaan3hfJzs+7VK2o+O
k8s.io/kube-openapi v0.0.0-20221012153701-172d655c2280/go.mod h1:+Axhij7bCpeqhklhUTe3xmOn6bWxolyZEeyaFpjGtl4=
k8s.io/utils v0.0.0-20230505201702-9f6742963106 h1:EObNQ3TW2D+WptiYXlApGNLVy0zm/JIBVY9i+M4wpAU=
k8s.io/utils v0.0.0-20230505201702-9f6742963106/go.mod h1:OLgZIPagt7ERELqWJFomSt595RzquPNLL48iOWgYOg0=
knative.dev/eventing v0.38.4 h1:eH059bfeLilj2xAN6V7XXOh3wqzz5ssoMS/CIJpJfmk=
knative.dev/eventing v0.38.4/go.mod h1:ct8t+v6nmp1kFCy6ngkDWIEvnjJDNDoKptrfnQVh+z8=
knative.dev/eventing v0.38.5 h1:NvSy3lek9IbLLWEot36NyAfNv7VkJNl38F1ItVL0D6s=
knative.dev/eventing v0.38.5/go.mod h1:g+iAS+KBRSKULEPqoVnseMkObDeq3SJhqefbuIu8zY8=
knative.dev/hack v0.0.0-20230712131415-ddae80293c43 h1:3SE06uNfSFGm/5XS+0trbyCUpgsOaBeyhPQU8FPNFz8=
knative.dev/hack v0.0.0-20230712131415-ddae80293c43/go.mod h1:yk2OjGDsbEnQjfxdm0/HJKS2WqTLEFg/N6nUs6Rqx3Q=
knative.dev/pkg v0.0.0-20231011193800-bd99f2f98be7 h1:y3qbfYX1SuSr/1ysXvKfpV8q/kCwWLWieCUgAhBUHmQ=
knative.dev/pkg v0.0.0-20231011193800-bd99f2f98be7/go.mod h1:g+UCgSKQ2f15kHYu/V3CPtoKo5F1x/2Y1ot0NSK7gA0=
knative.dev/reconciler-test v0.0.0-20231010075208-03cc77c11831 h1:rOisVvTe0yuJNImgOex1Z4vdqXRPP1FAg5xPxbLOSlU=
knative.dev/reconciler-test v0.0.0-20231010075208-03cc77c11831/go.mod h1:i+/PWK/n3HPgjXMoj5U7CA6WRW/C3c3EfHCQ0FmrhNM=
knative.dev/pkg v0.0.0-20231023150739-56bfe0dd9626 h1:qFE+UDBRg6cpF5LbA0sv1XK4XZ36Z7aTRCa+HcuxnNQ=
knative.dev/pkg v0.0.0-20231023150739-56bfe0dd9626/go.mod h1:g+UCgSKQ2f15kHYu/V3CPtoKo5F1x/2Y1ot0NSK7gA0=
knative.dev/reconciler-test v0.0.0-20231023114057-785e0bd2d9a2 h1:Lenj/sGhPYZoCdl4bvoeZzA4Y1VS4LNEIWH1/HTU+6I=
knative.dev/reconciler-test v0.0.0-20231023114057-785e0bd2d9a2/go.mod h1:HgugJUOhHZ3F6Tbhte92ecL0sBqJtCeJtd7K8jX+IJk=
pgregory.net/rapid v0.3.3 h1:jCjBsY4ln4Atz78QoBWxUEvAHaFyNDQg9+WU62aCn1U=
pgregory.net/rapid v0.3.3/go.mod h1:UYpPVyjFHzYBGHIxLFoupi8vwk6rXNzRY9OMvVxFIOU=
rsc.io/binaryregexp v0.2.0/go.mod h1:qTv7/COck+e2FymRvadv62gMdZztPaShugOCi3I+8D8=
Expand Down
Original file line number Diff line number Diff line change
@@ -0,0 +1,105 @@
/*
Copyright 2023 The Knative 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 broker

import (
"context"
"time"

cetest "github.com/cloudevents/sdk-go/v2/test"
"github.com/google/uuid"
"k8s.io/apimachinery/pkg/types"
"knative.dev/pkg/system"
"knative.dev/reconciler-test/pkg/eventshub"
"knative.dev/reconciler-test/pkg/eventshub/assert"
"knative.dev/reconciler-test/pkg/feature"
"knative.dev/reconciler-test/pkg/resources/service"
"knative.dev/reconciler-test/resources/certificate"

"knative.dev/eventing/test/rekt/features/featureflags"
"knative.dev/eventing/test/rekt/resources/addressable"
"knative.dev/eventing/test/rekt/resources/broker"
"knative.dev/eventing/test/rekt/resources/trigger"
)

func RotateMTChannelBrokerTLSCertificates() *feature.Feature {
ingressCertificateName := "mt-broker-ingress-server-tls"
ingressSecretName := "mt-broker-ingress-server-tls"

filterCertificateName := "mt-broker-filter-server-tls"

brokerName := feature.MakeRandomK8sName("broker")
triggerName := feature.MakeRandomK8sName("trigger")
sink := feature.MakeRandomK8sName("sink")
source := feature.MakeRandomK8sName("source")

f := feature.NewFeatureNamed("Rotate MTChannelBroker TLS certificate")

f.Prerequisite("transport encryption is strict", featureflags.TransportEncryptionStrict())
f.Prerequisite("should not run when Istio is enabled", featureflags.IstioDisabled())

f.Setup("Rotate ingress certificate", certificate.Rotate(certificate.RotateCertificate{
Certificate: types.NamespacedName{
Namespace: system.Namespace(),
Name: ingressCertificateName,
},
}))
// We cannot externally verify this certificate rotation
f.Setup("Rotate filter certificate", certificate.Rotate(certificate.RotateCertificate{
Certificate: types.NamespacedName{
Namespace: system.Namespace(),
Name: filterCertificateName,
},
}))

f.Setup("install sink", eventshub.Install(sink, eventshub.StartReceiverTLS))
f.Setup("install broker", broker.Install(brokerName, broker.WithEnvConfig()...))
f.Setup("Broker is ready", broker.IsReady(brokerName))
f.Setup("install trigger", func(ctx context.Context, t feature.T) {
d := service.AsDestinationRef(sink)
d.CACerts = eventshub.GetCaCerts(ctx)
trigger.Install(triggerName, brokerName, trigger.WithSubscriberFromDestination(d))(ctx, t)
})
f.Setup("trigger is ready", trigger.IsReady(triggerName))
f.Setup("Broker has HTTPS address", broker.ValidateAddress(brokerName, addressable.AssertHTTPSAddress))

event := cetest.FullEvent()
event.SetID(uuid.New().String())

f.Requirement("install source", eventshub.Install(source,
eventshub.StartSenderToResourceTLS(broker.GVR(), brokerName, nil),
eventshub.InputEvent(event),
// Send multiple events so that we take into account that the certificate rotation might
// be detected by the server after some time.
eventshub.SendMultipleEvents(100, 3*time.Second),
))

f.Assert("Event sent", assert.OnStore(source).
MatchSentEvent(cetest.HasId(event.ID())).
AtLeast(1),
)
f.Assert("Event received", assert.OnStore(sink).
MatchReceivedEvent(cetest.HasId(event.ID())).
AtLeast(1),
)
f.Assert("Source match updated peer certificate", assert.OnStore(source).
MatchPeerCertificatesReceived(assert.MatchPeerCertificatesFromSecret(system.Namespace(), ingressSecretName, "tls.crt")).
AtLeast(1),
)

return f
}
Original file line number Diff line number Diff line change
Expand Up @@ -46,6 +46,20 @@ func TransportEncryptionPermissiveOrStrict() feature.ShouldRun {
}
}

func TransportEncryptionStrict() feature.ShouldRun {
return func(ctx context.Context, t feature.T) (feature.PrerequisiteResult, error) {
flags, err := getFeatureFlags(ctx, "config-features")
if err != nil {
return feature.PrerequisiteResult{}, err
}

return feature.PrerequisiteResult{
ShouldRun: flags.IsStrictTransportEncryption(),
Reason: flags.String(),
}, nil
}
}

func IstioDisabled() feature.ShouldRun {
return func(ctx context.Context, t feature.T) (feature.PrerequisiteResult, error) {
flags, err := getFeatureFlags(ctx, "config-features")
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -18,6 +18,7 @@ package addressable

import (
"context"
"fmt"
"time"

apierrors "k8s.io/apimachinery/pkg/api/errors"
Expand All @@ -27,6 +28,8 @@ import (
"knative.dev/reconciler-test/pkg/k8s"
)

type ValidateAddress func(addressable *duckv1.Addressable) error

// Address returns a broker's address.
func Address(ctx context.Context, gvr schema.GroupVersionResource, name string, timings ...time.Duration) (*duckv1.Addressable, error) {
interval, timeout := k8s.PollTimings(ctx, timings)
Expand All @@ -51,3 +54,10 @@ func Address(ctx context.Context, gvr schema.GroupVersionResource, name string,
})
return addr, err
}

func AssertHTTPSAddress(addr *duckv1.Addressable) error {
if addr.URL.Scheme != "https" {
return fmt.Errorf("address is not HTTPS: %#v", addr)
}
return nil
}
15 changes: 15 additions & 0 deletions vendor/knative.dev/eventing/test/rekt/resources/broker/broker.go
Original file line number Diff line number Diff line change
Expand Up @@ -158,6 +158,21 @@ func IsAddressable(name string, timings ...time.Duration) feature.StepFn {
return k8s.IsAddressable(GVR(), name, timings...)
}

// ValidateAddress validates the address retured by Address
func ValidateAddress(name string, validate addressable.ValidateAddress, timings ...time.Duration) feature.StepFn {
return func(ctx context.Context, t feature.T) {
addr, err := Address(ctx, name, timings...)
if err != nil {
t.Error(err)
return
}
if err := validate(addr); err != nil {
t.Error(err)
return
}
}
}

// Address returns a broker's address.
func Address(ctx context.Context, name string, timings ...time.Duration) (*duckv1.Addressable, error) {
return addressable.Address(ctx, GVR(), name, timings...)
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -172,3 +172,18 @@ func AsDestinationRef(name string) *duckv1.Destination {

// WithDeadLetterSink adds the dead letter sink related config to a Subscription spec.
var WithDeadLetterSink = delivery.WithDeadLetterSink

// ValidateAddress validates the address retured by Address
func ValidateAddress(name string, validate addressable.ValidateAddress, timings ...time.Duration) feature.StepFn {
return func(ctx context.Context, t feature.T) {
addr, err := Address(ctx, name, timings...)
if err != nil {
t.Error(err)
return
}
if err := validate(addr); err != nil {
t.Error(err)
return
}
}
}
Original file line number Diff line number Diff line change
Expand Up @@ -19,14 +19,16 @@ package subscription
import (
"context"
"embed"
"strings"
"time"

"k8s.io/apimachinery/pkg/runtime/schema"
"knative.dev/eventing/test/rekt/resources/delivery"
duckv1 "knative.dev/pkg/apis/duck/v1"
"knative.dev/reconciler-test/pkg/feature"
"knative.dev/reconciler-test/pkg/k8s"
"knative.dev/reconciler-test/pkg/manifest"

"knative.dev/eventing/test/rekt/resources/delivery"
)

//go:embed *.yaml
Expand Down Expand Up @@ -128,3 +130,36 @@ func Install(name string, opts ...manifest.CfgFn) feature.StepFn {
func IsReady(name string, timing ...time.Duration) feature.StepFn {
return k8s.IsReady(gvr(), name, timing...)
}

// WithSubscriberFromDestination adds the subscriber related config to a Trigger spec.
func WithSubscriberFromDestination(dest *duckv1.Destination) manifest.CfgFn {
return func(cfg map[string]interface{}) {
if _, set := cfg["subscriber"]; !set {
cfg["subscriber"] = map[string]interface{}{}
}
subscriber := cfg["subscriber"].(map[string]interface{})

uri := dest.URI
ref := dest.Ref

if dest.CACerts != nil {
// This is a multi-line string and should be indented accordingly.
// Replace "new line" with "new line + spaces".
subscriber["CACerts"] = strings.ReplaceAll(*dest.CACerts, "\n", "\n ")
}

if uri != nil {
subscriber["uri"] = uri.String()
}
if ref != nil {
if _, set := subscriber["ref"]; !set {
subscriber["ref"] = map[string]interface{}{}
}
sref := subscriber["ref"].(map[string]interface{})
sref["apiVersion"] = ref.APIVersion
sref["kind"] = ref.Kind
// skip namespace
sref["name"] = ref.Name
}
}
}
Original file line number Diff line number Diff line change
Expand Up @@ -36,6 +36,10 @@ spec:
{{ if .subscriber.uri }}
uri: {{ .subscriber.uri }}
{{ end }}
{{ if .subscriber.CACerts }}
CACerts: |-
{{ .subscriber.CACerts }}
{{ end }}
{{ end }}
{{if .reply }}
reply:
Expand All @@ -53,6 +57,10 @@ spec:
{{ if .reply.uri }}
uri: {{ .reply.uri }}
{{ end }}
{{ if .reply.CACerts }}
CACerts: |-
{{ .reply.CACerts }}
{{ end }}
{{ end }}
{{ if .delivery }}
delivery:
Expand All @@ -72,6 +80,10 @@ spec:
{{ if .delivery.deadLetterSink.uri }}
uri: {{ .delivery.deadLetterSink.uri }}
{{ end }}
{{ if .delivery.deadLetterSink.CACerts }}
CACerts: |-
{{ .delivery.deadLetterSink.CACerts }}
{{ end }}
{{ end }}
{{ if .delivery.retry }}
retry: {{ .delivery.retry}}
Expand Down
18 changes: 18 additions & 0 deletions vendor/knative.dev/pkg/webhook/webhook.go
Original file line number Diff line number Diff line change
Expand Up @@ -74,6 +74,17 @@ type Options struct {
// ControllerOptions encapsulates options for creating a new controller,
// including throttling and stats behavior.
ControllerOptions *controller.ControllerOptions

// EnableHTTP2 enables HTTP2 for webhooks.
// Mitigate CVE-2023-44487 by disabling HTTP2 by default until the Go
// standard library and golang.org/x/net are fully fixed.
// Right now, it is possible for authenticated and unauthenticated users to
// hold open HTTP2 connections and consume huge amounts of memory.
// See:
// * https://github.com/kubernetes/kubernetes/pull/121120
// * https://github.com/kubernetes/kubernetes/issues/121197
// * https://github.com/golang/go/issues/63417#issuecomment-1758858612
EnableHTTP2 bool
}

// Operation is the verb being operated on
Expand Down Expand Up @@ -237,12 +248,19 @@ func (wh *Webhook) Run(stop <-chan struct{}) error {
QuietPeriod: wh.Options.GracePeriod,
}

// If TLSNextProto is not nil, HTTP/2 support is not enabled automatically.
nextProto := map[string]func(*http.Server, *tls.Conn, http.Handler){}
if wh.Options.EnableHTTP2 {
nextProto = nil
}

server := &http.Server{
ErrorLog: log.New(&zapWrapper{logger}, "", 0),
Handler: drainer,
Addr: fmt.Sprint(":", wh.Options.Port),
TLSConfig: wh.tlsConfig,
ReadHeaderTimeout: time.Minute, //https://medium.com/a-journey-with-go/go-understand-and-mitigate-slowloris-attack-711c1b1403f6
TLSNextProto: nextProto,
}

var serve = server.ListenAndServe
Expand Down
20 changes: 17 additions & 3 deletions vendor/knative.dev/reconciler-test/pkg/environment/namespace.go
Original file line number Diff line number Diff line change
Expand Up @@ -122,12 +122,26 @@ func (mr *MagicEnvironment) CreateNamespaceIfNeeded() error {
return fmt.Errorf("error copying the image pull Secret: %s", err)
}

_, err = c.CoreV1().ServiceAccounts(mr.namespace).Patch(context.Background(), sa.Name, types.StrategicMergePatchType,
[]byte(`{"imagePullSecrets":[{"name":"`+mr.imagePullSecretName+`"}]}`), metav1.PatchOptions{})
for _, secret := range sa.ImagePullSecrets {
if secret.Name == mr.imagePullSecretName {
return nil
}
}

// Prevent overwriting existing imagePullSecrets
patch := `[{"op":"add","path":"/imagePullSecrets/-","value":{"name":"` + mr.imagePullSecretName + `"}}]`
if len(sa.ImagePullSecrets) == 0 {
patch = `[{"op":"add","path":"/imagePullSecrets","value":[{"name":"` + mr.imagePullSecretName + `"}]}]`
}

_, err = c.CoreV1().ServiceAccounts(mr.namespace).Patch(context.Background(), sa.Name, types.JSONPatchType,
[]byte(patch), metav1.PatchOptions{})
if err != nil {
return fmt.Errorf("patch failed on NS/SA (%s/%s): %s", mr.namespace, sa.Name, err)
return fmt.Errorf("patch failed on NS/SA (%s/%s): %w",
mr.namespace, sa.Name, err)
}
}

return nil
}

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -17,3 +17,9 @@ kind: ServiceAccount
metadata:
name: {{ .name }}
namespace: {{ .namespace }}
{{ if .withPullSecrets }}
imagePullSecrets:
{{ range $_, $value := .withPullSecrets.secrets }}
- name: {{ $value }}
{{ end }}
{{ end }}
Loading

0 comments on commit d814f8f

Please sign in to comment.