Skip to content

Commit 4d75af9

Browse files
committed
configobservation/auth: remove webhook token authenticator when auth type is OIDC
1 parent 846e179 commit 4d75af9

File tree

2 files changed

+14
-2
lines changed

2 files changed

+14
-2
lines changed

pkg/operator/configobservation/auth/webhook_authenticator.go

Lines changed: 12 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -11,6 +11,7 @@ import (
1111
"k8s.io/client-go/tools/clientcmd"
1212
clientcmdapi "k8s.io/client-go/tools/clientcmd/api"
1313

14+
configv1 "github.com/openshift/api/config/v1"
1415
"github.com/openshift/library-go/pkg/operator/configobserver"
1516
"github.com/openshift/library-go/pkg/operator/events"
1617
"github.com/openshift/library-go/pkg/operator/resourcesynccontroller"
@@ -51,6 +52,7 @@ func ObserveWebhookTokenAuthenticator(genericListers configobserver.Listers, rec
5152

5253
auth, err := listers.AuthConfigLister.Get("cluster")
5354
if errors.IsNotFound(err) {
55+
recorder.Eventf("ObserveWebhookTokenAuthenticator", "authentications.config.openshift.io/cluster: not found")
5456
return observedConfig, nil
5557
} else if err != nil {
5658
return existingConfig, append(errs, err)
@@ -62,7 +64,7 @@ func ObserveWebhookTokenAuthenticator(genericListers configobserver.Listers, rec
6264
}
6365

6466
observedWebhookConfigured := len(webhookSecretName) > 0
65-
if observedWebhookConfigured {
67+
if observedWebhookConfigured && auth.Spec.Type != configv1.AuthenticationTypeOIDC {
6668
// retrieve the secret from config and validate it, don't proceed on failure
6769
kubeconfigSecret, err := listers.ConfigSecretLister().Secrets("openshift-config").Get(webhookSecretName)
6870
if err != nil {
@@ -87,6 +89,15 @@ func ObserveWebhookTokenAuthenticator(genericListers configobserver.Listers, rec
8789
resourcesynccontroller.ResourceLocation{Namespace: operatorclient.GlobalUserSpecifiedConfigNamespace, Name: webhookSecretName},
8890
)
8991
} else {
92+
if auth.Spec.Type == configv1.AuthenticationTypeOIDC {
93+
if _, err := listers.ConfigmapLister_.ConfigMaps(operatorclient.TargetNamespace).Get(AuthConfigCMName); errors.IsNotFound(err) {
94+
// auth-config does not exist in target namespace yet; do not remove webhook until it's there
95+
return existingConfig, errs
96+
} else if err != nil {
97+
return existingConfig, append(errs, err)
98+
}
99+
}
100+
90101
// don't sync anything and remove whatever we synced
91102
resourceSyncer.SyncSecret(
92103
resourcesynccontroller.ResourceLocation{Namespace: operatorclient.TargetNamespace, Name: "webhook-authenticator"},

pkg/operator/configobservation/auth/webhook_authenticator_test.go

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -74,7 +74,8 @@ func TestObserveWebhookTokenAuthenticator(t *testing.T) {
7474
expectedConfig map[string]interface{}
7575
}{
7676
{
77-
name: "empty config",
77+
name: "empty config",
78+
expectEvents: true,
7879
},
7980
{
8081
name: "referenced secret missing",

0 commit comments

Comments
 (0)