fix(cognito-identitypool-alpha): cannot configure roleMappings with imported userPool and client#30421
Conversation
…giot-idp-use-imported-user-pool
TheRealAmazonKendra
left a comment
There was a problem hiding this comment.
Thank you for your contribution. Please see my comments inline.
|
|
||
| declare const userPool: UserPool; | ||
| declare const userPoolClient: UserPoolClient; | ||
| // If you use a previously defined Cognito User Pool, use the `fromUserPoolAttributes` method instead of `fromUserPoolId` or `fromUserPoolArn`. |
There was a problem hiding this comment.
Please specify why this is the case. This comment alone gives me pause about these changes.
| public readonly userPoolArn = userPoolArn; | ||
| public readonly userPoolId = userPoolId; | ||
|
|
||
| // In the UserPool construct, the userPoolProviderName is a required property but it is constructed from the arn and id of the user pool. |
There was a problem hiding this comment.
I'm not sure I'm getting this. If the name is constructed from the ARN and ID of the userpool, why can't we construct this on import functions so that it's accessible to users?
There was a problem hiding this comment.
Also, wouldn't the ID be a subset of the ARN ?
| * Import an existing user pool into the stack. | ||
| */ | ||
| public static fromUserPoolAttributes(scope: Construct, id: string, attrs: UserPoolAttributes): IUserPool { | ||
| if (!attrs.userPoolArn && !attrs.userPoolId) { |
There was a problem hiding this comment.
I'm not sure that this function is really needed here. The fromId and fromArn functions should be able to assemble and return all of the missing attributes.
Correct me if I'm wrong but the attributes for a UserPool are:
Arn: arn:<partition>:cognito-idp:<region>:<account>:userpool/<userpoolId>
ProviderName: cognito-idp.<region>.<url-suffix>/<userpoolId>
ProviderURL: https://cognito-idp.<region>.<url-suffix>/userpoolId/.well-known/jwks.json (this is listed as the token signing key url, which I think is what's being referred to here?)
UserPoolId: userpoolId
So, given that, you could add each of the missing fields as attributes in the IUserPool and then construct each of these (assuming same region as in the id for fromId) in the existing fromXxx functions so that you don't even need to create a new function.
There was a problem hiding this comment.
Doing so would mitigate every one of my comments above.
Pull request has been modified.
|
Hi @TheRealAmazonKendra |
Leo10Gama
left a comment
There was a problem hiding this comment.
Thanks for the changes! Left a few more comments looking for a bit more clarification on these changes.
| const stack = new Stack(); | ||
| const stack = new Stack(undefined, undefined, { | ||
| env: { region: 'us-east-1', account: '0123456789012' }, | ||
| }); |
There was a problem hiding this comment.
Can we keep the stack identical for this test, or does it need these additional properties to work? If so, that would probably make these breaking changes. If not, can we update the logic that checks for the new userPoolProviderName so that it works without additional props?
| readonly userPoolArn: string; | ||
|
|
||
| /** | ||
| * User pool provider name |
There was a problem hiding this comment.
Can we update the docstring to be more similar to some of the other attributes? Feels redundant to have an attribute userPoolProviderName with the description User pool provider name.
|
|
||
| const userPoolId = arnParts.resourceName; | ||
| // ex) cognito-idp.us-east-1.amazonaws.com/us-east-1_abcdefghi | ||
| const providerName = `cognito-idp.${Stack.of(scope).region}.amazonaws.com/${userPoolId}`; |
There was a problem hiding this comment.
The formation logic of this string should be changed, since amazonaws.com is a partition that could be different for different users. Can you use the arnParts attributes for this instead? Something along the lines of:
`cognito-idp.${arnParts.region}.${arnParts.partition}/${userPoolId}`;
Pull request has been modified.
aws-cdk-automation
left a comment
There was a problem hiding this comment.
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.
paulhcsun
left a comment
There was a problem hiding this comment.
Nice work, thanks @sakurai-ryo and @Leo10Gama both!
|
@Mergifyio update |
❌ Mergify doesn't have permission to updateDetailsFor security reasons, Mergify can't update this pull request. Try updating locally. |
|
@Mergifyio update |
☑️ Nothing to doDetails
|
Pull request has been modified.
|
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). |
|
Comments on closed issues and PRs are hard for our team to see. |
Issue # (if applicable)
Closes #30304
Reason for this change
Currently, we cannot use imported user pools and clients for role mapping in an identity pool.
This is because the
IdentityPoolProviderUrl.userPoolmethod takes an L2 construct as its argument type instead of Interface (IUserPool,IUserPoolClient).Description of changes
The argument types of the
IdentityPoolProviderUrl.userPoolmethod are changed toIUserPoolandIUserPoolClient.This method requires the
userPoolProviderNameof the userPool, but since it does not exist forIUserPool, a property was added.Since this property is required in the
UserPoolconstruct, it is also required inIUserPool.aws-cdk/packages/aws-cdk-lib/aws-cognito/lib/user-pool.ts
Line 902 in c3003ab
I add a required attribute to the Interface of the aws-cognito module(stable), but I do not think this to be a breaking change.
Please let me know if it is not.
Description of how you validated changes
Unit tests and integ tests are added to verify that the imported userPool and clinet can be used.
Checklist
By submitting this pull request, I confirm that my contribution is made under the terms of the Apache-2.0 license