Skip to content

Commit a1f477f

Browse files
Fix IAP OAuth credentials not being fetched when IAP is disabled
The behavior in validateIAP() of treating .spec.iap.enabled=false as equivalent to .spec.iap=nil and abort all validation is incongruent with that in pkg/backends/features/iap.go, where a full sync of the IAP configuration is triggered as long as .spec.iap!=nil. The latter behavior is the correct one, as it allows disabling IAP on an ingress where it was previously enabled by setting .spec.spec.enabled=false in the BackendConfig. However, because pkg/backendconfig/validation.go skips the entire validation and with that the lookup of the OAuth credentials referenced in .spec.iap.oauthclientCredentials.secretName, the desired BackendConfig's OAuth Client ID will be uninitialized and interpreted as empty (""). And in the case that IAP was previously configured with a non-default Client ID, this will trigger a switchingToDefaultError.
1 parent 4fba6f7 commit a1f477f

File tree

1 file changed

+3
-3
lines changed

1 file changed

+3
-3
lines changed

pkg/backendconfig/validation.go

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -66,11 +66,11 @@ func Validate(kubeClient kubernetes.Interface, beConfig *backendconfigv1.Backend
6666
// between which error is returned.
6767
func validateIAP(kubeClient kubernetes.Interface, beConfig *backendconfigv1.BackendConfig, servicePort *utils.ServicePort) error {
6868
// If IAP settings are not found or IAP is not enabled then don't bother continuing.
69-
if beConfig.Spec.Iap == nil || beConfig.Spec.Iap.Enabled == false {
69+
if beConfig.Spec.Iap == nil {
7070
return nil
7171
}
7272

73-
if servicePort != nil && servicePort.L7XLBRegionalEnabled {
73+
if beConfig.Spec.Iap.Enabled && servicePort != nil && servicePort.L7XLBRegionalEnabled {
7474
return fmt.Errorf("IAP configuration is not supported in TPC Environment")
7575
}
7676
// If necessary, get the OAuth credentials stored in the K8s secret.
@@ -92,7 +92,7 @@ func validateIAP(kubeClient kubernetes.Interface, beConfig *backendconfigv1.Back
9292
beConfig.Spec.Iap.OAuthClientCredentials.ClientSecret = string(clientSecret)
9393
}
9494

95-
if beConfig.Spec.Cdn != nil && beConfig.Spec.Cdn.Enabled {
95+
if beConfig.Spec.Iap.Enabled && beConfig.Spec.Cdn != nil && beConfig.Spec.Cdn.Enabled {
9696
return fmt.Errorf("iap and cdn cannot be enabled at the same time")
9797
}
9898
return nil

0 commit comments

Comments
 (0)