fix(apis): use rule name in OIDC resource identifier to fix JWT authorizer attachment#153
Open
tsushanth wants to merge 1 commit into
Open
Conversation
…dentifier
_oidc_to_resource was using b.name (the composite "{rule_name}-{api_name}"
key used internally by _create_resource for deduplication) as the
ResourceIdentifier.name. The security scheme is declared under this
composite name, but route security definitions reference the original
options.name ("cognito-auth-rule"), so API Gateway receives an OpenAPI
spec with a security reference that doesn't match any scheme in
securitySchemes and silently ignores the JWT authorizer.
b.rule_name (= options.name) is already stored on OidcSecurityDefinition
for this purpose; use it in the ResourceIdentifier so the declared scheme
name matches what routes reference.
Fixes nitrictech/nitric#919
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.
Bug
When using
oidc_rulewithApiOptions(security=[...]), the JWT authorizer is created in API Gateway but never attached to any route. Routes show "Authorization: NONE" despite the authorizer being visible in the Authorizers tab.Root cause
_oidc_to_resourceusesb.nameas theResourceIdentifier.name.b.nameis the composite keyf"{options.name}-{api_name}"(e.g."cognito-auth-rule-auth") — used internally by_create_resourcefor deduplication when the same OIDC rule is applied to multiple APIs.However, route security definitions reference the original
options.name(e.g."cognito-auth-rule"). The generated OpenAPI spec has a mismatch:API Gateway receives an unresolvable security reference and silently ignores the authorizer.
Fix
OidcSecurityDefinitionalready storesself.rule_name = options.namefor exactly this purpose. Change_oidc_to_resourceto useb.rule_nameinstead ofb.name:The composite key in
b.nameis preserved for internal deduplication in_create_resource; only the identifier sent to the runtime changes to match what routes reference.Fixes nitrictech/nitric#919