Repository navigation
KNOX-3601: Reject CLIENTID client secrets presented as access tokens - #1532
Merged
Merged
Conversation
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.
Test Results 5 files 5 suites 1m 14s ⏱️ Results for commit cd99850. |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
Add this suggestion to a batch that can be applied as a single commit.This suggestion is invalid because no changes were made to the code.Suggestions cannot be applied while the pull request is closed.Suggestions cannot be applied while viewing a subset of changes.Only one suggestion per line can be applied in a batch.Add this suggestion to a batch that can be applied as a single commit.Applying suggestions on deleted lines is not supported.You must change the existing code in this line in order to create a valid suggestion.Outdated suggestions cannot be applied.This suggestion has been applied or marked resolved.Suggestions cannot be applied from pending reviews.Suggestions cannot be applied on multi-line comments.Suggestions cannot be applied while the pull request is queued to merge.Suggestion cannot be applied right now. Please check back later.
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_credentialsgrant. Until nowJWTFederationFilteralso accepted it directly as an access token, asAuthorization: Bearer <client_secret>or as HTTP Basic with thePasscodeusername, because client secrets and API keys share the same passcode encoding.With this change:
JWTFederationFilterrejects a CLIENTID client secret presented directly as an access token with401 Unauthorizedand the message "A client secret is not an access token; exchange it for one using the client_credentials grant".validateToken, so a secret that is going to be rejected is never verified.TokenMetadata.isClientId(); API keys keep working as Bearer / BasicPasscodetokens.client_credentialsgrant, both in the form body (client_id/client_secret) and as HTTP Basicclient_id:client_secret.WireTokennow records whether the token came from aclient_credentialsgrant (WireToken.clientSecret(...)), and the grant parsing methods returnWireTokendirectly.JWTProviderparam,knox.token.allow.client.secret.as.access.token(defaultfalse), restores the old behavior on a topology that still needs it.Rejected client secret of {0} used as an access token); the param name is deliberately not in the log, it is documented instead.knox.token.exp.server-managedis on; without it a client secret cannot be identified as such and nothing changes.config_client_credentials.mdwith 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?
JWTFederationFilterTest: a client secret is rejected as Bearer and as BasicPasscode(and is never validated), is still rejected as Bearer whengrant_type=client_credentialsis present, and is accepted in both forms whenknox.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 theclient_credentialsgrant, in the form body and as HTTP Basic.HadoopAuthFilterTest: the strict filter config mock expects the new param.mvn verifyongateway-provider-security-jwtandgateway-provider-security-hadoopauth.client_credentialsgrant atoauth/v1/token, body and HTTP Basic: 200Passcode: 401, with the WARN log lineknox.token.allow.client.secret.as.access.token=true: 200Integration Tests
Extended
test_clientid_credentials.pyand added theknoxtoken-allow-client-secrettopology (knoxtokenplusknox.token.allow.client.secret.as.access.token=true):test_supplied_client_id_authenticatesused to present the client secret as BasicPasscodetoknoxtoken, which is now rejected. It now exchanges the secret through theclient_credentialsgrant, checks that the access token'ssubis 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 BasicPasscodeget 401 with the error message onknoxtoken.test_client_secret_accepted_as_access_token_when_allowed: both forms are accepted onknoxtoken-allow-client-secret.test_api_key_accepted_as_access_token: an API key (minted attokenlimitbytypefor a freshdoAsuser) is still accepted in both forms.