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

Use mt-broker-filter as the Audience of a Triggers Subscriptions Subscriber #7319

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
10 changes: 8 additions & 2 deletions pkg/reconciler/broker/trigger/trigger.go
Original file line number Diff line number Diff line change
Expand Up @@ -62,6 +62,8 @@ const (
subscriptionDeleteFailed = "SubscriptionDeleteFailed"
subscriptionCreateFailed = "SubscriptionCreateFailed"
subscriptionGetFailed = "SubscriptionGetFailed"

FilterAudience = "mt-broker-filter"
)

type Reconciler struct {
Expand Down Expand Up @@ -207,8 +209,8 @@ func (r *Reconciler) resolveDeadLetterSink(ctx context.Context, b *eventingv1.Br
// subscribeToBrokerChannel subscribes service 'svc' to the Broker's channels.
func (r *Reconciler) subscribeToBrokerChannel(ctx context.Context, b *eventingv1.Broker, t *eventingv1.Trigger, brokerTrigger *corev1.ObjectReference) (*messagingv1.Subscription, error) {
var dest *duckv1.Destination
transportEncryptionFlags := feature.FromContext(ctx)
if transportEncryptionFlags.IsPermissiveTransportEncryption() || transportEncryptionFlags.IsStrictTransportEncryption() {
featureFlags := feature.FromContext(ctx)
if featureFlags.IsPermissiveTransportEncryption() || featureFlags.IsStrictTransportEncryption() {
caCerts, err := r.getCaCerts()
if err != nil {
return nil, fmt.Errorf("failed to get CA certs: %w", err)
Expand All @@ -232,6 +234,10 @@ func (r *Reconciler) subscribeToBrokerChannel(ctx context.Context, b *eventingv1
}
}

if featureFlags.IsOIDCAuthentication() {
dest.Audience = pointer.String(FilterAudience)
}
pierDipi marked this conversation as resolved.
Show resolved Hide resolved

// Note that we have to hard code the brokerGKV stuff as sometimes typemeta is not
// filled in. So instead of b.TypeMeta.Kind and b.TypeMeta.APIVersion, we have to
// do it this way.
Expand Down
60 changes: 58 additions & 2 deletions pkg/reconciler/broker/trigger/trigger_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -1493,7 +1493,7 @@ func TestReconcile(t *testing.T) {
feature.OIDCAuthentication: feature.Enabled,
}),
Objects: allBrokerObjectsReadyPlus([]runtime.Object{
makeReadySubscription(testNS),
makeReadySubscriptionWithAudience(testNS),
NewTrigger(triggerName, testNS, brokerName,
WithTriggerUID(triggerUID),
WithTriggerSubscriberURI(subscriberURI),
Expand Down Expand Up @@ -1527,7 +1527,7 @@ func TestReconcile(t *testing.T) {
feature.OIDCAuthentication: feature.Enabled,
}),
Objects: allBrokerObjectsReadyPlus([]runtime.Object{
makeReadySubscription(testNS),
makeReadySubscriptionWithAudience(testNS),
makeTriggerOIDCServiceAccountWithoutOwnerRef(),
NewTrigger(triggerName, testNS, brokerName,
WithTriggerUID(triggerUID),
Expand Down Expand Up @@ -1556,6 +1556,49 @@ func TestReconcile(t *testing.T) {
Eventf(corev1.EventTypeWarning, "InternalError", fmt.Sprintf("service account %s not owned by Trigger %s", makeTriggerOIDCServiceAccountWithoutOwnerRef().Name, triggerName)),
},
},
{
Name: "OIDC: set Audience of broker-filter in Subscription",
Key: testKey,
Ctx: feature.ToContext(context.Background(), feature.Flags{
feature.OIDCAuthentication: feature.Enabled,
}),
Objects: allBrokerObjectsReadyPlus([]runtime.Object{
makeReadySubscription(testNS),
makeTriggerOIDCServiceAccount(),
NewTrigger(triggerName, testNS, brokerName,
WithTriggerUID(triggerUID),
WithTriggerSubscriberURI(subscriberURI),
WithInitTriggerConditions,
)}...),
WantErr: false,
WantStatusUpdates: []clientgotesting.UpdateActionImpl{{
Object: NewTrigger(triggerName, testNS, brokerName,
WithTriggerUID(triggerUID),
WithTriggerSubscriberURI(subscriberURI),
WithTriggerBrokerReady(),
// The first reconciliation will initialize the status conditions.
WithInitTriggerConditions,
WithTriggerDependencyReady(),
WithTriggerSubscribed(),
WithTriggerStatusSubscriberURI(subscriberURI),
WithTriggerSubscriberResolvedSucceeded(),
WithTriggerDeadLetterSinkNotConfigured(),
WithTriggerSubscriptionNotConfigured(),
WithTriggerOIDCIdentityCreatedSucceeded(),
WithTriggerOIDCServiceAccountName(makeTriggerOIDCServiceAccount().Name),
),
}},
WantCreates: []runtime.Object{
resources.NewSubscription(makeTrigger(testNS), createTriggerChannelRef(), makeBrokerRef(), makeServiceURIWithAudience(), makeEmptyDelivery()),
},
WantDeletes: []clientgotesting.DeleteActionImpl{{
ActionImpl: clientgotesting.ActionImpl{
Namespace: testNS,
Resource: eventingduckv1.SchemeGroupVersion.WithResource("subscriptions"),
},
Name: subscriptionName,
}},
},
}

logger := logtesting.TestLogger(t)
Expand Down Expand Up @@ -1696,6 +1739,13 @@ func makeServiceURI() *duckv1.Destination {
}
}

func makeServiceURIWithAudience() *duckv1.Destination {
dst := makeServiceURI()
dst.Audience = ptr.String(FilterAudience)

return dst
}

func makeServiceURIHTTPS() *duckv1.Destination {
return &duckv1.Destination{
URI: &apis.URL{
Expand Down Expand Up @@ -1807,6 +1857,12 @@ func makeReadySubscription(subscriberNamespace string) *messagingv1.Subscription
return s
}

func makeReadySubscriptionWithAudience(subscriberNamespace string) *messagingv1.Subscription {
s := makeReadySubscription(subscriberNamespace)
s.Spec.Subscriber.Audience = ptr.String(FilterAudience)
return s
}

func makeSubscriberAddressableAsUnstructured(subscriberNamespace string) *unstructured.Unstructured {
return &unstructured.Unstructured{
Object: map[string]interface{}{
Expand Down
Loading