已经为此创建了一个类似的问题。我阅读了一些答案,但我无法解决问题。我不得不为此创建一个单独的帖子,因为我没有足够的声誉点来回复该帖子中的用户。链接是:-这里。除了几个安全组之外,我想限制所有公开的端口。例如,对于其中一个安全组,我不希望端口 80 向公众公开,但对于安全组说“sg-123456789”,我希望端口 80 向公众开放。如何编写云托管策略?
- name: sg-123456789
resource: security-group
description: |
Remove any rule from a security group that allows 0.0.0.0/0 or ::/0 (IPv6) ingress
mode:
type: cloudtrail
role: arn:aws:iam::9797979797:role/cloudcustodianrole
events:
- source: ec2.amazonaws.com
event: AuthorizeSecurityGroupIngress
ids: "requestParameters.groupId"
- source: ec2.amazonaws.com
event: RevokeSecurityGroupIngress
ids: "requestParameters.groupId"
filters:
-and:
- type: value
key: GroudId
value: "sg-123456789"
op: in
-or:
- type: ingress
OnlyPorts: [80]
Cidr:
value: "0.0.0.0/0"
op: in
- type: ingress
OnlyPorts: [80]
CidrV6:
value: "::/0"
op: in
actions:
- type: remove-permissions
ingress: matched
- name: sg-987654321
resource: security-group
description: |
Remove any rule from a security group that allows 0.0.0.0/0 or ::/0 (IPv6) ingress
mode:
type: cloudtrail
role: arn:aws:iam::9797979797:role/cloudcustodianrole
events:
- source: ec2.amazonaws.com
event: AuthorizeSecurityGroupIngress
ids: "requestParameters.groupId"
- source: ec2.amazonaws.com
event: RevokeSecurityGroupIngress
ids: "requestParameters.groupId"
filters:
-and:
- type: value
key: GroudId
value: "sg-987654321"
op: in
-or:
- type: ingress
OnlyPorts: [3000]
Cidr:
value: "0.0.0.0/0"
op: in
- type: ingress
OnlyPorts: [3000]
CidrV6:
value: "::/0"
op: in
actions:
- type: remove-permissions
ingress: matched