Skip to content

Commit

Permalink
fixup: return err if failing to compile KeySelector CEL expression
Browse files Browse the repository at this point in the history
Signed-off-by: KevFan <[email protected]>
  • Loading branch information
KevFan committed Feb 25, 2025
1 parent 01a81eb commit 6f999e6
Show file tree
Hide file tree
Showing 2 changed files with 8 additions and 4 deletions.
6 changes: 5 additions & 1 deletion controllers/auth_config_controller.go
Original file line number Diff line number Diff line change
Expand Up @@ -262,7 +262,11 @@ func (r *AuthConfigReconciler) translateAuthConfig(ctx context.Context, authConf
return nil, err
}

translatedIdentity.APIKey = identity_evaluators.NewApiKeyIdentity(identityCfgName, selector, namespace, string(identity.ApiKey.KeySelector), authCred, r.Client, ctxWithLogger)
if apiKeyIdentity, err := identity_evaluators.NewApiKeyIdentity(identityCfgName, selector, namespace, string(identity.ApiKey.KeySelector), authCred, r.Client, ctxWithLogger); err != nil {
return nil, err
} else {
translatedIdentity.APIKey = apiKeyIdentity
}

// MTLS
case api.X509ClientCertificateAuthentication:
Expand Down
6 changes: 3 additions & 3 deletions pkg/evaluators/identity/api_key.go
Original file line number Diff line number Diff line change
Expand Up @@ -41,7 +41,7 @@ type APIKey struct {
k8sClient k8s_client.Reader
}

func NewApiKeyIdentity(name string, labelSelectors k8s_labels.Selector, namespace string, keySelectorExpression string, authCred auth.AuthCredentials, k8sClient k8s_client.Reader, ctx context.Context) *APIKey {
func NewApiKeyIdentity(name string, labelSelectors k8s_labels.Selector, namespace string, keySelectorExpression string, authCred auth.AuthCredentials, k8sClient k8s_client.Reader, ctx context.Context) (*APIKey, error) {
if keySelectorExpression == "" {
keySelectorExpression = defaultKeySelectorExpression
}
Expand All @@ -51,7 +51,7 @@ func NewApiKeyIdentity(name string, labelSelectors k8s_labels.Selector, namespac
expr, err := cel.NewKeySelectorExpression(keySelectorExpression)
if err != nil {
logger.Error(err, "failed to create key selector expression")
return nil
return nil, err
}

apiKey := &APIKey{
Expand All @@ -66,7 +66,7 @@ func NewApiKeyIdentity(name string, labelSelectors k8s_labels.Selector, namespac
if err := apiKey.loadSecrets(context.TODO()); err != nil {
logger.Error(err, credentialsFetchingErrorMsg)
}
return apiKey
return apiKey, nil
}

// loadSecrets will load the matching k8s secrets from the cluster to the cache of trusted API keys
Expand Down

0 comments on commit 6f999e6

Please sign in to comment.