Skip to content
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

feat(cognito): allow retrieval of UserPoolClient generated client secret #21262

Merged
merged 54 commits into from
Aug 5, 2022
Merged

feat(cognito): allow retrieval of UserPoolClient generated client secret #21262

merged 54 commits into from
Aug 5, 2022

Conversation

Dzhuneyt
Copy link
Contributor

@Dzhuneyt Dzhuneyt commented Jul 21, 2022

Consumers of the cognito.UserPoolClient construct currently have a way to retrieve useful information and pass that information to other pieces of infrastructure (e.g. Lambdas, ECS, Parameter Store, CfnOutput), e.g. the Client ID, which is useful for certain operations against the Cognito user pool that require a Cognito client.

However, if consumers decide to configure the Client, with a pre-generated (random) Client Secret for security reasons, by passing the generateSecret: true prop to cognito.UserPoolClient, most operations to the Cognito UserPool now require the Client ID AND Client Secret, otherwise they generate the Unable to verify secret hash for client <client-id> error (see AWS support article for more info).

Currently, the construct exposes no way to retrieve the Client Secret, forcing consumers to work around this by using custom resources or custom AWS SDK calls to retrieve it.

This PR addresses that, by exposing a new getter method of the UserPoolClient class, allowing consumers to read it on demand and pass it to other pieces of infrastructure, using code like:

const userPoolClient = new cognito.UserPoolClient(this, 'UserPoolClient', {
  userPool,
  generateSecret: true,
});

// Allows you to pass the generated secret to other pieces of infrastructure
const secret = userPoolClient.userPoolClientSecret;

Closes #7225


All Submissions:

Adding new Unconventional Dependencies:

  • This PR adds new unconventional dependencies following the process described here

New Features

  • Have you added the new feature to an integration test?
    • Did you use yarn integ to deploy the infrastructure and generate the snapshot (i.e. yarn integ without --dry-run)?

By submitting this pull request, I confirm that my contribution is made under the terms of the Apache-2.0 license

Dzhuneyt and others added 13 commits January 31, 2022 14:49
…ion with `userDataCausesReplacement` (#18726)

If both `addSignalOnExitCommand` _and_ `userDataCausesReplacement` are
 used it results in an invalid logicalId being used in the
`cfn-signal` call. This is due to `addSignalOnExitCommand` getting the
logicalID from `Stack.getLogicalId` which does not take into
consideration logicalId overrides which `userDataCausesReplacement`
uses.

This updates `addSignalOnExitCommand` to use the `logicalId` of the
resource which is evaluated lazily and happens after all overrides.

fixes #12749


----

*By submitting this pull request, I confirm that my contribution is made under the terms of the Apache-2.0 license*
@gitpod-io
Copy link

gitpod-io bot commented Jul 21, 2022

@aws-cdk-automation aws-cdk-automation requested a review from a team July 21, 2022 09:56
@github-actions github-actions bot added effort/medium Medium work item – several days of effort feature-request A feature should be added or improved. p1 labels Jul 21, 2022
Copy link
Contributor

@misterjoshua misterjoshua left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I like the idea and this is a great start, but I have a few thoughts.

@pahud Could you please tag a few more community reviewers for this one?

Copy link
Contributor

@misterjoshua misterjoshua left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

This looks really good. I have only a few small nitpicky comments.

I'd like to see more community feedback and perhaps some review by the CDK group, but otherwise, I'm happy with this changeset.

Thanks for your work so far!

@mergify mergify bot dismissed TheRealAmazonKendra’s stale review August 1, 2022 21:52

Pull request has been modified.

@Dzhuneyt Dzhuneyt changed the title feat: Retrieve UserPoolClient generated secret feat(cognito): Retrieve UserPoolClient generated secret Aug 1, 2022
@Dzhuneyt Dzhuneyt changed the title feat(cognito): Retrieve UserPoolClient generated secret feat(cognito): Allow retrieving UserPoolClient generated Client Secret Aug 1, 2022
@Dzhuneyt
Copy link
Contributor Author

Dzhuneyt commented Aug 1, 2022

@TheRealAmazonKendra this should be ready for another set of eyes now. Just FYI. Thanks for the good tips above.

@TheRealAmazonKendra TheRealAmazonKendra changed the title feat(cognito): Allow retrieving UserPoolClient generated Client Secret feat(cognito): allow retrieval of UserPoolClient generated client secret Aug 2, 2022
Copy link
Contributor

@TheRealAmazonKendra TheRealAmazonKendra left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Just a few nitpicky things and then this will be ready to go!

Co-authored-by: Kendra Neil <53584728+TheRealAmazonKendra@users.noreply.github.com>
@mergify mergify bot dismissed TheRealAmazonKendra’s stale review August 2, 2022 07:20

Pull request has been modified.

@mergify
Copy link
Contributor

mergify bot commented Aug 2, 2022

update

✅ Branch has been successfully updated

@mergify mergify bot dismissed TheRealAmazonKendra’s stale review August 3, 2022 11:54

Pull request has been modified.

Copy link
Contributor

@TheRealAmazonKendra TheRealAmazonKendra left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I've left suggestions below with the kind of testing I'm looking for. Feel free to just commit my suggestions directly. I've tested them locally and it passes.

Dzhuneyt and others added 2 commits August 5, 2022 09:06
Co-authored-by: Kendra Neil <53584728+TheRealAmazonKendra@users.noreply.github.com>
@mergify mergify bot dismissed TheRealAmazonKendra’s stale review August 5, 2022 06:06

Pull request has been modified.

@mergify
Copy link
Contributor

mergify bot commented Aug 5, 2022

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).

