-
Notifications
You must be signed in to change notification settings - Fork 601
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
TLS certificate rotation tests (#7103)
Fixes #7039 <!-- Please include the 'why' behind your changes if no issue exists --> ## Proposed Changes <!-- Please categorize your changes: - 🎁 Add new feature - 🐛 Fix bug - 🧹 Update or clean up current behavior - 🗑️ Remove feature or internal logic --> - Test broker ingress TLS key pair rotation - Test IMC dispatcher TLS key pair rotation ### Pre-review Checklist <!-- If these boxes are not checked, you will be asked to complete these requirements or explain why they do not apply to your PR. --> - [ ] **At least 80% unit test coverage** - [ ] **E2E tests** for any new behavior - [ ] **Docs PR** for any user-facing impact - [ ] **Spec PR** for any new API feature - [ ] **Conformance test** for any change to the spec **Release Note** <!-- 📄 If this change has user-visible impact, write a release note in the block below. Include the string "action required" if additional action is required of users switching to the new release, for example in case of a breaking change. Write as if you are speaking to users, not other Knative contributors. If this change has no user-visible impact, no release note is needed. --> ```release-note ``` **Docs** <!-- 📖 If this change has user-visible impact, link to an issue or PR in https://github.com/knative/docs. --> --------- Signed-off-by: Pierangelo Di Pilato <[email protected]>
- Loading branch information
Showing
17 changed files
with
599 additions
and
6 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
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,24 @@ | ||
# Copyright 2021 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 | ||
# | ||
# https://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. | ||
|
||
apiVersion: v1 | ||
kind: ConfigMap | ||
metadata: | ||
name: config-features | ||
namespace: knative-eventing | ||
labels: | ||
knative.dev/config-propagation: original | ||
knative.dev/config-category: eventing | ||
data: | ||
transport-encryption: "strict" |
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
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,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 | ||
} |
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,98 @@ | ||
/* | ||
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 channel | ||
|
||
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/channel_impl" | ||
"knative.dev/eventing/test/rekt/resources/subscription" | ||
) | ||
|
||
func RotateDispatcherTLSCertificate() *feature.Feature { | ||
certificateName := "imc-dispatcher-server-tls" | ||
secretName := "imc-dispatcher-server-tls" | ||
|
||
channelName := feature.MakeRandomK8sName("channel") | ||
subscriptionName := feature.MakeRandomK8sName("sub") | ||
sink := feature.MakeRandomK8sName("sink") | ||
source := feature.MakeRandomK8sName("source") | ||
|
||
f := feature.NewFeatureNamed("Rotate " + certificateName + " certificate") | ||
|
||
f.Prerequisite("transport encryption is strict", featureflags.TransportEncryptionStrict()) | ||
f.Prerequisite("should not run when Istio is enabled", featureflags.IstioDisabled()) | ||
|
||
f.Setup("Rotate certificate", certificate.Rotate(certificate.RotateCertificate{ | ||
Certificate: types.NamespacedName{ | ||
Namespace: system.Namespace(), | ||
Name: certificateName, | ||
}, | ||
})) | ||
|
||
f.Setup("install sink", eventshub.Install(sink, eventshub.StartReceiverTLS)) | ||
f.Setup("install channel", channel_impl.Install(channelName)) | ||
f.Setup("channel is ready", channel_impl.IsReady(channelName)) | ||
f.Setup("install subscription", func(ctx context.Context, t feature.T) { | ||
d := service.AsDestinationRef(sink) | ||
d.CACerts = eventshub.GetCaCerts(ctx) | ||
subscription.Install(subscriptionName, | ||
subscription.WithChannel(channel_impl.AsRef(channelName)), | ||
subscription.WithSubscriberFromDestination(d))(ctx, t) | ||
}) | ||
f.Setup("subscription is ready", subscription.IsReady(subscriptionName)) | ||
f.Setup("Channel has HTTPS address", channel_impl.ValidateAddress(channelName, addressable.AssertHTTPSAddress)) | ||
|
||
event := cetest.FullEvent() | ||
event.SetID(uuid.New().String()) | ||
|
||
f.Requirement("install source", eventshub.Install(source, | ||
eventshub.StartSenderToResourceTLS(channel_impl.GVR(), channelName, 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(), secretName, "tls.crt")). | ||
AtLeast(1), | ||
) | ||
|
||
return f | ||
} |
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.