Sandor Molnar created KNOX-3621:
-----------------------------------

             Summary: KnoxIDF: LDAP user params lookup failure breaks token 
issuance; make the mint-time lookup non-fatal and configurable
                 Key: KNOX-3621
                 URL: https://issues.apache.org/jira/browse/KNOX-3621
             Project: Apache Knox
          Issue Type: Improvement
          Components: KnoxIDF
            Reporter: Sandor Molnar
            Assignee: Sandor Molnar
             Fix For: 3.1.0


h3. Problem

When the LDAP user params provider ({{user.params.provider.ldap.*}}) is 
configured on a KnoxIDF topology, every {{authorization_code}} and 
{{refresh_token}} grant does an LDAP lookup to put optional user claims (name, 
email, roles, ...) into the access token. If that lookup fails for any reason 
(LDAP unreachable, timeout, bind failure, user entry not found or not 
readable), {{LdapUserParamsProvider#getParamsFor}} throws a 
{{RuntimeException}}. Nothing catches it, and the token endpoint answers with 
an HTTP 500:

{noformat}
"event": "Error while exchanging the code for authorization",
"error": "500: { ... 'url': 
'https://<knox-host>/.../knoxidf-auth-token/.../token', 'status': '500'}"
{noformat}

This is worse than a failed request:
* *The credential is burned.* {{TokenResource#handleAuthorizationCodeFlow}} and 
{{TokenResource#handleRefreshToken}} consume the auth code / refresh token 
(single-use guard) *before* the LDAP lookup. A temporary LDAP problem therefore 
invalidates the user's auth code or refresh token for good, and the user has to 
log in again.
* *The audit log does not say why.* The grant is audited as {{reason=unknown}}.
* *The claims are optional.* The LDAP claims only go into the access token as 
custom claims. The local id_token does not carry them, and {{/userinfo}} 
fetches them again on its own. Failing to add them should not stop token 
issuance.

There is also a design issue: with the provider configured, LDAP is queried 
twice per login, once when the token is minted and again on {{/userinfo}}. Many 
deployments only need the profile claims from {{/userinfo}} and should not need 
LDAP on the token path at all. Today the only way out is to remove the LDAP 
provider config from the token topology.

h3. Proposed changes

# *Make the mint-time lookup non-fatal.* In {{TokenResource}} (both 
{{authorization_code}} and {{refresh_token}} grants), catch failures from 
{{UserParamsProvider#getParamsFor}}. Log a WARN (user and cause) and issue the 
token without the optional claims ({{scope}} is still set). Add the failure to 
the grant's audit entry ({{user_params=unavailable}}). The provider itself 
keeps throwing, so each caller decides what a failure means.
# *Add a KnoxIDF service-level switch for the mint-time lookup:* 
{{knoxidf.token.user.params.enabled}} (default: {{true}}, for backward 
compatibility). When set to {{false}}, {{TokenResource}} never calls the user 
params provider and the access token carries no user params claims. 
{{/userinfo}} is not affected and keeps using the provider whenever it is 
configured.
# *Better {{/userinfo}} error handling.* {{/userinfo}} exists to return these 
claims, so returning an empty profile would mislead clients. A failed lookup 
now returns an OIDC error, HTTP 503 {{temporarily_unavailable}}, with a WARN 
log instead of a raw 500, and the audit entry records 
{{reason=user_params_unavailable}}. Clients can retry; no credential is 
consumed.
# *Detect misconfiguration early.* Check static provider config (missing or 
unresolvable system password alias, search filters without {{\{0\}}}) once at 
service initialization and log an ERROR. Today these errors only show up on 
every request, and with (1) in place a broken config would otherwise produce 
tokens without claims, with only WARN lines as a sign.

h3. Notes

* With (1), a downstream service that authorizes on the {{roles}} claim in the 
access token will see a token without roles until it expires. This fails safe 
(fewer privileges, not more), but it should be documented.
* Tests: unit tests for both grants with a failing provider (token issued, 
claims missing, WARN and audit detail present), for the new switch (provider 
not called when disabled, default enabled), and for the {{/userinfo}} 503 path.




--
This message was sent by Atlassian Jira
(v10.3.26#10030026)

Reply via email to