amazon-web-services - 云形成安全组未创建入口规则

标签 amazon-web-services aws-cloudformation

我为一个安全组创建了一个 cloudformation 模板,其中包含 3 个入口规则,一个用于 SSH,一个用于 HTTP,另一个用于 HTTP(端口 8080)

首先,当我包含 SourceSecurityGroupOwnerId 时,该组根本不会创建。当我删除它时,该组会创建但仅使用一条规则(ssh 规则)。

这是完整的模板:

AWSTemplateFormatVersion: 2010-09-09
Description: Provision security group to allow SSH access to instance
Parameters:
  EnvironmentName:
    Description: An environment name that will be prefixed to resource names
    Type: String
  SSHLocation:
    Description: The IP address range that can be used to SSH to the EC2 instances
    Type: String
    MinLength: '9'
    MaxLength: '18'
    Default: 0.0.0.0/0
    AllowedPattern: '(\d{1,3})\.(\d{1,3})\.(\d{1,3})\.(\d{1,3})/(\d{1,2})'
    ConstraintDescription: must be a valid IP CIDR range of the form x.x.x.x/x.

Resources:
  InstanceSecurityGroup:
    Type: 'AWS::EC2::SecurityGroup'
    Properties:
      VpcId: !ImportValue hvfVPC-Name
      Tags:
        - Key: Name
          Value: !Ref EnvironmentName
      GroupDescription: Enable SSH access and HTTP from the load balancer only
      SecurityGroupIngress:
        - IpProtocol: tcp
          FromPort: '22'
          ToPort: '22'
          CidrIp: !Ref SSHLocation
        - IpProtocol: tcp
          FromPort: '80'
          ToPort: '80'
          SourceSecurityGroupOwnerId: !ImportValue wordpressELB-SG-Id
          SourceSecurityGroupName: !ImportValue wordpressELB-SG-Name
        - IpProtocol: tcp
          FromPort: '8080'
          ToPort: '8080'
          SourceSecurityGroupOwnerId: !ImportValue wordpressELB-SG-Id
          SourceSecurityGroupName: !ImportValue wordpressELB-SG-Name

这最终只是运行了很长一段时间而没有实际创建组。当我删除 SourceSecurityGroupId 和 SourceSecurityGroupName 时,模板会运行,但它只创建一个入口规则。

我进行了三次检查,以确保导出正确,但由于某种原因,除非我删除这两行,否则 Cloudformation 就会挂起

附上图片以供澄清 CloudFormation says the group is created Only the SSH ingress rule is actually created

Exports from the ELB template that I'm trying to use in the SG template

最佳答案

我的猜测是,您应该简单地指定 SourceSecurityGroupId 而不是 SourceSecurityGroupOwnerIdSourceSecurityGroupName。大致思路是这样的:

    - IpProtocol: tcp
      FromPort: 80
      ToPort: 80
      SourceSecurityGroupId: !ImportValue wordpressELB-SG-Id

类似的配置很适合我。

关于 SourceSecurityGroupOwnerId 的文档说:

You can't specify this parameter in combination with the following parameters: the CIDR IP address range, the IP protocol, the start of the port range, and the end of the port range.

这可能是未创建规则的原因。

接下来,您似乎在 SourceSecurityGroupOwnerId 中指定了源安全组 wordpressELB-SG-Id 的 ID。 SourceSecurityGroupOwnerId 实际上是源安全组的 AWS账户 ID,因此这无论如何都是不正确的。

关于amazon-web-services - 云形成安全组未创建入口规则,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/58071034/

相关文章:

amazon-web-services - Cloudwatch 中未显示 Cognito 的指标

java - 运行集成测试时,Maven Shade 插件会导致类路径上出现重复的 jar

amazon-web-services - Cloudformation 中的 VPC 终端节点 - 终端节点类型(网关)与可用服务类型([接口(interface)])不匹配

amazon-web-services - 在 CloudFormation 中,将子网 ID 存储在 Parameter Store 中

amazon-web-services - 如何描述cloudformation跨帐户堆栈信息/名称/详细信息

amazon-web-services - 从 AWS 模板、lambda 指定 AWS EMR 安全配置

amazon-web-services - ELB 和 ECS 集群前的 Amazon API Gateway

amazon-s3 - 将 S3 存储桶挂载为 EC2 实例上的 NFS 共享

amazon-web-services - 使用 cloudformation 为 S3 存储桶启用 Lambda 函数

amazon-web-services - 安装 AWS EFS 后无法访问 Drupal 站点