kubesphere/kubesphere · error
invalid mapping method found %s
Error message
invalid mapping method found %s
What it means
authByIdentityProvider maps an identity from an identity provider to a KubeSphere user according to the IdentityProvider's MappingMethod (e.g. 'auto', 'lookup'). If the configured MappingMethod string is none of the supported values, the function falls through all mapping branches and returns this error. It indicates a misconfigured or unsupported mappingMethod in the IdentityProvider spec.
Source
Thrown at pkg/models/auth/authenticator.go:105
}
mappedUser.Annotations[fmt.Sprintf("%s.%s", iamv1beta1.IdentityProviderAnnotation, providerConfig.Name)] = identity.GetUserID()
mappedUser.Status.State = iamv1beta1.UserActive
if identity.GetEmail() != "" {
mappedUser.Spec.Email = identity.GetEmail()
}
return nil
})
if err != nil {
return nil, fmt.Errorf("failed to create or update user %s, error: %v", mappedUser.Name, err)
}
klog.V(4).Infof("user %s has been updated successfully, operation: %s", mappedUser.Name, op)
return &authuser.DefaultInfo{Name: mappedUser.GetName()}, nil
}
return nil, fmt.Errorf("invalid mapping method found %s", providerConfig.MappingMethod)
}
if mappedUser.Status.State == iamv1beta1.UserDisabled {
return nil, AccountIsNotActiveError
}
return &authuser.DefaultInfo{Name: mappedUser.GetName()}, nil
}
View on GitHub (pinned to 04a29b5c60)
Solutions
- Check kubectl get identityprovider <name> -o yaml and correct spec.mappingMethod to 'auto' or 'lookup'
- Re-apply the IdentityProvider with a validated sample manifest
- If a custom method is needed, extend authByIdentityProvider in pkg/models/auth/authenticator.go to support it
Example fix
// before mappingMethod: Auto // after mappingMethod: auto
Defensive patterns
Strategy: validation
Validate before calling
const validMethods = map[string]bool{"auto": true, "lookup": true}
if !validMethods[idp.Spec.MappingMethod] {
return fmt.Errorf("identity provider %s has unsupported mappingMethod %q", idp.Name, idp.Spec.MappingMethod)
} Try / catch
user, err := authenticate(ctx, provider, req)
if err != nil {
if strings.Contains(err.Error(), "invalid mapping method") {
// fix IdentityProvider CR mappingMethod before retrying login
}
return err
} Prevention
- Only set mappingMethod to 'auto' or 'lookup' in IdentityProvider CRs
- Apply CRs through validation-enabled tooling (kubectl apply, not raw etcd writes)
- Add a schema enum for mappingMethod in your CRD/manifests
When it happens
Trigger: A user authenticates via an OAuth/generic identity provider (oauthAuthenticator.Authenticate or passwordAuthenticator.authByProvider) and the referenced IdentityProvider resource has a mappingMethod value outside {auto, lookup} (typo like 'Auto', 'manual', or empty after CRD validation bypass).
Common situations: Hand-edited IdentityProvider YAML with a typo in mappingMethod; upgrading KubeSphere after a custom mapping method was removed; applying CRs via tooling that skips OpenAPI validation.
Related errors
- the Identity provider was not found
- the Identity provider was Disabled
- failed to get identity provider configuration for %s, error:
- generic identity provider %s not found
- failed to get identity provider configuration: %s
AI-assisted analysis of kubesphere/kubesphere@04a29b5c60 (2026-09-03).
Data as JSON: /api/errors/4d2f045ed150ab5c.
Report an issue: GitHub.