diff --git a/cmd/broker/filter/main.go b/cmd/broker/filter/main.go index 0ccb24ccb16..e491670f934 100644 --- a/cmd/broker/filter/main.go +++ b/cmd/broker/filter/main.go @@ -120,6 +120,8 @@ func main() { // Watch the observability config map and dynamically update request logs. configMapWatcher.Watch(logging.ConfigMapName(), logging.UpdateLevelFromConfigMap(sl, atomicLevel, component)) + trustBundleConfigMapLister := configmapinformer.Get(ctx, eventingtls.TrustBundleLabelSelector).Lister().ConfigMaps(system.Namespace()) + var featureStore *feature.Store var handler *filter.Handler @@ -134,7 +136,6 @@ func main() { } handler.EventTypeCreator = autoCreate } - }) featureStore.WatchConfigs(configMapWatcher) @@ -154,9 +155,8 @@ func main() { oidcTokenProvider := auth.NewOIDCTokenProvider(ctx) // We are running both the receiver (takes messages in from the Broker) and the dispatcher (send // the messages to the triggers' subscribers) in this binary. - authVerifier := auth.NewVerifier(ctx, eventpolicyinformer.Get(ctx).Lister()) - trustBundleConfigMapInformer := configmapinformer.Get(ctx, eventingtls.TrustBundleLabelSelector).Lister().ConfigMaps(system.Namespace()) - handler, err = filter.NewHandler(logger, authVerifier, oidcTokenProvider, triggerinformer.Get(ctx), brokerinformer.Get(ctx), subscriptioninformer.Get(ctx), reporter, trustBundleConfigMapInformer, ctxFunc) + authVerifier := auth.NewVerifier(ctx, eventpolicyinformer.Get(ctx).Lister(), trustBundleConfigMapLister, configMapWatcher) + handler, err = filter.NewHandler(logger, authVerifier, oidcTokenProvider, triggerinformer.Get(ctx), brokerinformer.Get(ctx), subscriptioninformer.Get(ctx), reporter, trustBundleConfigMapLister, ctxFunc) if err != nil { logger.Fatal("Error creating Handler", zap.Error(err)) } diff --git a/cmd/broker/ingress/main.go b/cmd/broker/ingress/main.go index 1b1b5c852b9..bd8e76d8fea 100644 --- a/cmd/broker/ingress/main.go +++ b/cmd/broker/ingress/main.go @@ -143,6 +143,8 @@ func main() { logger.Fatal("Error setting up trace publishing", zap.Error(err)) } + trustBundleConfigMapLister := configmapinformer.Get(ctx, eventingtls.TrustBundleLabelSelector).Lister().ConfigMaps(system.Namespace()) + var featureStore *feature.Store var handler *ingress.Handler @@ -168,9 +170,8 @@ func main() { reporter := ingress.NewStatsReporter(env.ContainerName, kmeta.ChildName(env.PodName, uuid.New().String())) oidcTokenProvider := auth.NewOIDCTokenProvider(ctx) - authVerifier := auth.NewVerifier(ctx, eventpolicyinformer.Get(ctx).Lister()) - trustBundleConfigMapInformer := configmapinformer.Get(ctx, eventingtls.TrustBundleLabelSelector).Lister().ConfigMaps(system.Namespace()) - handler, err = ingress.NewHandler(logger, reporter, broker.TTLDefaulter(logger, int32(env.MaxTTL)), brokerInformer, authVerifier, oidcTokenProvider, trustBundleConfigMapInformer, ctxFunc) + authVerifier := auth.NewVerifier(ctx, eventpolicyinformer.Get(ctx).Lister(), trustBundleConfigMapLister, configMapWatcher) + handler, err = ingress.NewHandler(logger, reporter, broker.TTLDefaulter(logger, int32(env.MaxTTL)), brokerInformer, authVerifier, oidcTokenProvider, trustBundleConfigMapLister, ctxFunc) if err != nil { logger.Fatal("Error creating Handler", zap.Error(err)) } diff --git a/cmd/jobsink/main.go b/cmd/jobsink/main.go index d06dafdfd84..a79cf5d7655 100644 --- a/cmd/jobsink/main.go +++ b/cmd/jobsink/main.go @@ -25,6 +25,9 @@ import ( "net/http" "strings" + configmapinformer "knative.dev/pkg/client/injection/kube/informers/core/v1/configmap/filtered" + filteredFactory "knative.dev/pkg/client/injection/kube/informers/factory/filtered" + "github.com/cloudevents/sdk-go/v2/binding" cehttp "github.com/cloudevents/sdk-go/v2/protocol/http" "go.uber.org/zap" @@ -70,9 +73,13 @@ func main() { cfg := injection.ParseAndGetRESTConfigOrDie() ctx = injection.WithConfig(ctx, cfg) + ctx = filteredFactory.WithSelectors(ctx, + eventingtls.TrustBundleLabelSelector, + ) ctx, informers := injection.Default.SetupInformers(ctx, cfg) ctx = injection.WithConfig(ctx, cfg) + loggingConfig, err := cmdbroker.GetLoggingConfig(ctx, system.Namespace(), logging.ConfigMapName()) if err != nil { log.Fatal("Error loading/parsing logging configuration:", err) @@ -104,9 +111,10 @@ func main() { logger.Info("Starting the JobSink Ingress") - featureStore := feature.NewStore(logging.FromContext(ctx).Named("feature-config-store"), func(name string, value interface{}) { - logger.Info("Updated", zap.String("name", name), zap.Any("value", value)) - }) + trustBundleConfigMapLister := configmapinformer.Get(ctx, eventingtls.TrustBundleLabelSelector).Lister().ConfigMaps(system.Namespace()) + var h *Handler + + featureStore := feature.NewStore(logging.FromContext(ctx).Named("feature-config-store")) featureStore.WatchConfigs(configMapWatcher) // Decorate contexts with the current state of the feature config. @@ -114,11 +122,11 @@ func main() { return logging.WithLogger(featureStore.ToContext(ctx), sl) } - h := &Handler{ + h = &Handler{ k8s: kubeclient.Get(ctx), lister: jobsink.Get(ctx).Lister(), withContext: ctxFunc, - authVerifier: auth.NewVerifier(ctx, eventpolicyinformer.Get(ctx).Lister()), + authVerifier: auth.NewVerifier(ctx, eventpolicyinformer.Get(ctx).Lister(), trustBundleConfigMapLister, configMapWatcher), } tlsConfig, err := getServerTLSConfig(ctx) diff --git a/pkg/apis/feature/features.go b/pkg/apis/feature/features.go index b2ca380fc77..98eeb2907ca 100644 --- a/pkg/apis/feature/features.go +++ b/pkg/apis/feature/features.go @@ -64,6 +64,9 @@ const ( // This configuration is applied when there is no EventPolicy with a "to" referencing a given // resource. AuthorizationAllowSameNamespace Flag = "Allow-Same-Namespace" + + // DefaultOIDCDiscoveryURL is the default OIDC Discovery URL used in most Kubernetes clusters. + DefaultOIDCDiscoveryBaseURL Flag = "https://kubernetes.default.svc" ) // Flags is a map containing all the enabled/disabled flags for the experimental features. @@ -81,6 +84,7 @@ func newDefaults() Flags { EvenTypeAutoCreate: Disabled, NewAPIServerFilters: Disabled, AuthorizationDefaultMode: AuthorizationAllowSameNamespace, + OIDCDiscoveryBaseURL: DefaultOIDCDiscoveryBaseURL, } } @@ -134,6 +138,19 @@ func (e Flags) IsAuthorizationDefaultModeSameNamespace() bool { return e != nil && e[AuthorizationDefaultMode] == AuthorizationAllowSameNamespace } +func (e Flags) OIDCDiscoveryBaseURL() string { + if e == nil { + return string(DefaultOIDCDiscoveryBaseURL) + } + + discoveryUrl, ok := e[OIDCDiscoveryBaseURL] + if !ok { + return string(DefaultOIDCDiscoveryBaseURL) + } + + return string(discoveryUrl) +} + func (e Flags) String() string { return fmt.Sprintf("%+v", map[string]Flag(e)) } @@ -183,7 +200,7 @@ func NewFlagsConfigFromMap(data map[string]string) (Flags, error) { flags[sanitizedKey] = AuthorizationDenyAll } else if sanitizedKey == AuthorizationDefaultMode && strings.EqualFold(v, string(AuthorizationAllowSameNamespace)) { flags[sanitizedKey] = AuthorizationAllowSameNamespace - } else if strings.Contains(k, NodeSelectorLabel) { + } else if strings.Contains(k, NodeSelectorLabel) || sanitizedKey == OIDCDiscoveryBaseURL { flags[sanitizedKey] = Flag(v) } else { flags[k] = Flag(v) diff --git a/pkg/apis/feature/features_test.go b/pkg/apis/feature/features_test.go index 5b7caa8404a..34d899d2209 100644 --- a/pkg/apis/feature/features_test.go +++ b/pkg/apis/feature/features_test.go @@ -61,6 +61,8 @@ func TestGetFlags(t *testing.T) { nodeSelector := flags.NodeSelector() expectedNodeSelector := map[string]string{"testkey": "testvalue", "testkey1": "testvalue1", "testkey2": "testvalue2"} require.Equal(t, expectedNodeSelector, nodeSelector) + + require.Equal(t, flags.OIDCDiscoveryBaseURL(), "https://oidc.eks.eu-west-1.amazonaws.com/id/1") } func TestShouldNotOverrideDefaults(t *testing.T) { diff --git a/pkg/apis/feature/flag_names.go b/pkg/apis/feature/flag_names.go index 6a7579fb710..e21056eb444 100644 --- a/pkg/apis/feature/flag_names.go +++ b/pkg/apis/feature/flag_names.go @@ -28,4 +28,5 @@ const ( CrossNamespaceEventLinks = "cross-namespace-event-links" NewAPIServerFilters = "new-apiserversource-filters" AuthorizationDefaultMode = "default-authorization-mode" + OIDCDiscoveryBaseURL = "oidc-discovery-base-url" ) diff --git a/pkg/apis/feature/testdata/config-features.yaml b/pkg/apis/feature/testdata/config-features.yaml index 6c3252ba429..bebbfea4b79 100644 --- a/pkg/apis/feature/testdata/config-features.yaml +++ b/pkg/apis/feature/testdata/config-features.yaml @@ -29,3 +29,4 @@ data: apiserversources-nodeselector-testkey: testvalue apiserversources-nodeselector-testkey1: testvalue1 apiserversources-nodeselector-testkey2: testvalue2 + oidc-discovery-base-url: "https://oidc.eks.eu-west-1.amazonaws.com/id/1" diff --git a/pkg/auth/verifier.go b/pkg/auth/verifier.go index 3cf9c436bc8..df5c9d402df 100644 --- a/pkg/auth/verifier.go +++ b/pkg/auth/verifier.go @@ -22,10 +22,19 @@ import ( "encoding/json" "fmt" "io" + "net" "net/http" "strings" + "sync" "time" + "go.opencensus.io/plugin/ochttp" + corev1listers "k8s.io/client-go/listers/core/v1" + "knative.dev/eventing/pkg/eventingtls" + "knative.dev/pkg/configmap" + "knative.dev/pkg/network" + "knative.dev/pkg/tracing/propagation/tracecontextb3" + duckv1 "knative.dev/eventing/pkg/apis/duck/v1" "knative.dev/eventing/pkg/client/listers/eventing/v1alpha1" @@ -41,15 +50,13 @@ import ( "knative.dev/pkg/logging" ) -const ( - kubernetesOIDCDiscoveryBaseURL = "https://kubernetes.default.svc" -) - type Verifier struct { - logger *zap.SugaredLogger - restConfig *rest.Config - provider *oidc.Provider - eventPolicyLister v1alpha1.EventPolicyLister + logger *zap.SugaredLogger + restConfig *rest.Config + eventPolicyLister v1alpha1.EventPolicyLister + trustBundleConfigMapLister corev1listers.ConfigMapNamespaceLister + m sync.RWMutex + provider *oidc.Provider } type IDToken struct { @@ -61,14 +68,24 @@ type IDToken struct { AccessTokenHash string } -func NewVerifier(ctx context.Context, eventPolicyLister listerseventingv1alpha1.EventPolicyLister) *Verifier { +func NewVerifier(ctx context.Context, eventPolicyLister listerseventingv1alpha1.EventPolicyLister, trustBundleConfigMapLister corev1listers.ConfigMapNamespaceLister, cmw configmap.Watcher) *Verifier { tokenHandler := &Verifier{ - logger: logging.FromContext(ctx).With("component", "oidc-token-handler"), - restConfig: injection.GetConfig(ctx), - eventPolicyLister: eventPolicyLister, + logger: logging.FromContext(ctx).With("component", "oidc-token-handler"), + restConfig: injection.GetConfig(ctx), + eventPolicyLister: eventPolicyLister, + trustBundleConfigMapLister: trustBundleConfigMapLister, } - if err := tokenHandler.initOIDCProvider(ctx); err != nil { + featureStore := feature.NewStore(logging.FromContext(ctx).Named("feature-config-store"), func(name string, value interface{}) { + if features, ok := value.(feature.Flags); ok { + if err := tokenHandler.initOIDCProvider(ctx, features); err != nil { + tokenHandler.logger.Error(fmt.Sprintf("could not initialize provider after config update. You can ignore this message, when the %s feature is disabled", feature.OIDCAuthentication), zap.Error(err)) + } + } + }) + featureStore.WatchConfigs(cmw) + + if err := tokenHandler.initOIDCProvider(ctx, featureStore.Load()); err != nil { tokenHandler.logger.Error(fmt.Sprintf("could not initialize provider. You can ignore this message, when the %s feature is disabled", feature.OIDCAuthentication), zap.Error(err)) } @@ -196,6 +213,9 @@ func (v *Verifier) verifyAuthZ(ctx context.Context, features feature.Flags, idTo // verifyJWT verifies the given JWT for the expected audience and returns the parsed ID token. func (v *Verifier) verifyJWT(ctx context.Context, jwt, audience string) (*IDToken, error) { + v.m.RLock() + defer v.m.RUnlock() + if v.provider == nil { return nil, fmt.Errorf("provider is nil. Is the OIDC provider config correct?") } @@ -219,29 +239,35 @@ func (v *Verifier) verifyJWT(ctx context.Context, jwt, audience string) (*IDToke }, nil } -func (v *Verifier) initOIDCProvider(ctx context.Context) error { - discovery, err := v.getKubernetesOIDCDiscovery() +func (v *Verifier) initOIDCProvider(ctx context.Context, features feature.Flags) error { + httpClient, err := v.getHTTPClient(features) + if err != nil { + return fmt.Errorf("could not get HTTP client: %w", err) + } + + discovery, err := v.getKubernetesOIDCDiscovery(features, httpClient) if err != nil { return fmt.Errorf("could not load Kubernetes OIDC discovery information: %w", err) } - if discovery.Issuer != kubernetesOIDCDiscoveryBaseURL { + if discovery.Issuer != features.OIDCDiscoveryBaseURL() { // in case we have another issuer as the api server: ctx = oidc.InsecureIssuerURLContext(ctx, discovery.Issuer) } - httpClient, err := v.getHTTPClientForKubeAPIServer() - if err != nil { - return fmt.Errorf("could not get HTTP client with TLS certs of API server: %w", err) - } ctx = oidc.ClientContext(ctx, httpClient) // get OIDC provider - v.provider, err = oidc.NewProvider(ctx, kubernetesOIDCDiscoveryBaseURL) + provider, err := oidc.NewProvider(ctx, features.OIDCDiscoveryBaseURL()) if err != nil { return fmt.Errorf("could not get OIDC provider: %w", err) } + // provider is valid, update it + v.m.Lock() + defer v.m.Unlock() + v.provider = provider + v.logger.Debug("updated OIDC provider config", zap.Any("discovery-config", discovery)) return nil @@ -256,13 +282,38 @@ func (v *Verifier) getHTTPClientForKubeAPIServer() (*http.Client, error) { return client, nil } -func (v *Verifier) getKubernetesOIDCDiscovery() (*openIDMetadata, error) { - client, err := v.getHTTPClientForKubeAPIServer() - if err != nil { - return nil, fmt.Errorf("could not get HTTP client for API server: %w", err) +func (v *Verifier) getHTTPClient(features feature.Flags) (*http.Client, error) { + if features.OIDCDiscoveryBaseURL() == "https://kubernetes.default.svc" { + return v.getHTTPClientForKubeAPIServer() + } + + var base = http.DefaultTransport.(*http.Transport).Clone() + + clientConfig := eventingtls.ClientConfig{ + TrustBundleConfigMapLister: v.trustBundleConfigMapLister, } - resp, err := client.Get(kubernetesOIDCDiscoveryBaseURL + "/.well-known/openid-configuration") + base.DialTLSContext = func(ctx context.Context, net, addr string) (net.Conn, error) { + tlsConfig, err := eventingtls.GetTLSClientConfig(clientConfig) + if err != nil { + return nil, fmt.Errorf("could not get tls client config: %w", err) + } + return network.DialTLSWithBackOff(ctx, net, addr, tlsConfig) + } + + client := &http.Client{ + // Add output tracing. + Transport: &ochttp.Transport{ + Base: base, + Propagation: tracecontextb3.TraceContextEgress, + }, + } + + return client, nil +} + +func (v *Verifier) getKubernetesOIDCDiscovery(features feature.Flags, client *http.Client) (*openIDMetadata, error) { + resp, err := client.Get(features.OIDCDiscoveryBaseURL() + "/.well-known/openid-configuration") if err != nil { return nil, fmt.Errorf("could not get response: %w", err) } diff --git a/pkg/broker/filter/filter_handler_test.go b/pkg/broker/filter/filter_handler_test.go index 6f020d8870d..b15f2fde3df 100644 --- a/pkg/broker/filter/filter_handler_test.go +++ b/pkg/broker/filter/filter_handler_test.go @@ -27,6 +27,11 @@ import ( "testing" "time" + "knative.dev/eventing/pkg/eventingtls" + filteredFactory "knative.dev/pkg/client/injection/kube/informers/factory/filtered" + "knative.dev/pkg/configmap" + "knative.dev/pkg/system" + messagingv1 "knative.dev/eventing/pkg/apis/messaging/v1" "knative.dev/eventing/pkg/reconciler/broker/resources" @@ -38,10 +43,12 @@ import ( "go.uber.org/atomic" "go.uber.org/zap" "go.uber.org/zap/zaptest" + corev1 "k8s.io/api/core/v1" metav1 "k8s.io/apimachinery/pkg/apis/meta/v1" "k8s.io/apimachinery/pkg/types" "knative.dev/pkg/apis" configmapinformer "knative.dev/pkg/client/injection/kube/informers/core/v1/configmap/fake" + filteredconfigmapinformer "knative.dev/pkg/client/injection/kube/informers/core/v1/configmap/filtered/fake" "knative.dev/pkg/logging" reconcilertesting "knative.dev/pkg/reconciler/testing" @@ -60,6 +67,7 @@ import ( // Fake injection client _ "knative.dev/eventing/pkg/client/injection/informers/eventing/v1alpha1/eventpolicy/fake" _ "knative.dev/pkg/client/injection/kube/client/fake" + _ "knative.dev/pkg/client/injection/kube/informers/factory/filtered/fake" ) const ( @@ -425,10 +433,11 @@ func TestReceiver(t *testing.T) { } for n, tc := range testCases { t.Run(n, func(t *testing.T) { - ctx, _ := reconcilertesting.SetupFakeContext(t) + ctx, _ := reconcilertesting.SetupFakeContext(t, SetUpInformerSelector) ctx = feature.ToContext(ctx, feature.Flags{ feature.OIDCAuthentication: feature.Enabled, }) + trustBundleConfigMapLister := filteredconfigmapinformer.Get(ctx, eventingtls.TrustBundleLabelSelector).Lister().ConfigMaps(system.Namespace()) fh := fakeHandler{ failRequest: tc.requestFails, @@ -444,7 +453,17 @@ func TestReceiver(t *testing.T) { logger := zaptest.NewLogger(t, zaptest.WrapOptions(zap.AddCaller())) oidcTokenProvider := auth.NewOIDCTokenProvider(ctx) - authVerifier := auth.NewVerifier(ctx, eventpolicyinformerfake.Get(ctx).Lister()) + authVerifier := auth.NewVerifier(ctx, eventpolicyinformerfake.Get(ctx).Lister(), trustBundleConfigMapLister, configmap.NewStaticWatcher( + &corev1.ConfigMap{ + ObjectMeta: metav1.ObjectMeta{ + Name: "config-features", + Namespace: "knative-eventing", + }, + Data: map[string]string{ + feature.OIDCAuthentication: string(feature.Enabled), + }, + }, + )) for _, trig := range tc.triggers { // Replace the SubscriberURI to point at our fake server. @@ -641,7 +660,8 @@ func TestReceiver_WithSubscriptionsAPI(t *testing.T) { } for n, tc := range testCases { t.Run(n, func(t *testing.T) { - ctx, _ := reconcilertesting.SetupFakeContext(t) + ctx, _ := reconcilertesting.SetupFakeContext(t, SetUpInformerSelector) + trustBundleConfigMapLister := filteredconfigmapinformer.Get(ctx, eventingtls.TrustBundleLabelSelector).Lister().ConfigMaps(system.Namespace()) fh := fakeHandler{ t: t, @@ -653,7 +673,17 @@ func TestReceiver_WithSubscriptionsAPI(t *testing.T) { logger := zaptest.NewLogger(t, zaptest.WrapOptions(zap.AddCaller())) oidcTokenProvider := auth.NewOIDCTokenProvider(ctx) - authVerifier := auth.NewVerifier(ctx, eventpolicyinformerfake.Get(ctx).Lister()) + authVerifier := auth.NewVerifier(ctx, eventpolicyinformerfake.Get(ctx).Lister(), trustBundleConfigMapLister, configmap.NewStaticWatcher( + &corev1.ConfigMap{ + ObjectMeta: metav1.ObjectMeta{ + Name: "config-features", + Namespace: "knative-eventing", + }, + Data: map[string]string{ + feature.OIDCAuthentication: string(feature.Enabled), + }, + }, + )) // Replace the SubscriberURI to point at our fake server. for _, trig := range tc.triggers { @@ -989,3 +1019,8 @@ func makeEmptyResponse(status int) *http.Response { } return r } + +func SetUpInformerSelector(ctx context.Context) context.Context { + ctx = filteredFactory.WithSelectors(ctx, eventingtls.TrustBundleLabelSelector) + return ctx +} diff --git a/pkg/broker/ingress/ingress_handler_test.go b/pkg/broker/ingress/ingress_handler_test.go index 37982bd27ac..f30174c1476 100644 --- a/pkg/broker/ingress/ingress_handler_test.go +++ b/pkg/broker/ingress/ingress_handler_test.go @@ -26,20 +26,28 @@ import ( "testing" "time" + "knative.dev/eventing/pkg/eventingtls" + filteredconfigmapinformer "knative.dev/pkg/client/injection/kube/informers/core/v1/configmap/filtered/fake" + filteredFactory "knative.dev/pkg/client/injection/kube/informers/factory/filtered" + "knative.dev/pkg/system" + "github.com/cloudevents/sdk-go/v2/client" "github.com/cloudevents/sdk-go/v2/event" cehttp "github.com/cloudevents/sdk-go/v2/protocol/http" "github.com/google/go-cmp/cmp" "go.uber.org/zap" + corev1 "k8s.io/api/core/v1" metav1 "k8s.io/apimachinery/pkg/apis/meta/v1" configmapinformer "knative.dev/pkg/client/injection/kube/informers/core/v1/configmap/fake" duckv1 "knative.dev/pkg/apis/duck/v1" + "knative.dev/pkg/configmap" reconcilertesting "knative.dev/pkg/reconciler/testing" "knative.dev/eventing/pkg/apis/eventing" eventingv1 "knative.dev/eventing/pkg/apis/eventing/v1" + "knative.dev/eventing/pkg/apis/feature" "knative.dev/eventing/pkg/auth" "knative.dev/eventing/pkg/broker" @@ -49,6 +57,7 @@ import ( // Fake injection client _ "knative.dev/eventing/pkg/client/injection/informers/eventing/v1alpha1/eventpolicy/fake" _ "knative.dev/pkg/client/injection/kube/client/fake" + _ "knative.dev/pkg/client/injection/kube/informers/factory/filtered/fake" ) const ( @@ -262,7 +271,8 @@ func TestHandler_ServeHTTP(t *testing.T) { for _, tc := range tt { t.Run(tc.name, func(t *testing.T) { - ctx, _ := reconcilertesting.SetupFakeContext(t) + ctx, _ := reconcilertesting.SetupFakeContext(t, SetUpInformerSelector) + trustBundleConfigMapLister := filteredconfigmapinformer.Get(ctx, eventingtls.TrustBundleLabelSelector).Lister().ConfigMaps(system.Namespace()) s := httptest.NewServer(tc.handler) defer s.Close() @@ -291,7 +301,17 @@ func TestHandler_ServeHTTP(t *testing.T) { } tokenProvider := auth.NewOIDCTokenProvider(ctx) - authVerifier := auth.NewVerifier(ctx, eventpolicyinformerfake.Get(ctx).Lister()) + authVerifier := auth.NewVerifier(ctx, eventpolicyinformerfake.Get(ctx).Lister(), trustBundleConfigMapLister, configmap.NewStaticWatcher( + &corev1.ConfigMap{ + ObjectMeta: metav1.ObjectMeta{ + Name: "config-features", + Namespace: "knative-eventing", + }, + Data: map[string]string{ + feature.OIDCAuthentication: string(feature.Enabled), + }, + }, + )) h, err := NewHandler(logger, &mockReporter{}, @@ -401,3 +421,8 @@ func withUninitializedAnnotations(b *eventingv1.Broker) *eventingv1.Broker { b.Status.Annotations = nil return b } + +func SetUpInformerSelector(ctx context.Context) context.Context { + ctx = filteredFactory.WithSelectors(ctx, eventingtls.TrustBundleLabelSelector) + return ctx +} diff --git a/pkg/reconciler/inmemorychannel/dispatcher/controller.go b/pkg/reconciler/inmemorychannel/dispatcher/controller.go index a919ef7a2d7..2eac2c0771c 100644 --- a/pkg/reconciler/inmemorychannel/dispatcher/controller.go +++ b/pkg/reconciler/inmemorychannel/dispatcher/controller.go @@ -88,7 +88,7 @@ func NewController( ) *controller.Impl { logger := logging.FromContext(ctx) - trustBundleConfigMapInformer := filteredconfigmapinformer.Get(ctx, eventingtls.TrustBundleLabelSelector) + trustBundleConfigMapLister := filteredconfigmapinformer.Get(ctx, eventingtls.TrustBundleLabelSelector).Lister().ConfigMaps(system.Namespace()) // Setup trace publishing. iw := cmw.(*configmapinformer.InformedWatcher) @@ -127,9 +127,18 @@ func NewController( oidcTokenProvider := auth.NewOIDCTokenProvider(ctx) clientConfig := eventingtls.ClientConfig{ - TrustBundleConfigMapLister: trustBundleConfigMapInformer.Lister().ConfigMaps(system.Namespace()), + TrustBundleConfigMapLister: trustBundleConfigMapLister, } + var globalResync func(obj interface{}) + + featureStore := feature.NewStore(logging.FromContext(ctx).Named("feature-config-store"), func(_ string, _ interface{}) { + if globalResync != nil { + globalResync(nil) + } + }) + + featureStore.WatchConfigs(cmw) r := &Reconciler{ multiChannelEventHandler: sh, reporter: reporter, @@ -137,20 +146,11 @@ func NewController( eventingClient: eventingclient.Get(ctx).EventingV1beta2(), eventTypeLister: eventtypeinformer.Get(ctx).Lister(), eventDispatcher: kncloudevents.NewDispatcher(clientConfig, oidcTokenProvider), - authVerifier: auth.NewVerifier(ctx, eventpolicyinformer.Get(ctx).Lister()), + authVerifier: auth.NewVerifier(ctx, eventpolicyinformer.Get(ctx).Lister(), trustBundleConfigMapLister, cmw), clientConfig: clientConfig, inMemoryChannelLister: inmemorychannelInformer.Lister(), } - var globalResync func(obj interface{}) - - featureStore := feature.NewStore(logging.FromContext(ctx).Named("feature-config-store"), func(_ string, _ interface{}) { - if globalResync != nil { - globalResync(nil) - } - }) - featureStore.WatchConfigs(cmw) - impl := inmemorychannelreconciler.NewImpl(ctx, r, func(impl *controller.Impl) controller.Options { return controller.Options{SkipStatusUpdates: true, FinalizerName: finalizerName, ConfigStore: featureStore} })