-
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(cognito-identitypool-alpha): cannot configure roleMappings with imported userPool and client #30421
fix(cognito-identitypool-alpha): cannot configure roleMappings with imported userPool and client #30421
Conversation
…giot-idp-use-imported-user-pool
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.
Thank you for your contribution. Please see my comments inline.
@@ -353,13 +353,18 @@ cannot be references. For example: | |||
import { UserPool, UserPoolClient } from 'aws-cdk-lib/aws-cognito'; | |||
import { IdentityPoolProviderUrl } from '@aws-cdk/aws-cognito-identitypool-alpha'; | |||
|
|||
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.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Please specify why this is the case. This comment alone gives me pause about these changes.
@@ -874,6 +906,48 @@ export class UserPool extends UserPoolBase { | |||
class ImportedUserPool extends UserPoolBase { | |||
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.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
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.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
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.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
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.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Doing so would mitigate every one of my comments above.
Pull request has been modified.
Hi @TheRealAmazonKendra |
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 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.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
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?
@@ -767,6 +767,12 @@ export interface IUserPool extends IResource { | |||
*/ | |||
readonly userPoolArn: string; | |||
|
|||
/** | |||
* User pool provider name |
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 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
.
@@ -870,10 +877,14 @@ export class UserPool extends UserPoolBase { | |||
} | |||
|
|||
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.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
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.
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.
Nice work, thanks @sakurai-ryo and @Leo10Gama both!
@Mergifyio update |
❌ Mergify doesn't have permission to updateFor security reasons, Mergify can't update this pull request. Try updating locally. |
@Mergifyio update |
☑️ Nothing to do
|
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.userPool
method takes an L2 construct as its argument type instead of Interface (IUserPool
,IUserPoolClient
).Description of changes
The argument types of the
IdentityPoolProviderUrl.userPool
method are changed toIUserPool
andIUserPoolClient
.This method requires the
userPoolProviderName
of the userPool, but since it does not exist forIUserPool
, a property was added.Since this property is required in the
UserPool
construct, 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