feat: add support for JWT from AWS Cognito by allowing bearer_jwt_all… - #146
Open
vmignot wants to merge 2 commits into
Open
feat: add support for JWT from AWS Cognito by allowing bearer_jwt_all…#146vmignot wants to merge 2 commits into
vmignot wants to merge 2 commits into
Conversation
vmignot
force-pushed
the
feat/add-support-for-jwt-from-aws-cognito
branch
3 times, most recently
from
June 16, 2026 12:52
a41092c to
172d7ba
Compare
…owed_auds=["*"] Signed-off-by: Victor Mignot <victor.mignot-ext@randstad.fr>
vmignot
force-pushed
the
feat/add-support-for-jwt-from-aws-cognito
branch
from
June 16, 2026 13:53
172d7ba to
ffb33a9
Compare
vmignot
marked this pull request as ready for review
June 16, 2026 14:43
Signed-off-by: Victor Mignot <victor.mignot-ext@randstad.fr>
|
Owner
|
Hello and thanks for the proposal. The current Bearer JWT validation logic is targeted towards ID tokens (although access tokens of some IDPs may work as well if they are JWTs and contain ID token claims). At least currently my thinking is that I do not want to extend scope of this plugin towards more general purpose JWT/access token processing. |
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.


Description
This PR introduces support for M2M (Machine-to-Machine) access tokens generated by AWS Cognito, which natively omit the
aud(audience) claim and use theclient_idclaim instead.https://docs.aws.amazon.com/verifiedpermissions/latest/userguide/cognito-validation.html
The Issue
When using the
client_credentialsflow with AWS Cognito, the returnedaccess_tokendoes not contain anaudclaim. Because of this, the plugin currently blocks these valid tokens:verifyIDTokenCommonstrictly expectslen(idToken.Audience) == 1and fails immediately on Cognito tokens (which have 0 audience).authBearerTokenonly checks theaudclaim againstBearerJWTAllowedAuds, causing a401 Unauthorizedeven if theclient_idis authorized.The Fix
To support these tokens without compromising existing security, this PR introduces the following changes:
verifyIDTokenCommonto allow0or1audience, rejecting only tokens with multiple audiences. This prevents aggressively blocking Cognito M2M tokens.client_id: InauthBearerToken, claims are now extracted earlier. If the audience check fails, it falls back to checking theclient_idclaim against theBearerJWTAllowedAudslist."*"wildcard inBearerJWTAllowedAudsto allow any valid token cryptographically signed by the IdP. This is particularly useful when AuthZ routing is delegated to other Kong plugins (e.g., Kong ACL plugin) based on scopes.groups_claim(e.g.,scope) is returned as a single space-separated string (standard OAuth2 behavior for scopes),setServiceDataGroupsnow splits the string by space instead of evaluating the entire string as a single group. This prevents the regex validator from improperly rejecting standard scope strings containing spaces.Testing
TestBearerJWTWildcardAudienceinmain_test.goto ensure the wildcard and relaxed audience checks work as intended.