-
Notifications
You must be signed in to change notification settings - Fork 3.9k
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
fix(apigatewayv2): defaultAuthorizer cannot be applied to HttpRoute #27576
Conversation
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
The pull request linter has failed. See the aws-cdk-automation comment below for failure reasons. If you believe this pull request should receive an exemption, please comment and provide a justification.
A comment requesting an exemption should contain the text Exemption Request
. Additionally, if clarification is needed add Clarification Request
to a comment.
✅ Updated pull request passes all PRLinter validations. Dismissing previous PRLinter review.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Looks good overall 👍
Adding the properties to the IHttpApi
interface results in a clearer implementation and it should not cause problems in my opinion.
if (props.authorizer) { | ||
this.authBindResult = props.authorizer.bind({ | ||
route: this, | ||
scope: this.httpApi instanceof Construct ? this.httpApi : this, // scope under the API if it's not imported | ||
}); | ||
} else if (this.httpApi instanceof HttpApi && this.httpApi.defaultAuthorizer) { // because IHttpApi as it is does not have a defaultAuthorizer | ||
this.authBindResult = this.httpApi.defaultAuthorizer.bind({ | ||
route: this, | ||
scope: this.httpApi, // this.httpApi is also a Construct because it is an HttpApi | ||
}); | ||
} |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
if (props.authorizer) { | |
this.authBindResult = props.authorizer.bind({ | |
route: this, | |
scope: this.httpApi instanceof Construct ? this.httpApi : this, // scope under the API if it's not imported | |
}); | |
} else if (this.httpApi instanceof HttpApi && this.httpApi.defaultAuthorizer) { // because IHttpApi as it is does not have a defaultAuthorizer | |
this.authBindResult = this.httpApi.defaultAuthorizer.bind({ | |
route: this, | |
scope: this.httpApi, // this.httpApi is also a Construct because it is an HttpApi | |
}); | |
} | |
const authorizer = props.authorizer ?? this.httpApi.defaultAuthorizer; | |
this.authBindResult = authorizer?.bind({ | |
route: this, | |
scope: this.httpApi instanceof Construct ? this.httpApi : this, // scope under the API if it's not imported | |
}); |
It should be fine to add defaultAuthorizer
and defaultAuthorizationScopes
to the IHttpApi
interface (unless I'm missing something).
if (this.authBindResult) { | ||
if (props.authorizationScopes) { | ||
authorizationScopes = Array.from(new Set([ | ||
...authorizationScopes ?? [], | ||
...props.authorizationScopes, | ||
])); | ||
} else if (this.httpApi instanceof HttpApi && this.httpApi.defaultAuthorizationScopes) {// because IHttpApi as it is does not have a defaultAuthorizationScopes | ||
authorizationScopes = Array.from(new Set([ | ||
...authorizationScopes ?? [], | ||
...this.httpApi.defaultAuthorizationScopes, | ||
])); | ||
} |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
if (this.authBindResult) { | |
if (props.authorizationScopes) { | |
authorizationScopes = Array.from(new Set([ | |
...authorizationScopes ?? [], | |
...props.authorizationScopes, | |
])); | |
} else if (this.httpApi instanceof HttpApi && this.httpApi.defaultAuthorizationScopes) {// because IHttpApi as it is does not have a defaultAuthorizationScopes | |
authorizationScopes = Array.from(new Set([ | |
...authorizationScopes ?? [], | |
...this.httpApi.defaultAuthorizationScopes, | |
])); | |
} | |
if (this.authBindResult && (props.authorizationScopes || this.httpApi.defaultAuthorizationScopes)) { | |
authorizationScopes = Array.from(new Set([ | |
...authorizationScopes ?? [], | |
...props.authorizationScopes ?? this.httpApi.defaultAuthorizationScopes ?? [], | |
])); | |
} |
const httpApi = new HttpApi(stack, 'MyHttpApi'); | ||
const httpApiWithDefaultAuthorizer = new HttpApi(stack, 'MyHttpApiWithDefaultAuthorizer', { | ||
defaultAuthorizer, | ||
}); |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Can you also add defaultAuthorizationScopes
to the httpApiWithDefaultAuthorizer
API?
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
I changed integ.user-pool instead of integ.lambda because defaultAuthorizationScopes (Authorization Scopes) are only valid for COGNITO_USER_POOLS and JWT authorization types
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
👍 Thanks for the clarification.
Thanks for your review. I changed, so please review again! |
change an integ test
41ca1bc
to
2a76067
Compare
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
The pull request linter has failed. See the aws-cdk-automation comment below for failure reasons. If you believe this pull request should receive an exemption, please comment and provide a justification.
A comment requesting an exemption should contain the text Exemption Request
. Additionally, if clarification is needed add Clarification Request
to a comment.
✅ Updated pull request passes all PRLinter validations. Dismissing previous PRLinter review.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Thanks 👍
Some documentation adjustments are needed.
Also, can you please add back the default authorizer in the lambda integration test?
Is good to have some extra coverage.
readonly defaultAuthorizer?: IHttpRouteAuthorizer; | ||
|
||
/** | ||
* Default OIDC scopes attached to all routes in the gateway, unless explicitly configured on the route. |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
* Default OIDC scopes attached to all routes in the gateway, unless explicitly configured on the route. | |
* Default OIDC scopes attached to all routes in the gateway, unless explicitly configured on the route. | |
* The scopes are used with a COGNITO_USER_POOLS authorizer to authorize the method invocation. | |
* |
Can you please align this as well?
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Can you please provide documentation that describes the usage with a JWT authorizer?
I was only able to verify the COGNITO_USER_POOLS authorizer.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Oh... I tried in the integ.lambda with defaultAuthorizationScopes in httpApiWithDefaultAuthorizer, CFn occurred the following error message.
I'll see if I can find any documentation.
UPDATE_ROLLBACK_COMPLETE: Resource handler returned message: "Invalid Route authorization type specified. Authorization Scopes are only valid for COGNITO_USER_POOLS and JWT authorization types (Service: AmazonApiGatewayV2; Status Code: 400; Error Code: BadRequestException; Request ID: xxxxxx; Proxy: null)" (RequestToken: xxxxxx, HandlerErrorCode: GeneralServiceException)
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
There is If you specify the AuthorizerId property, specify CUSTOM or COGNITO_USER_POOLS for this property.
in the CFn doc.
I guess this CFn message represents CUSTOM
COGNITO_USER_POOLS
as JWT.
What should we do in CDK doc?
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
I found only this article.
https://docs.aws.amazon.com/apigateway/latest/developerguide/http-api-jwt-authorizer.html
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
I'm starting to feel that COGNITO_USER_POOLS is all I need.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Yeah, I think that COGNITO_USER_POOLS
is sufficient since it generates a JWT
authorizer.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
In the meantime, please review again as I have added only COGNITO_USER_POOLS for the message.
/** | ||
* Default Authorizer to applied to all routes in the gateway | ||
* @attribute | ||
* @default - No authorizer | ||
*/ |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
/** | |
* Default Authorizer to applied to all routes in the gateway | |
* @attribute | |
* @default - No authorizer | |
*/ | |
/** | |
* Default Authorizer applied to all routes in the gateway. | |
* | |
* @attribute | |
* @default - no default authorizer | |
*/ |
Can you please align this as well?
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Please check.
OK, I changed the integ.lambda and added snapshots. |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Thanks 👍
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Thanks for you contribution!
Thank you for contributing! Your pull request will be updated from main and then merged automatically (do not update manually, and be sure to allow changes to be pushed to your fork). |
Thank you for contributing! Your pull request will be updated from main and then merged automatically (do not update manually, and be sure to allow changes to be pushed to your fork). |
AWS CodeBuild CI Report
Powered by github-codebuild-logs, available on the AWS Serverless Application Repository |
Thank you for contributing! Your pull request will be updated from main and then merged automatically (do not update manually, and be sure to allow changes to be pushed to your fork). |
This PR fixes a bug that
defaultAuthorizer
cannot be applied toHttpRoute
without an authorizer.Closes #27436.
By submitting this pull request, I confirm that my contribution is made under the terms of the Apache-2.0 license