@mergify mergify bot merged commit 67a24ba into aws:main Aug 5, 2022
@mergify
Copy link
Contributor

mergify bot commented Aug 5, 2022

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-cdk-automation
Copy link
Collaborator

AWS CodeBuild CI Report

  • CodeBuild project: AutoBuildv2Project1C6BFA3F-wQm2hXv2jqQv
  • Commit ID: d6c2cc8
  • Result: SUCCEEDED
  • Build Logs (available for 30 days)

Powered by github-codebuild-logs, available on the AWS Serverless Application Repository

@Dzhuneyt Dzhuneyt deleted the dzhuneyt/issue-7225-userpool-secret branch August 5, 2022 15:15
josephedward pushed a commit to josephedward/aws-cdk that referenced this pull request Aug 30, 2022
…ret (aws#21262)

Consumers of the `cognito.UserPoolClient` construct currently have a way to retrieve useful information and pass that information to other pieces of infrastructure (e.g. Lambdas, ECS, Parameter Store, CfnOutput), e.g. the Client ID, which is useful for certain operations against the Cognito user pool that require a Cognito client.

However, if consumers decide to configure the Client, with a pre-generated (random) Client Secret for security reasons, by passing the `generateSecret: true` prop to `cognito.UserPoolClient`, most operations to the Cognito UserPool now require the Client ID AND Client Secret, otherwise they generate the `Unable to verify secret hash for client <client-id>` error (see [AWS support article](https://aws.amazon.com/premiumsupport/knowledge-center/cognito-unable-to-verify-secret-hash/) for more info).

Currently, the construct exposes no way to retrieve the Client Secret, forcing consumers to work around this by using custom resources or custom AWS SDK calls to retrieve it.

This PR addresses that, by exposing a new getter method of the `UserPoolClient` class, allowing consumers to read it on demand and pass it to other pieces of infrastructure, using code like:

```ts
const userPoolClient = new cognito.UserPoolClient(this, 'UserPoolClient', {
  userPool,
  generateSecret: true,
});

// Allows you to pass the generated secret to other pieces of infrastructure
const secret = userPoolClient.userPoolClientSecret;
```

Closes aws#7225

----

### All Submissions:

* [X] Have you followed the guidelines in our [Contributing guide?](https://github.com/aws/aws-cdk/blob/main/CONTRIBUTING.md)

### Adding new Unconventional Dependencies:

* [ ] This PR adds new unconventional dependencies following the process described [here](https://github.com/aws/aws-cdk/blob/main/CONTRIBUTING.md/#adding-new-unconventional-dependencies)

### New Features

* [ ] Have you added the new feature to an [integration test](https://github.com/aws/aws-cdk/blob/main/INTEGRATION_TESTS.md)?
	* [ ] Did you use `yarn integ` to deploy the infrastructure and generate the snapshot (i.e. `yarn integ` without `--dry-run`)?

*By submitting this pull request, I confirm that my contribution is made under the terms of the Apache-2.0 license*
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
effort/medium Medium work item – several days of effort feature-request A feature should be added or improved. p1
Projects
None yet
Development

Successfully merging this pull request may close these issues.

UserPoolClient - Retrieve the client secret
8 participants