cloudformation-coverage-roadmap icon indicating copy to clipboard operation
cloudformation-coverage-roadmap copied to clipboard

Update of Security Group fails in a way that Rollback fails also

Open pplu opened this issue 4 years ago • 2 comments

Name of the resource

AWS::EC2::SecurityGroup

Resource Name

No response

Issue Description

When updating a stack with a Security Group Ingress rule that has a CidrIp to an invalid SourcePrefixListId, the update fails, as expected, but the rollback also fails unexpectedly.

Expected Behavior

The rollback should return the Security Group rule to the CidrIp from before the update.

Observed Behavior

CloudFormation reports that the update fails with:

The prefix list ID 'com.amazonaws.global.cloudfront.origin-facing' does not exist (Service: AmazonEC2; Status Code: 400; Error Code: InvalidPrefixListID.NotFound; Request ID: redacted; Proxy: null)

And as it is rolling back, the same error message appears: The prefix list ID 'com.amazonaws.global.cloudfront.origin-facing' does not exist (Service: AmazonEC2; Status Code: 400; Error Code: InvalidPrefixListID.NotFound; Request ID: redacted; Proxy: null)

leaving the stack in UPDATE_ROLLBACK_FAILED

Test Cases

Provision this template:

AWSTemplateFormatVersion: "2010-09-09"
Description: 'SG Error Test'
Parameters:
  VpcId:
    Type: String
Resources:
  SG:
    Type: AWS::EC2::SecurityGroup
    Properties:
      VpcId: !Ref VpcId
      GroupDescription: test
      SecurityGroupIngress:
      - CidrIp: '0.0.0.0/0'
        FromPort: 80
        ToPort: 80
        IpProtocol: tcp
        Description: open to CFront

Now update to this template

AWSTemplateFormatVersion: "2010-09-09"
Description: 'SG Error Test'
Parameters:
  VpcId:
    Type: String
Resources:
  SG:
    Type: AWS::EC2::SecurityGroup
    Properties:
      VpcId: !Ref VpcId
      GroupDescription: test
      SecurityGroupIngress:
      - SourcePrefixListId: 'com.amazonaws.global.cloudfront.origin-facing'
        FromPort: 80
        ToPort: 80
        IpProtocol: tcp
        Description: open to CFront

Other Details

Note that this happened to me when changing a Security Group from being open to 0.0.0.0/0 to using a SourcePrefixList. It was not evident that I had to look up the Id of the prefix list in my account (since the given name in the documentation (com.amazonaws.global.cloudfront.origin-facing) seems like an ID. It is very confusing that CloudFormation does not have a way to give the name of a source prefix list (com.amazonaws.global.cloudfront.origin-facing), instead of its ID pl-XXXX (which changes in each account, so it complicates templates).

pplu avatar Mar 08 '22 21:03 pplu

This issue has been fixed. I created a new stack using the template from the issue description:

AWSTemplateFormatVersion: "2010-09-09"
Description: 'SG Error Test'
Parameters:
  VpcId:
    Type: String
Resources:
  SG:
    Type: AWS::EC2::SecurityGroup
    Properties:
      VpcId: !Ref VpcId
      GroupDescription: test
      SecurityGroupIngress:
      - CidrIp: '0.0.0.0/0'
        FromPort: 80
        ToPort: 80
        IpProtocol: tcp
        Description: open to CFront

That created the security group fine:

% aws ec2 describe-security-groups --group-ids sg-... --region $REGION
{
    "SecurityGroups": [
        {
            "Description": "test",
            "GroupName": "...",
            "IpPermissions": [
                {
                    "FromPort": 80,
                    "IpProtocol": "tcp",
                    "IpRanges": [
                        {
                            "CidrIp": "0.0.0.0/0",
                            "Description": "open to CFront"
                        }
                    ],
                    "Ipv6Ranges": [],
                    "PrefixListIds": [],
                    "ToPort": 80,
                    "UserIdGroupPairs": []
                }
            ],
            ...
        }
    ]
}

I then updated the template to:

AWSTemplateFormatVersion: "2010-09-09"
Description: 'SG Error Test'
Parameters:
  VpcId:
    Type: String
Resources:
  SG:
    Type: AWS::EC2::SecurityGroup
    Properties:
      VpcId: !Ref VpcId
      GroupDescription: test
      SecurityGroupIngress:
      - SourcePrefixListId: 'com.amazonaws.global.cloudfront.origin-facing'
        FromPort: 80
        ToPort: 80
        IpProtocol: tcp
        Description: open to CFront

The update failed (as expected) but rolled back successfully:

% aws cloudformation describe-stacks --stack-name ... --region $REGION
{
    "Stacks": [
        {
            "StackId": "...",
            "StackName": "...",
            "Description": "SG Error Test",
            "Parameters": [
                {
                    "ParameterKey": "VpcId",
                    "ParameterValue": "vpc-..."
                }
            ],
            "CreationTime": "2025-05-16T19:41:54.512000+00:00",
            "LastUpdatedTime": "2025-05-16T19:45:10.282000+00:00",
            "RollbackConfiguration": {
                "RollbackTriggers": []
            },
            "StackStatus": "UPDATE_ROLLBACK_COMPLETE",
            "DisableRollback": false,
            "NotificationARNs": [],
            "Tags": [],
            "EnableTerminationProtection": false,
            "DriftInformation": {
                "StackDriftStatus": "NOT_CHECKED"
            }
        }
    ]
}

And the security group still looks right:

% aws ec2 describe-security-groups --group-ids sg-... --region $REGION
{
    "SecurityGroups": [
        {
            "Description": "test",
            "GroupName": "...",
            "IpPermissions": [
                {
                    "FromPort": 80,
                    "IpProtocol": "tcp",
                    "IpRanges": [
                        {
                            "CidrIp": "0.0.0.0/0",
                            "Description": "open to CFront"
                        }
                    ],
                    "Ipv6Ranges": [],
                    "PrefixListIds": [],
                    "ToPort": 80,
                    "UserIdGroupPairs": []
                }
            ],
            ...
        }
    ]
}

We'll close this issue out, but please either reopen it or create a new issue if you need anything else.

davidataws avatar May 19 '25 12:05 davidataws

Closing this out based on @davidataws 's comment above. Please let us know if the issue resurfaces or if you have questions.

shantgup avatar May 19 '25 13:05 shantgup