aws-cdk icon indicating copy to clipboard operation
aws-cdk copied to clipboard

(opensearch): Response object is too long from cloudformation when adding enough access policies despite the update succeeding.

Open wordlesstruth opened this issue 2 years ago • 8 comments

Describe the bug

If you add enough access policies the response data from lambda is problematic.

The code is even aware of this limitation. However, clearly this is not sufficient.

We should be able to add policies that succeed in being updated on the domain by simply suppressing this data output.

    "Status": "SUCCESS",
    "Reason": "OK",
    "PhysicalResourceId": "blahAccessPolicy",
    "StackId": "arn:aws:cloudformation:us-west-2:blah:stack/blah-us-west-2/blah",
    "RequestId": "blah",
    "LogicalResourceId": "blahPolicy",
    "NoEcho": false,
    "Data": {
        "DomainConfig.AccessPolicies.Options": "{\"Version\":\"2012-10-17\",\"Statement\":[{\"Effect\":\"Allow\",\"Principal\":{\"Service\":[\"blah.blah.blah.blah.blah.blah\",\"us-west-2.blah.blah.blah.blah.blah\"]},\"Action\":\"es:ESHttp*\",\"Resource\":[\"arn:aws:es:us-west-2:blah:domain/blah/\",\"arn:aws:es:us-west-2:blah:domain/blah/*\"],\"Condition\":{\"ArnEquals\":{\"aws:PrincipalArn\":\"arn:aws:iam::*:role/blah\"}}} <TRUNCATED FOR BREVITY>",
        "DomainConfig.AccessPolicies.Status.PendingDeletion": false,
        "DomainConfig.AccessPolicies.Status.State": "Processing",
        "DomainConfig.AccessPolicies.Status.UpdateVersion": 45
    }

Expected Behavior

Ability to add access policies up to opensearch limit, not cloudformation limits imposed by this custom resource.

Current Behavior

Failed cloudformation deployments.

UPDATE_FAILED | Response object is too long.

Reproduction Steps

Add enough access policies to an opensearch domain and try to deploy it via cdk.

Possible Solution

  • Ability to add a NoEcho to custom resource
  • Ability to disable output DomainConfig.AccessPolicies.Options

Additional Information/Context

No response

CDK CLI Version

2.126.0 (build fb74c41)

Framework Version

No response

Node.js Version

18

OS

AL2

Language

TypeScript

Language Version

No response

Other information

No response

wordlesstruth avatar Feb 13 '24 19:02 wordlesstruth

I think I was able to workaround this by cloning this code and doing this myself: outputPaths: ['DomainConfig.AccessPolicies.Status'], note the deeper key of Status

wordlesstruth avatar Feb 14 '24 01:02 wordlesstruth

Yes we can always workdaround this by outputPaths.

The code is aware of that but the payload is from custom resource and I believe CDK actually can't see and validate that in synth time.

pahud avatar Feb 14 '24 17:02 pahud

Right, but I had to clone-and-own my own version to make this work - I'm wondering if it would be sufficient to merge in a change where you do go deeper one Key in the outputPaths ['DomainConfig.AccessPolicies.Status'] rather than ['DomainConfig.AccessPolicies'], or if anybody for some reason needs that Options key.. just give us the option to do something ourselves here.

wordlesstruth avatar Feb 14 '24 21:02 wordlesstruth

Hi @wordlesstruth,

Thank you for reporting this issue. This is a known limitation where CloudFormation custom resources have a 4KB response size limit. While the OpenSearchAccessPolicy implementation attempts to handle this using outputPaths, it's not sufficient when dealing with large policy documents.

The OpenSearch service itself supports larger access policies, but we need to modify the CDK implementation to handle the CloudFormation response size constraint.

We can resolve this by either:

  1. Adding the noEcho flag to suppress response data completely
  2. Further limiting the outputPaths to exclude the large policy document from the response

Would you be interested in contributing a fix? We can guide you through the implementation details.

Until this is fixed, as a workaround, you could:

  1. Split your access policies into smaller groups
  2. Create multiple policy attachments
  3. Or directly use CloudFormation/AWS SDK to update the policies

Let us know if you need any clarification or assistance.

Possible Solutions to fix it

// Solution 1: Add NoEcho flag to suppress response data
onUpdate: {
  // ...
  physicalResourceId: cr.PhysicalResourceId.of(`${props.domainName}AccessPolicy`),
  noEcho: true // Suppress sensitive information in response
}

// Solution 2: Further limit outputPaths
onUpdate: {
  // ...
  outputPaths: [
    'DomainConfig.AccessPolicies.Status.State',
    'DomainConfig.AccessPolicies.Status.UpdateVersion'
  ], // Exclude the large Options field
}

pahud avatar Jun 06 '25 21:06 pahud

As this doesn't have any workaround for customers I am making it a p1.

pahud avatar Jun 06 '25 21:06 pahud

I've just today come across this issue in the context of kubectl provider: https://github.com/aws/aws-cdk/blob/452a5e13f73046d1e58e5a92d33ae1e896c3251b/packages/%40aws-cdk/custom-resource-handlers/lib/aws-eks/kubectl-handler/apply/init.py

It seems certain k8s API responses can result in the same error Response object is too long.

I think this issue is more specfic to OpenSearch, but it seems like there's a few providers out there not considering the response size returned as a custom resource.

I'll raise a separate issue for my case.

andyt10 avatar Jun 10 '25 00:06 andyt10

@wordlesstruth Could you please elaborate more on how you are using the OpenSearchAccessPolicy custom resource? I noticed that it is (mainly) used in the Amazon OpenSearch Service domain creation flow. If your use case involves using the custom resource through the Domain construct, there may be more changes required than initially expected.

kumvprat avatar Jun 12 '25 15:06 kumvprat

Comments on closed issues and PRs are hard for our team to see. If you need help, please open a new issue that references this one.

github-actions[bot] avatar Jun 16 '25 15:06 github-actions[bot]