Skip to content

(cognito): Client Secret handler resource update breaks references #23796

@laurelmay

Description

@laurelmay

Describe the bug

In #23591 installLatestAwsSdk. This results in a resource update for custom resources. The custom resource that fetches the client secret does not have an onUpdate handler (https://github.com/aws/aws-cdk/blame/0798876e5e6c1a665033c759aed3bc0eab05a892/packages/%40aws-cdk/aws-cognito/lib/user-pool-client.ts#L449).

When the update occurs, the response object does not have a UserPoolClient.ClientSecret field, resulting in failures when .userPoolClientSecret is referenced.

This results in stacks that fail to update

Expected Behavior

Updates should happen gracefully. The same content as the onCreate handler should be run for update events.

Current Behavior

There is no update handler. Updates fail with an error like:

CustomResource attribute error: Vendor response doesn't contain UserPoolClient.ClientSecret key in object arn:aws-us-gov:cloudformation:us-gov-west-1:123456789012:stack/StackName/UUID|ResourceId|UUID in S3 bucket cloudformation-custom-resource-storage-usgovwest1

CloudWatch Logs shows:

{
    "RequestType": "Update",
    "ResourceType": "Custom::DescribeCognitoUserPoolClient",
    "ResourceProperties": {
        "ServiceToken": "...",
        "InstallLatestAwsSdk": "true",
        "Create": "{\"region\":\"us-gov-west-1\",\"service\":\"CognitoIdentityServiceProvider\",\"action\":\"describeUserPoolClient\",\"parameters\":{\"UserPoolId\":\"...\",\"ClientId\":\"...\"},\"physicalResourceId\":{\"id\":\"...\"}}"
    },
    "OldResourceProperties": {
        "ServiceToken": "...",
        "InstallLatestAwsSdk": "false",
        "Create": "{\"region\":\"us-gov-west-1\",\"service\":\"CognitoIdentityServiceProvider\",\"action\":\"describeUserPoolClient\",\"parameters\":{\"UserPoolId\":\"...\",\"ClientId\":\"...\"},\"physicalResourceId\":{\"id\":\"...\"}}"
    }
}

{
    "Status": "SUCCESS",
    "Reason": "OK",
    "PhysicalResourceId": "...",
    "StackId": "...",
    "RequestId": "...",
    "LogicalResourceId": "...",
    "NoEcho": false,
    "Data": {}
}

I can confirm, but do not want to share, the contents of the Create object match between the two events.

Reproduction Steps

import * as cdk from "aws-cdk-lib";
import * as cognito from "aws-cdk-lib/aws-cognito";
import * as secretsmanager from "aws-cdk-lib/aws-secretsmanager";

const app = new cdk.App();
const stack = new cdk.Stack(app, 'TestStack');
const userPool = new cognito.UserPool(stack, 'UserPool');
const client = userPool.addClient('TestClient', { generateSecret: true });
const secret = new secretsmanager.Secret(stack, 'ClientSecret', {
  secretStringValue: client.userPoolClientSecret;
});
  • update the stack using v2.61.1

Possible Solution

Copy the onCreate handler to onUpdate.

Additional Information/Context

Typically, if the User Pool ID or the User Pool Client ID changes, the User Pool Client Secret would too. But other properties passed to the resource can change (like installLatestAwsSdk) and this will result in a resource update

CDK CLI Version

2.61.1

Framework Version

No response

Node.js Version

16

OS

Linux

Language

Typescript

Language Version

No response

Other information

I am preparing a patch that implements the suggested fix.

Metadata

Metadata

Assignees

No one assigned

    Labels

    @aws-cdk/aws-cognitoRelated to Amazon CognitobugThis issue is a bug.needs-triageThis issue or PR still needs to be triaged.

    Type

    No type

    Projects

    No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions