aws-cloudformation / aws-cloudformation/cloudformation-coverage-roadmap
Cloudformation will fail for custom lambda resource on VPC with vpc endpoint policy having PrincipalOrgID
- Dominant language
- No language data
- Stars
- 1.1k
- Forks
- 62
- PR merge metrics
- No merged PRs in 30d
Description
Issue:
Cfn response from the Lambda function to the buckets hosted on AWS is not making through and resulted in Access denied from the Lambda Perspective, which inturn causing cloudformation stack to fail (If VPC Endpoint policy has PrincipalOrgID)
Note - Accessing the bucket hosted on the same account works, access getting denied only for aws owned bucket.
I'm able to successfully replicate the issue in my environment, The issue is on the condition statement present in the endpoint policy, The process works good by removing the condition param which is in the policy which holds PrincipalOrgID.
Exact steps to reproduce issue (numbered):
--------------------------------------------------
1. Make sure the account belongs to a aws organization
2. Create VPC with subnet without internet gateway
3. Create a S3 VPC endpoint and attach the following policy.
4. Note - Modify the PrincipalOrgID with your org id.
```
{
"Version": "2012-10-17",
"Id": "Policy1598863929319",
"Statement": [
{
"Sid": "Stmt1598863925525",
"Effect": "Allow",
"Principal": "*",
"Action": "s3:*",
"Resource": "arn:aws:s3:::*",
"Condition": {
"StringEquals": {
"aws:PrincipalOrgID": "o-xxxxxxxxxx"
}
}
}
]
}
```
5. Create a sample Lambda function which does sum and returns cfn response and place it inside the VPC.
https://aws.amazon.com/blogs/infrastructure-and-automation/aws-cloudformation-custom-resource-creation-with-python-aws-lambda-and-crhelper/
My sample Lambda function. = Runtime Python 3.7 (entire zip file attached)
```
from crhelper import CfnResource
helper = CfnResource()
@helper.create
@helper.update
def sum_2_numbers(event, _):
s = int(event['ResourceProperties']['No1']) + int(event['ResourceProperties']['No2'])
helper.Data['Sum'] = s
@helper.delete
def no_op(_, __):
pass
def handler(event, context):
helper(event, context)
```
6. Cloudformation template:
```
AWSTemplateFormatVersion: "2010-09-09"
Resources:
SumResource:
Type: "Custom::Summer"
Properties:
ServiceToken: "arn:aws:lambda:us-west-2:xxxxxxxx:function:crhelper-sum-resource"
No1: 1
No2: 2
Outputs:
Sum:
Value: !GetAtt SumResource.Sum
```
7. The Lambda execution will fail with access forbidden error and cloudformation stack will stuck in create in progress.
--------------------------------------------------
Contributor guide
Assessment
This issue has not been assessed yet.