[ 
https://issues.apache.org/jira/browse/KNOX-3582?focusedWorklogId=1055417&page=com.atlassian.jira.plugin.system.issuetabpanels:worklog-tabpanel#worklog-1055417
 ]

ASF GitHub Bot logged work on KNOX-3582:
----------------------------------------

                Author: ASF GitHub Bot
            Created on: 17/Nov/26 19:07
            Start Date: 17/Nov/26 19:07
    Worklog Time Spent: 10m 
      Work Description: lmccay merged PR #1521:
URL: https://github.com/apache/knox/pull/1521




Issue Time Tracking
-------------------

    Worklog Id:     (was: 1055417)
    Time Spent: 0.5h  (was: 20m)

> Passcode token based resources: honor knox.token.exp.server-managed instead 
> of always enabling token state
> ----------------------------------------------------------------------------------------------------------
>
>                 Key: KNOX-3582
>                 URL: https://issues.apache.org/jira/browse/KNOX-3582
>             Project: Apache Knox
>          Issue Type: Bug
>          Components: Server
>    Affects Versions: 3.0.0
>            Reporter: Sandor Molnar
>            Assignee: Sandor Molnar
>            Priority: Major
>             Fix For: 3.1.0
>
>          Time Spent: 0.5h
>  Remaining Estimate: 0h
>
> h3. Problem
> {{PasscodeTokenResourceBase#setupTokenStateService}} always wires in the 
> token state service:
> {code:java}
> wrapperContext.setInitParameter(TokenStateService.CONFIG_SERVER_MANAGED, 
> "true");
> ...
> tokenStateService = services.getService(ServiceType.TOKEN_STATE_SERVICE);
> {code}
> Its subclasses all use this setup: {{APIKeyResource}}, 
> {{ClientCredentialsResource}}, {{OAuthResource}} and the KnoxIDF 
> {{TokenResource}}.
> The {{setInitParameter}} call only sets a default. 
> {{ServletContextWrapper#getInitParameter}} checks the extension-prefixed 
> params first ({{knoxidf.}}, {{apikey.}}, {{clientid.}}), then the topology's 
> params, then the defaults. So if a topology sets 
> {{knox.token.exp.server-managed=false}}, 
> {{TokenResource#isServerManagedTokenStateEnabled}} returns {{false}}.
> However, {{setupTokenStateService}} assigns {{tokenStateService}} without 
> looking at that setting, and nothing clears it later. Saving the token and 
> setting the {{managed}} claim only check {{tokenStateService != null}}. So 
> every token these resources issue is saved and marked managed, whatever the 
> topology says. There is no way to turn this off.
> It is also inconsistent: with an explicit {{false}}, the parent 
> {{TokenResource#init}} skips building the token MAC, but 
> {{tokenStateService}} is still set. {{persistTokenDetails}} then fails with 
> an NPE on the null {{tokenMAC}}.
> h3. Impact
> For grants whose tokens are never revoked or looked up, saving them is pure 
> overhead. One example is RFC 8693 token exchange on the KnoxIDF token 
> endpoint, where data services get a short-lived token for a workload. With 
> {{JDBCTokenStateService}}, each issued token means:
> * synchronous DB writes on the request path ({{addToken}} plus 
> {{addMetadata}})
> * one more row in the token tables until it is cleaned up
> h3. Proposal
> Make {{PasscodeTokenResourceBase#setupTokenStateService}} honor the setting:
> * Keep {{true}} as the default by calling {{setInitParameter}} first. Then 
> read the effective value with {{isServerManagedTokenStateEnabled}} (made 
> {{protected}}). A blank value falls back to the gateway-level 
> {{gateway.knox.token.exp.server-managed}}, as it does for KNOXTOKEN.
> * *Not declared, or {{true}}:* the same as today.
> * *Declared {{false}}* (plain or extension-prefixed, for example 
> {{knoxidf.knox.token.exp.server-managed}}): don't assign 
> {{tokenStateService}}, and log that token state is disabled for the topology. 
> Tokens are not saved and get {{managed.token=false}}. They are checked by 
> signature and expiry only, so they can't be revoked; the operator opts into 
> that trade-off.
> * Still generate the token hash key alias in both cases, because the KnoxIDF 
> {{TokenResource}} always builds a {{TokenMAC}} from it.
> There is no special handling for features that need stored state. With 
> {{false}}, these won't work:
> * the KnoxIDF {{authorization_code}} and {{refresh_token}} grants, and the 
> authorize and registration endpoints;
> * API key and client credentials passcodes.
> The setting is meant for token-exchange-only topologies, combined with 
> {{jwt.allowed.grant.types}} (KNOX-3578) so other grants are rejected with 
> {{400 unsupported_grant_type}}. The docs say this.
> h3. Testing
> * Unit tests for {{PasscodeTokenResourceBase}} and its subclasses 
> ({{OAuthResource}}, {{APIKeyResource}}, {{ClientCredentialsResource}}):
> ** Not declared (even with the gateway default {{false}}), or {{true}}: token 
> state is used.
> ** {{false}}: no token state, and the hash key alias is still generated.
> ** Blank: falls back to the gateway default.
> ** An extension-prefixed value wins over a plain one, and works on its own.
> * Existing knoxtoken and KnoxIDF tests pass unchanged.
> h3. Docs
> * {{config_knox_token.md}}: CLIENTID, APIKEY and KnoxIDF default the setting 
> to {{true}}, and an explicit value is honored.
> * {{knoxidf/configuration.md}}: the {{knoxidf.knox.token.exp.server-managed}} 
> parameter and an "Unmanaged tokens" section.



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

Reply via email to