【问题标题】:How to allow certain ports open to world only for certain security groups in Cloud Custodian?如何允许某些端口仅对 Cloud Custodian 中的某些安全组开放?
【发布时间】:2019-09-07 13:14:41
【问题描述】:

我的政策中规定只允许 80 和 443 向世界开放。

      "or": [
        {
          "Cidr": {
            "value": "0.0.0.0/0"
          }, 
          "type": "ingress", 
          "OnlyPorts": [
            80, 
            443
          ]
        }, 
        {
          "CidrV6": {
            "value": "::/0"
          }, 
          "type": "ingress", 
          "OnlyPorts": [
            80, 
            443
          ]
        }
      ]

现在,我想只允许 8080 和 8081 进入选定的安全组,而不是所有安全组。这可能吗?

【问题讨论】:

    标签: amazon-ec2 policy aws-security-group standards-compliance cloudcustodian


    【解决方案1】:

    您只需要编辑特定的安全组。只需打开那里的端口即可。

    【讨论】:

    • 如果我打开端口,它将申请所有的安全组。有什么方法可以在策略文件中添加安全组 ID?
    • 如何在端口打开的情况下创建新的 sg 并将其附加到您要打开的其他 sg 上?
    • 一旦我创建了一个开放端口的新安全组,lambda函数就会被触发,它会删除对世界开放的规则。
    【解决方案2】:

    使用键和值数组添加值过滤器以排除您不想匹配的安全组

    【讨论】:

      【解决方案3】:

      对于 IPV4:

      resource: security-group
          filters:
            - tag:c7n_exception: absent
            - type: ingress
              OnlyPorts: [80,443]
              Cidr:
                value: "0.0.0.0/0"
      

      对于 IPV6:

          resource: security-group
          filters:
            - tag:c7n_exception: absent
            - type: ingress
              OnlyPorts: [80,443]
              CidrV6:
                value: "::/0"
      

      更多过滤器

      filters:
        - and:
                  - type: security-group
                    key: GroupId
                    #key: SecurityGroups[].GroupID  
                    op: not-in
                    value:
                      - sg-0db5e1ab7s8323
      

      【讨论】:

        猜你喜欢
        • 1970-01-01
        • 2014-07-07
        • 1970-01-01
        • 1970-01-01
        • 1970-01-01
        • 1970-01-01
        • 2021-03-20
        • 2020-09-18
        • 2014-10-23
        相关资源
        最近更新 更多