簡體   English   中英

雲形成安全組未創建入口規則

[英]Cloud formation security group is not creating ingress rules

我為具有 3 個入口規則的安全組創建了一個 cloudformation 模板,一個用於 SSH,一個用於 HTTP,另一個用於 HTTP(port8080)

首先,當我包含 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表示該組已創建實際上僅創建了 SSH 入口規則

從我嘗試在 SG 模板中使用的 ELB 模板導出

我的猜測是您應該簡單地指定SourceSecurityGroupId而不是SourceSecurityGroupOwnerIdSourceSecurityGroupName 類似的東西:

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

類似的配置很適合我。

SourceSecurityGroupOwnerId上的文檔說:

此參數不能與以下參數組合指定:CIDR IP 地址范圍、IP 協議、端口范圍的開始和端口范圍的結束。

這可能是未創建規則的原因。

接下來,您似乎在SourceSecurityGroupOwnerId中指定了源安全組wordpressELB-SG-Id的 ID。 SourceSecurityGroupOwnerId實際上是源安全組的 AWS賬戶 ID ,所以無論如何這都不正確。

暫無
暫無

聲明:本站的技術帖子網頁,遵循CC BY-SA 4.0協議,如果您需要轉載,請注明本站網址或者原文地址。任何問題請咨詢:yoyou2525@163.com.

 
粵ICP備18138465號  © 2020-2024 STACKOOM.COM