Skip to content

KNOX-3601: Reject CLIENTID client secrets presented as access tokens - #1532

Merged
smolnar82 merged 1 commit into
apache:masterfrom
smolnar82:KNOX-3601
Nov 20, 2026
Merged

smolnar82 merged 1 commit into
apache:masterfrom
smolnar82:KNOX-3601

Conversation

@smolnar82

@smolnar82 smolnar82 commented Nov 20, 2026 •

Copy link
Copy Markdown
Contributor

KNOX-3601 - Reject CLIENTID client secrets presented as access tokens

What changes were proposed in this pull request?

A client secret issued by the CLIENTID service is a long-lived grant credential: it should be exchanged for a short-lived access token through the OAuth 2.0 client_credentials grant. Until now JWTFederationFilter also accepted it directly as an access token, as Authorization: Bearer <client_secret> or as HTTP Basic with the Passcode username, because client secrets and API keys share the same passcode encoding.

With this change:

  • JWTFederationFilter rejects a CLIENTID client secret presented directly as an access token with 401 Unauthorized and the message "A client secret is not an access token; exchange it for one using the client_credentials grant".
  • The check runs right after the passcode is decoded and before validateToken, so a secret that is going to be rejected is never verified.
  • Client secrets are told apart from API keys by TokenMetadata.isClientId(); API keys keep working as Bearer / Basic Passcode tokens.
  • Client secrets are still accepted in the client_credentials grant, both in the form body (client_id / client_secret) and as HTTP Basic client_id:client_secret. WireToken now records whether the token came from a client_credentials grant (WireToken.clientSecret(...)), and the grant parsing methods return WireToken directly.
  • A new JWTProvider param, knox.token.allow.client.secret.as.access.token (default false), restores the old behavior on a topology that still needs it.
  • The rejection is logged at WARN with the token id display text only (Rejected client secret of {0} used as an access token); the param name is deliberately not in the log, it is documented instead.
  • The check needs the token state service, so it only applies when knox.token.exp.server-managed is on; without it a client secret cannot be identified as such and nothing changes.
  • Docs: new "Using the client secret" section in config_client_credentials.md with the grant examples, the 401 behavior and the new param.

Follow-up: KNOX-3602 (read client_credentials grant parameters from the request body only).

How was this patch tested?

  • Unit tests:
    • JWTFederationFilterTest: a client secret is rejected as Bearer and as Basic Passcode (and is never validated), is still rejected as Bearer when grant_type=client_credentials is present, and is accepted in both forms when knox.token.allow.client.secret.as.access.token=true. The existing passcode tests cover API keys and non-server-managed topologies.
    • OAuthFlowsFederationFilterTest: a client secret is accepted in the client_credentials grant, in the form body and as HTTP Basic.
    • HadoopAuthFilterTest: the strict filter config mock expects the new param.
  • mvn verify on gateway-provider-security-jwt and gateway-provider-security-hadoopauth.
  • Manual tests against a local gateway with CLIENTID and APIKEY credentials:
    • client_credentials grant at oauth/v1/token, body and HTTP Basic: 200
    • client secret as Bearer and as Basic Passcode: 401, with the WARN log line
    • API key as Bearer: 200
    • client secret as Bearer on a topology with knox.token.allow.client.secret.as.access.token=true: 200

Integration Tests

Extended test_clientid_credentials.py and added the knoxtoken-allow-client-secret topology (knoxtoken plus knox.token.allow.client.secret.as.access.token=true):

  • test_supplied_client_id_authenticates used to present the client secret as Basic Passcode to knoxtoken, which is now rejected. It now exchanges the secret through the client_credentials grant, checks that the access token's sub is the custom client id, and authenticates with that access token.
  • test_client_secret_exchanged_through_client_credentials_grant: the grant accepts the secret in the body and as HTTP Basic.
  • test_client_secret_rejected_as_access_token: Bearer and Basic Passcode get 401 with the error message on knoxtoken.
  • test_client_secret_accepted_as_access_token_when_allowed: both forms are accepted on knoxtoken-allow-client-secret.
  • test_api_key_accepted_as_access_token: an API key (minted at tokenlimitbytype for a fresh doAs user) is still accepted in both forms.
tests-1  | Waiting for knox...
tests-1  | ============================= test session starts ==============================
tests-1  | platform linux -- Python 3.10.20, pytest-9.0.3, pluggy-1.7.0
tests-1  | rootdir: /tests
tests-1  | plugins: platformdirs-4.12.4
tests-1  | collected 166 items
tests-1  | 
tests-1  | test_clientid_credentials.py ...........                                 [  6%]
tests-1  | test_delegation.py ............                                          [ 13%]
tests-1  | test_gateway_identity_cert.py ......                                     [ 17%]
tests-1  | test_health.py .....                                                     [ 20%]
tests-1  | test_k8s_delegation.py ........                                          [ 25%]
tests-1  | test_k8s_jwks_ca.py ...........                                          [ 31%]
tests-1  | test_k8s_serviceaccount_validation.py ......                             [ 35%]
tests-1  | test_knox_admin_path_traversal.py ...                                    [ 37%]
tests-1  | test_knox_auth_service_and_ldap.py ...                                   [ 39%]
tests-1  | test_knox_configs.py .                                                   [ 39%]
tests-1  | test_knox_ldap_backend_password_alias_retry.py ..                        [ 40%]
tests-1  | test_knox_ldap_cache.py ...                                              [ 42%]
tests-1  | test_knox_ldap_injection.py .......                                      [ 46%]
tests-1  | test_knox_ldap_proxy_search.py ...............                           [ 56%]
tests-1  | test_knoxauth_preauth_and_paths.py ......                                [ 59%]
tests-1  | test_knoxauth_token_forwarding.py ...........                            [ 66%]
tests-1  | test_knoxidf.py .......                                                  [ 70%]
tests-1  | test_knoxsso_redirect.py .                                               [ 71%]
tests-1  | test_knoxtoken_jwt.py ....................                               [ 83%]
tests-1  | test_remote_auth.py ...                                                  [ 84%]
tests-1  | test_remoteauth_extauthz_additional_path.py ....                         [ 87%]
tests-1  | test_token_exchange.py .................                                 [ 97%]
tests-1  | test_token_limit_by_type.py ....                                         [100%]
tests-1  | 
tests-1  | =============================== warnings summary ===============================
...
tests-1  | -- Docs: https://docs.pytest.org/en/stable/how-to/capture-warnings.html
tests-1  | ----------------- generated xml file: /tests/test-results.xml ------------------
tests-1  | ================= 166 passed, 144 warnings in 60.42s (0:01:00) =================
tests-1 exited with code 0

A client secret is accepted only in a client_credentials grant. Presented
directly as a Bearer token or as Basic Passcode, it is rejected with 401
before validation. API keys are not affected. The new JWTProvider param
knox.token.allow.client.secret.as.access.token (default false) restores
the old behavior.
@github-actions

Copy link
Copy Markdown

Test Results

  5 files    5 suites   1m 14s ⏱️
231 tests 230 ✅ 1 💤 0 ❌
283 runs  282 ✅ 1 💤 0 ❌

Results for commit cd99850.

@lmccay lmccay left a comment

Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

+1

@smolnar82
smolnar82 merged commit eaca05a into apache:master Nov 20, 2026
3 of 4 checks passed
@smolnar82
smolnar82 deleted the KNOX-3601 branch November 20, 2026 20:42
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Projects

None yet

Development

Successfully merging this pull request may close these issues.

2 participants