-
Notifications
You must be signed in to change notification settings - Fork 170
OCPBUGS-61432: fix(oidc): fix secret lookup, validation, and condition cleanup #1216
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
base: main
Are you sure you want to change the base?
Changes from all commits
File filter
Filter by extension
Conversations
Jump to
Diff view
Diff view
There are no files selected for viewing
| Original file line number | Diff line number | Diff line change | ||||
|---|---|---|---|---|---|---|
|
|
@@ -58,6 +58,7 @@ type oidcSetupController struct { | |||||
| authnLister configv1listers.AuthenticationLister | ||||||
| consoleOperatorLister operatorv1listers.ConsoleLister | ||||||
| configConfigMapLister corev1listers.ConfigMapLister | ||||||
| configSecretsLister corev1listers.SecretLister | ||||||
| targetNSSecretsLister corev1listers.SecretLister | ||||||
| targetNSConfigMapLister corev1listers.ConfigMapLister | ||||||
| targetNSDeploymentsLister appsv1listers.DeploymentLister | ||||||
|
|
@@ -74,6 +75,7 @@ func NewOIDCSetupController( | |||||
| authenticationClient configv1client.AuthenticationInterface, | ||||||
| consoleOperatorInformer operatorv1informers.ConsoleInformer, | ||||||
| configConfigMapInformer corev1informers.ConfigMapInformer, | ||||||
| configSecretInformer corev1informers.SecretInformer, | ||||||
| targetNSsecretsInformer corev1informers.SecretInformer, | ||||||
| targetNSConfigMapInformer corev1informers.ConfigMapInformer, | ||||||
| targetNSDeploymentsInformer appsv1informers.DeploymentInformer, | ||||||
|
|
@@ -87,6 +89,7 @@ func NewOIDCSetupController( | |||||
| authnLister: authnInformer.Lister(), | ||||||
| consoleOperatorLister: consoleOperatorInformer.Lister(), | ||||||
| configConfigMapLister: configConfigMapInformer.Lister(), | ||||||
| configSecretsLister: configSecretInformer.Lister(), | ||||||
| targetNSSecretsLister: targetNSsecretsInformer.Lister(), | ||||||
| targetNSDeploymentsLister: targetNSDeploymentsInformer.Lister(), | ||||||
| targetNSConfigMapLister: targetNSConfigMapInformer.Lister(), | ||||||
|
|
@@ -102,6 +105,7 @@ func NewOIDCSetupController( | |||||
| authnInformer.Informer(), | ||||||
| configConfigMapInformer.Informer(), | ||||||
| consoleOperatorInformer.Informer(), | ||||||
| configSecretInformer.Informer(), | ||||||
| targetNSsecretsInformer.Informer(), | ||||||
| targetNSDeploymentsInformer.Informer(), | ||||||
| targetNSConfigMapInformer.Informer(), | ||||||
|
|
@@ -200,7 +204,7 @@ func (c *oidcSetupController) syncAuthTypeOIDC(ctx context.Context, authnConfig | |||||
| return nil | ||||||
| } | ||||||
|
|
||||||
| clientSecret, err := c.targetNSSecretsLister.Secrets(api.TargetNamespace).Get("console-oauth-config") | ||||||
| clientSecret, err := c.configSecretsLister.Secrets(api.OpenShiftConfigNamespace).Get(clientConfig.ClientSecret.Name) | ||||||
| if err != nil { | ||||||
| c.authStatusHandler.Degraded("OIDCClientSecretGet", err.Error()) | ||||||
| return err | ||||||
|
|
@@ -252,7 +256,14 @@ func (c *oidcSetupController) checkClientConfigStatus(authnConfig *configv1.Auth | |||||
| return false, "deployment unavailable or outdated", nil | ||||||
| } | ||||||
|
|
||||||
| if clientSecret.GetResourceVersion() != depl.ObjectMeta.Annotations["console.openshift.io/oauth-secret-version"] { | ||||||
| // Get the TARGET secret (synced copy in openshift-console namespace) | ||||||
| // to compare its resource version with the deployment annotation | ||||||
| targetClientSecret, err := c.targetNSSecretsLister.Secrets(api.OpenShiftConsoleNamespace).Get("console-oauth-config") | ||||||
| if err != nil { | ||||||
| return false, "", err | ||||||
| } | ||||||
|
|
||||||
| if targetClientSecret.GetResourceVersion() != depl.ObjectMeta.Annotations["console.openshift.io/oauth-secret-version"] { | ||||||
|
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. 📐 Maintainability & Code Quality | 🟡 Minor | ⚡ Quick win Clear the QF1008 warning before merge. Static analysis reports QF1008 for Proposed fix- if targetClientSecret.GetResourceVersion() != depl.ObjectMeta.Annotations["console.openshift.io/oauth-secret-version"] {
+ if targetClientSecret.GetResourceVersion() != depl.Annotations["console.openshift.io/oauth-secret-version"] {📝 Committable suggestion
Suggested change
🧰 Tools🪛 golangci-lint (2.12.2)[error] 266-266: QF1008: could remove embedded field "ObjectMeta" from selector (staticcheck) 🤖 Prompt for AI AgentsSource: Linters/SAST tools |
||||||
| return false, "client secret version not up to date in current deployment", nil | ||||||
| } | ||||||
|
|
||||||
|
|
||||||
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
📐 Maintainability & Code Quality | 🟠 Major | ⚡ Quick win
Wrap the new Secret lookup errors with context.
At Line 207, the source Secret lister error is returned raw. At Line 261, the target Secret lister error is also returned raw. Wrap both errors with
%wand include the Secret name and namespace.Proposed fix
if err != nil { + err = fmt.Errorf("failed to get OIDC client secret %q from namespace %q: %w", clientConfig.ClientSecret.Name, api.OpenShiftConfigNamespace, err) c.authStatusHandler.Degraded("OIDCClientSecretGet", err.Error()) return err } targetClientSecret, err := c.targetNSSecretsLister.Secrets(api.OpenShiftConsoleNamespace).Get("console-oauth-config") if err != nil { - return false, "", err + return false, "", fmt.Errorf("failed to get synced OIDC client secret %q from namespace %q: %w", "console-oauth-config", api.OpenShiftConsoleNamespace, err) }As per coding guidelines: “When returning errors in Go, wrap them with
%wand include meaningful context instead of returning the raw error or using%v.”As per path instructions: “Report transient or permanent failures through the appropriate status.Handle* condition helpers, using meaningful context in errors.”
Also applies to: 261-264
🤖 Prompt for AI Agents
Sources: Coding guidelines, Path instructions