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

AwsCustomResource: Response too long when doing Securityhub:createConfigurationPolicy #28498

Closed
kabo opened this issue Dec 27, 2023 · 4 comments
Labels
@aws-cdk/aws-iam Related to AWS Identity and Access Management bug This issue is a bug. effort/medium Medium work item – several days of effort p2 response-requested Waiting on additional info and feedback. Will move to "closing-soon" in 7 days.

Comments

@kabo
Copy link

kabo commented Dec 27, 2023

Describe the bug

We're trying to set up a securityhub configuration policy. There's no native cloudformation support for this so we figured a custom resource would be suitable.

    new AwsCustomResource(this, 'CreatePolicy', {
      resourceType: 'Custom::ConfigurationPolicy',
      installLatestAwsSdk: true,
      logRetention: RetentionDays.ONE_MONTH,
      onCreate: {
        service: 'Securityhub',
        action: 'createConfigurationPolicy',
        ignoreErrorCodesMatching: '.*',
        parameters: {
          Name: 'MyPolicy',
          ConfigurationPolicy: {
            SecurityHub: {
              EnabledStandardIdentifiers: [
                'arn:aws:securityhub:eu-west-1::standards/aws-foundational-security-best-practices/v/1.0.0',
              ],
              SecurityControlsConfiguration: {
                DisabledSecurityControlIdentifiers: [
                  'Macie.1',
                ],
              },
              ServiceEnabled: true,
            },
          },
        },
        physicalResourceId: PhysicalResourceId.of('MyPolicy'),
      },
      policy: AwsCustomResourcePolicy.fromSdkCalls({
        resources: AwsCustomResourcePolicy.ANY_RESOURCE,
      }),
    })

This fails with Response object is too long. Event though we've tried to ignore all errors with ignoreErrorCodesMatching: '.*'.

The policy is successfully created, but the resource shows it as failing.

Expected Behavior

The custom resource to be created successfully.

Current Behavior

Resource fails with Response object is too long

Reproduction Steps

See above

Possible Solution

Handle the longer response objects? Escape hatch similar to ignoreErrorCodesMatching to ignore this type of failure?

Additional Information/Context

No response

CDK CLI Version

2.115.0 (build 58027ee)

Framework Version

No response

Node.js Version

20

OS

Artix Linux

Language

TypeScript

Language Version

TypeScript 5.3.3

Other information

No response

@kabo kabo added bug This issue is a bug. needs-triage This issue or PR still needs to be triaged. labels Dec 27, 2023
@github-actions github-actions bot added the @aws-cdk/aws-iam Related to AWS Identity and Access Management label Dec 27, 2023
@kabo
Copy link
Author

kabo commented Dec 27, 2023

Workaround: provide your own lambda to do the creation

    const lambda = new NodejsFunction(this, 'CreatePolicyLambda', {
      entry: join(dirname, './create-policy/index.ts'),
      logRetention: RetentionDays.ONE_MONTH,
      runtime: Runtime.NODEJS_20_X,
      architecture: Architecture.ARM_64,
      memorySize: 256,
      timeout: Duration.seconds(60),
      bundling: {
        minify: true,
        sourceMap: false,
        mainFields: [ 'module', 'main' ],
        target: 'node20',
        format: OutputFormat.ESM,
        externalModules: [],
      },
    })
    lambda.addToRolePolicy(new PolicyStatement({
      actions: [
        'securityHub:CreateConfigurationPolicy',
      ],
      resources: [
        '*',
      ],
    }))

    const provider = new Provider(this, 'CreatePolicyProvider', {
      onEventHandler: lambda,
    })
    new CustomResource(this, 'CreatePolicy', {
      serviceToken: provider.serviceToken,
      resourceType: 'Custom::CreatePolicy',
    })

@pahud
Copy link
Contributor

pahud commented Dec 27, 2023

Generally, for all the response too long or response too large issues from AwsCustomResource, you can always specify outputPaths to filter its output.

For example:

outputPaths: [
'ClusterInfo.ZookeeperConnectString',
'ClusterInfo.ZookeeperConnectStringTls',

@pahud pahud added p2 response-requested Waiting on additional info and feedback. Will move to "closing-soon" in 7 days. effort/medium Medium work item – several days of effort and removed needs-triage This issue or PR still needs to be triaged. labels Dec 27, 2023
@kabo
Copy link
Author

kabo commented Dec 29, 2023

I think outputPaths solves this issue. Closing.

@kabo kabo closed this as completed Dec 29, 2023
Copy link

⚠️COMMENT VISIBILITY WARNING⚠️

Comments on closed issues are hard for our team to see.
If you need more assistance, please either tag a team member or open a new issue that references this one.
If you wish to keep having a conversation with other community members under this issue feel free to do so.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
@aws-cdk/aws-iam Related to AWS Identity and Access Management bug This issue is a bug. effort/medium Medium work item – several days of effort p2 response-requested Waiting on additional info and feedback. Will move to "closing-soon" in 7 days.
Projects
None yet
Development

No branches or pull requests

2 participants