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

Enable TLS for OIDC e2e tests #7551

Merged
merged 33 commits into from
Jan 18, 2024
Merged
Show file tree
Hide file tree
Changes from 26 commits
Commits
Show all changes
33 commits
Select commit Hold shift + click to select a range
d46ad64
Enable the TLS feature for BrokerSendEventWithOIDCTokenToSubscriber
Leo6Leo Jan 8, 2024
bc97023
Enable the TLS feature for BrokerSendEventWithOIDCTokenToReply
Leo6Leo Jan 8, 2024
7db5f0e
Save the progress on adding TLS support for BrokerSendEventWithOIDCTo…
Leo6Leo Jan 8, 2024
27678b1
Merge branch 'main' into enable-tls-for-broker-oidc-test
Leo6Leo Jan 9, 2024
53e8c40
Still couldn't figure out. Will leave a comment there
Leo6Leo Jan 9, 2024
765ff4e
Update more test to enable TLS
Leo6Leo Jan 9, 2024
ba9e0da
Merge branch 'main' into enable-tls-for-broker-oidc-test
Leo6Leo Jan 10, 2024
b9ed6db
Fix the review comments
Leo6Leo Jan 10, 2024
cb42428
Merge branch 'main' into enable-tls-for-broker-oidc-test
Leo6Leo Jan 11, 2024
eecf885
Fix the review comments by using destination object
Leo6Leo Jan 11, 2024
3ce0a71
Enable TLS in the CI
Leo6Leo Jan 11, 2024
ee4d57e
comment out all the other tests to validate my assumption
Leo6Leo Jan 12, 2024
c6b758d
Merge branch 'main' into enable-tls-for-broker-oidc-test
Leo6Leo Jan 15, 2024
dd5c43d
Merge branch 'main' into enable-tls-for-broker-oidc-test
Leo6Leo Jan 17, 2024
a05a5d9
Merge remote-tracking branch 'upstream/main' into enable-tls-for-brok…
Leo6Leo Jan 17, 2024
47935dc
Revert "comment out all the other tests to validate my assumption"
Leo6Leo Jan 17, 2024
72164dd
fix the wrong indentation for the cacert format
Leo6Leo Jan 17, 2024
ec2b5b7
enable the TLS for TestParallelTwoBranchesWithOIDCSupport
Leo6Leo Jan 17, 2024
1e21507
enable the TLS for TestSequenceSendsEventsWithOIDCSupport
Leo6Leo Jan 17, 2024
162b239
enable the TLS for TestApiserversourceSendEventWithJWT
Leo6Leo Jan 17, 2024
fc055e8
enable the TLS for TestContainerSourceSendsEventsWithOIDCSupport
Leo6Leo Jan 17, 2024
7a156b4
Update test/rekt/resources/sequence/sequence.go
Leo6Leo Jan 18, 2024
e567102
Update test/auth/features/oidc/broker.go
Leo6Leo Jan 18, 2024
3e84423
Update test/auth/features/oidc/broker.go
Leo6Leo Jan 18, 2024
41c9372
Update test/auth/features/oidc/parallel.go
Leo6Leo Jan 18, 2024
f0a6f31
Merge remote-tracking branch 'upstream/main' into enable-tls-for-brok…
Leo6Leo Jan 18, 2024
60463ba
Update test/auth/features/oidc/broker.go
Leo6Leo Jan 18, 2024
d82242a
enable the TLS for TestSequenceSendsEventsWithOIDCSupport
Leo6Leo Jan 18, 2024
3d42786
Merge remote-tracking branch 'origin/enable-tls-for-broker-oidc-test'…
Leo6Leo Jan 18, 2024
d7a180d
enable the TLS for TestPingSourceSendsEventsWithOIDC
Leo6Leo Jan 18, 2024
810b5e7
enable the TLS for TestChannelDispatcherAuthenticatesWithOIDC
Leo6Leo Jan 18, 2024
400c9f1
add the audience field
Leo6Leo Jan 18, 2024
0cf666c
Code clean up
Leo6Leo Jan 18, 2024
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 test/auth/config/features.yaml
Original file line number Diff line number Diff line change
Expand Up @@ -19,3 +19,5 @@ metadata:
namespace: knative-eventing
data:
authentication-oidc: "enabled"
transport-encryption: "strict"

8 changes: 4 additions & 4 deletions test/auth/features/oidc/addressable_oidc_conformance.go
Original file line number Diff line number Diff line change
Expand Up @@ -85,7 +85,7 @@ func addressableRejectInvalidAudience(gvr schema.GroupVersionResource, kind, nam

f.Requirement("install source", eventshub.Install(
source,
eventshub.StartSenderToResource(gvr, name),
eventshub.StartSenderToResourceTLS(gvr, name, nil),
eventshub.OIDCInvalidAudience(),
eventshub.InputEvent(event),
))
Expand All @@ -109,7 +109,7 @@ func addressableRejectExpiredToken(gvr schema.GroupVersionResource, kind, name s

f.Requirement("install source", eventshub.Install(
source,
eventshub.StartSenderToResource(gvr, name),
eventshub.StartSenderToResourceTLS(gvr, name, nil),
eventshub.OIDCExpiredToken(),
eventshub.InputEvent(event),
))
Expand All @@ -133,7 +133,7 @@ func addressableRejectCorruptedSignature(gvr schema.GroupVersionResource, kind,

f.Requirement("install source", eventshub.Install(
source,
eventshub.StartSenderToResource(gvr, name),
eventshub.StartSenderToResourceTLS(gvr, name, nil),
eventshub.OIDCCorruptedSignature(),
eventshub.InputEvent(event),
))
Expand All @@ -157,7 +157,7 @@ func addressableAllowsValidRequest(gvr schema.GroupVersionResource, kind, name s

f.Requirement("install source", eventshub.Install(
source,
eventshub.StartSenderToResource(gvr, name),
eventshub.StartSenderToResourceTLS(gvr, name, nil),
eventshub.InputEvent(event),
))

Expand Down
12 changes: 10 additions & 2 deletions test/auth/features/oidc/apiserversource.go
Original file line number Diff line number Diff line change
Expand Up @@ -19,6 +19,9 @@ package oidc
import (
"context"

"knative.dev/eventing/test/rekt/features/featureflags"
"knative.dev/eventing/test/rekt/features/source"

"github.com/cloudevents/sdk-go/v2/test"
rbacv1 "k8s.io/api/rbac/v1"
v1 "knative.dev/eventing/pkg/apis/sources/v1"
Expand All @@ -44,8 +47,11 @@ func ApiserversourceSendEventWithJWT() *feature.Feature {

f := feature.NewFeatureNamed("ApiServerSource send events with OIDC authentication")

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

f.Setup("deploy receiver", eventshub.Install(sink,
eventshub.StartReceiver,
eventshub.StartReceiverTLS,
eventshub.OIDCReceiverAudience(audience)))

f.Setup("Create Service Account for ApiServerSource with RBAC for v1.Event resources",
Expand All @@ -63,6 +69,7 @@ func ApiserversourceSendEventWithJWT() *feature.Feature {
f.Requirement("install ApiServerSource", func(ctx context.Context, t feature.T) {
d := service.AsDestinationRef(sink)
d.Audience = &audience
d.CACerts = eventshub.GetCaCerts(ctx)

cfg = append(cfg, apiserversource.WithSink(d))
apiserversource.Install(src, cfg...)(ctx, t)
Expand All @@ -81,7 +88,8 @@ func ApiserversourceSendEventWithJWT() *feature.Feature {
Match(eventassert.MatchKind(eventshub.EventReceived)).
MatchEvent(test.HasType("dev.knative.apiserver.resource.update")).
AtLeast(1),
)
).Must("Set sinkURI to HTTPS endpoint", source.ExpectHTTPSSink(apiserversource.Gvr(), src)).
Must("Set sinkCACerts to non empty CA certs", source.ExpectCACerts(apiserversource.Gvr(), src))

return f
}
Expand Down
115 changes: 75 additions & 40 deletions test/auth/features/oidc/broker.go
Original file line number Diff line number Diff line change
Expand Up @@ -17,8 +17,14 @@ limitations under the License.
package oidc

import (
"context"

"knative.dev/pkg/apis"

"github.com/cloudevents/sdk-go/v2/test"
"github.com/google/uuid"
"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/delivery"
"knative.dev/eventing/test/rekt/resources/trigger"
Expand All @@ -43,6 +49,10 @@ func BrokerSendEventWithOIDC() *feature.FeatureSet {
func BrokerSendEventWithOIDCTokenToSubscriber() *feature.Feature {
f := feature.NewFeatureNamed("Broker supports flow with OIDC tokens")

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

source := feature.MakeRandomK8sName("source")
brokerName := feature.MakeRandomK8sName("broker")
sink := feature.MakeRandomK8sName("sink")
Expand All @@ -55,28 +65,27 @@ func BrokerSendEventWithOIDCTokenToSubscriber() *feature.Feature {
f.Setup("install broker", broker.Install(brokerName, broker.WithEnvConfig()...))
f.Setup("broker is ready", broker.IsReady(brokerName))
f.Setup("broker is addressable", broker.IsAddressable(brokerName))
f.Setup("Broker has HTTPS address", broker.ValidateAddress(brokerName, addressable.AssertHTTPSAddress))

// Install the sink
f.Setup("install sink", eventshub.Install(
sink,
eventshub.StartReceiverTLS,
eventshub.OIDCReceiverAudience(sinkAudience),
eventshub.StartReceiver))

// Install the trigger and Point the Trigger subscriber to the sink svc.
f.Setup("install trigger", trigger.Install(
triggerName,
brokerName,
trigger.WithSubscriberFromDestination(&duckv1.Destination{
Ref: service.AsKReference(sink),
Audience: &sinkAudience,
}),
))

f.Setup("install the trigger and specify the CA cert of the destination", func(ctx context.Context, t feature.T) {
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I would simply name this step install the trigger, as you do some other configuration besides the CA too. Same in the other files.

d := service.AsDestinationRef(sink)
d.CACerts = eventshub.GetCaCerts(ctx)
d.Audience = &sinkAudience
trigger.Install(triggerName, brokerName, trigger.WithSubscriberFromDestination(d))(ctx, t)
})
f.Setup("trigger goes ready", trigger.IsReady(triggerName))

// Send event
f.Requirement("install source", eventshub.Install(
source,
eventshub.StartSenderToResource(broker.GVR(), brokerName),
eventshub.StartSenderToResourceTLS(broker.GVR(), brokerName, nil),
eventshub.InputEvent(event),
))

Expand All @@ -89,6 +98,10 @@ func BrokerSendEventWithOIDCTokenToSubscriber() *feature.Feature {
func BrokerSendEventWithOIDCTokenToDLS() *feature.Feature {
f := feature.NewFeature()

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

brokerName := feature.MakeRandomK8sName("broker")
dls := feature.MakeRandomK8sName("dls")
triggerName := feature.MakeRandomK8sName("trigger")
Expand All @@ -101,27 +114,37 @@ func BrokerSendEventWithOIDCTokenToDLS() *feature.Feature {
// Install DLS sink
f.Setup("install dead letter sink", eventshub.Install(dls,
eventshub.OIDCReceiverAudience(dlsAudience),
eventshub.StartReceiver))

// Install broker with DLS config
brokerConfig := append(
broker.WithEnvConfig(),
delivery.WithDeadLetterSinkFromDestination(&duckv1.Destination{
Ref: service.AsKReference(dls),
Audience: &dlsAudience,
}),
)
f.Setup("install broker", broker.Install(brokerName, brokerConfig...))
eventshub.StartReceiverTLS))

f.Setup("install broker", func(ctx context.Context, t feature.T) {
brokerConfig := append(broker.WithEnvConfig(),
delivery.WithDeadLetterSinkFromDestination(&duckv1.Destination{
Ref: service.AsKReference(dls),
Audience: &dlsAudience,
CACerts: eventshub.GetCaCerts(ctx),
}))
broker.Install(brokerName, brokerConfig...)(ctx, t)
})

f.Setup("Broker is ready", broker.IsReady(brokerName))

// FIXME: current progress left over here. Need to figure out why trigger cannot be initialized correctly.
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

leftover?

// Install Trigger
f.Setup("install trigger", trigger.Install(triggerName, brokerName,
trigger.WithSubscriber(nil, "bad://uri")))

f.Setup("install the trigger and specify the CA cert of the destination", func(ctx context.Context, t feature.T) {
// create an empty destination ref
d := duckv1.Destination{}
d.CACerts = eventshub.GetCaCerts(ctx)
d.URI, _ = apis.ParseURL("bad://uri")
trigger.Install(triggerName, brokerName, trigger.WithSubscriberFromDestination(&d))(ctx, t)

creydr marked this conversation as resolved.
Show resolved Hide resolved
})

f.Setup("trigger is ready", trigger.IsReady(triggerName))

// Send events after data plane is ready.
f.Requirement("install source", eventshub.Install(source,
eventshub.StartSenderToResource(broker.GVR(), brokerName),
eventshub.StartSenderToResourceTLS(broker.GVR(), brokerName, nil),
eventshub.InputEvent(event),
))

Expand All @@ -133,8 +156,17 @@ func BrokerSendEventWithOIDCTokenToDLS() *feature.Feature {
}

func BrokerSendEventWithOIDCTokenToReply() *feature.Feature {
//1. An event is sent to a broker.
//2. A trigger routes this event to a subscriber.
//3. The subscriber processes and replies to the event.
//4. A helper trigger routes the reply to a designated sink.
//5. The test verifies that the reply reaches the sink with the expected modifications.
f := feature.NewFeature()

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

brokerName := feature.MakeRandomK8sName("broker")
subscriber := feature.MakeRandomK8sName("subscriber")
reply := feature.MakeRandomK8sName("reply")
Expand All @@ -151,38 +183,41 @@ func BrokerSendEventWithOIDCTokenToReply() *feature.Feature {
// Install subscriber
f.Setup("install subscriber", eventshub.Install(subscriber,
eventshub.ReplyWithTransformedEvent(replyEventType, replyEventSource, ""),
eventshub.StartReceiver))
eventshub.StartReceiverTLS))

// Install sink for reply
// Hint: we don't need to require OIDC auth at the reply sink, because the
// actual reply is sent to the broker ingress, which must support OIDC. This
// reply sink is only to check that the reply as sent and routed correctly.
// reply sink is only to check that the reply was sent and routed correctly.
f.Setup("install sink for reply", eventshub.Install(reply,
eventshub.StartReceiver))
eventshub.StartReceiverTLS))

// Install broker
f.Setup("install broker", broker.Install(brokerName, broker.WithEnvConfig()...))
f.Setup("Broker is ready", broker.IsReady(brokerName))
f.Setup("Broker has HTTPS address", broker.ValidateAddress(brokerName, addressable.AssertHTTPSAddress))
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Not sure if we need this, as we have f.Prerequisite("transport encryption is strict", featureflags.TransportEncryptionStrict()). IMO this should be tested in a TLS related test 🤷


// Install Trigger
f.Setup("install trigger", trigger.Install(triggerName, brokerName,
trigger.WithSubscriber(service.AsKReference(subscriber), ""),
trigger.WithFilter(map[string]string{
f.Setup("install the trigger and specify the CA cert of the destination", func(ctx context.Context, t feature.T) {
d := service.AsDestinationRef(subscriber)
d.CACerts = eventshub.GetCaCerts(ctx)
trigger.Install(triggerName, brokerName, trigger.WithSubscriberFromDestination(d), trigger.WithFilter(map[string]string{
"type": event.Type(),
})))
}))(ctx, t)
})

f.Setup("trigger is ready", trigger.IsReady(triggerName))

// Install helper trigger to route replys to reply-sink
f.Setup("install helper trigger", trigger.Install(helperTriggerName, brokerName,
trigger.WithSubscriber(service.AsKReference(reply), ""),
trigger.WithFilter(map[string]string{
f.Setup("install the trigger and specify the CA cert of the destination", func(ctx context.Context, t feature.T) {
d := service.AsDestinationRef(reply)
d.CACerts = eventshub.GetCaCerts(ctx)
trigger.Install(helperTriggerName, brokerName, trigger.WithSubscriberFromDestination(d), trigger.WithFilter(map[string]string{
"type": replyEventType,
})))
f.Setup("helper trigger is ready", trigger.IsReady(helperTriggerName))
}))(ctx, t)
})

// Send events after data plane is ready.
f.Requirement("install source", eventshub.Install(source,
eventshub.StartSenderToResource(broker.GVR(), brokerName),
eventshub.StartSenderToResourceTLS(broker.GVR(), brokerName, nil),
eventshub.InputEvent(event),
))

Expand Down
32 changes: 21 additions & 11 deletions test/auth/features/oidc/containersource.go
Original file line number Diff line number Diff line change
Expand Up @@ -17,35 +17,45 @@ limitations under the License.
package oidc

import (
"context"

"github.com/cloudevents/sdk-go/v2/test"
"knative.dev/eventing/test/rekt/features/featureflags"
"knative.dev/eventing/test/rekt/features/source"
"knative.dev/eventing/test/rekt/resources/containersource"
duckv1 "knative.dev/pkg/apis/duck/v1"
"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"
)

func SendsEventsWithSinkRefOIDC() *feature.Feature {
source := feature.MakeRandomK8sName("containersource")
src := feature.MakeRandomK8sName("containersource")
sink := feature.MakeRandomK8sName("sink")
sinkAudience := "audience"
f := feature.NewFeature()

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

f.Setup("install sink", eventshub.Install(sink,
eventshub.OIDCReceiverAudience(sinkAudience),
eventshub.StartReceiver))
eventshub.StartReceiverTLS))

f.Requirement("install ContainerSource", func(ctx context.Context, t feature.T) {
d := service.AsDestinationRef(sink)
d.CACerts = eventshub.GetCaCerts(ctx)
d.Audience = &sinkAudience

f.Requirement("install containersource", containersource.Install(source,
containersource.WithSink(&duckv1.Destination{
Ref: service.AsKReference(sink),
Audience: &sinkAudience,
})))
f.Requirement("containersource goes ready", containersource.IsReady(source))
containersource.Install(src, containersource.WithSink(d))(ctx, t)
})

f.Requirement("containersource goes ready", containersource.IsReady(src))

f.Stable("containersource as event source").
Must("delivers events",
assert.OnStore(sink).MatchEvent(test.HasType("dev.knative.eventing.samples.heartbeat")).AtLeast(1))

assert.OnStore(sink).MatchEvent(test.HasType("dev.knative.eventing.samples.heartbeat")).AtLeast(1)).
Must("Set sinkURI to HTTPS endpoint", source.ExpectHTTPSSink(containersource.Gvr(), src)).
Must("Set sinkCACerts to non empty CA certs", source.ExpectCACerts(containersource.Gvr(), src))
return f
}
Loading
Loading