(opensearch): Response object is too long from cloudformation when adding enough access policies despite the update succeeding.
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
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
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.
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.
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:
- Adding the
noEchoflag to suppress response data completely - Further limiting the
outputPathsto 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:
- Split your access policies into smaller groups
- Create multiple policy attachments
- 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
}
As this doesn't have any workaround for customers I am making it a p1.
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.
@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.
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.