简体   繁体   English

撤销所有安全组入口规则(与源安全组)

[英]Revoke all security group ingress rules (with source security groups)

I have an ec2.SecurityGroup that I'd like to delete all rules from.我有一个 ec2.SecurityGroup 我想从中删除所有规则。 I am having trouble removing the default ingress rule for the group, where the source is the security group's ID:我无法删除组的默认入口规则,其中源是安全组的 ID:

具有安全组源的示例入口规则

I do so this way, using the Go SDK:我这样做,使用 Go SDK:

for _, perm := sg.IpPermissions {
  for _, pair := range perm.UserIdGroupPairs {
    service.RevokeSecurityGroupIngress(&ec2.RevokeSecurityGroupIngressInput{
    SourceSecurityGroupName: pair.GroupId,
    IpProtocol: perm.IpProtocol,
    SourceSecurityGroupOwnerId: pair.UserId,
        GroupId: sg.GroupId,
    });
  }
}

However, this produces an error: "VPCIdNotSpecified: No default VPC for this user".但是,这会产生错误:“VPCIdNotSpecified: No default VPC for this user”。
How am I supposed to revoke this rule, and ALL others?我应该如何撤销这条规则,以及所有其他规则? Go is preferred in answers but a way to accomplish this in any language would be appreciated. Go 在答案中是首选,但以任何语言实现此目的的方法将不胜感激。

I'm not a Go person, but here's some equivalent Python code:我不是 Go 人,但这里有一些等效的 Python 代码:

import boto3

ec2_client = boto3.client('ec2')

response = ec2_client.describe_security_groups(GroupIds=['sg-xxx'])

for group in response['SecurityGroups']:
    ec2_client.revoke_security_group_ingress(GroupId=group['GroupId'], IpPermissions = group['IpPermissions'])

Notice that the IpPermissions object returned from describe_security_groups() can be passed directly into revoke_security_group_ingress() .请注意,从describe_security_groups()返回的IpPermissions object 可以直接传递到revoke_security_group_ingress()中。 Hopefully you can do the same thing in Go.希望您可以在 Go 中做同样的事情。

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

相关问题 撤销所有 AWS 安全组入口规则 - Revoke all AWS security group ingress rules 如何使用 boto3 的 revoke_ingress 方法从入站规则中删除特定安全组 - How to use revoke_ingress method of boto3 to remove a particular security group from inbound rules Terraform - 为安全组迭代并创建入口规则 - Terraform - Iterate and create Ingress Rules for a Security Group 云形成安全组未创建入口规则 - Cloud formation security group is not creating ingress rules 将参数化的安全组列表添加到另一个安全组的入口 - Add a parameterized list of security groups to another security group's ingress Terraform:ingress_with_source_security_group_id 与 computed_ingress_with_source_security_group_id - Terraform: ingress_with_source_security_group_id vs. computed_ingress_with_source_security_group_id 安全组的入站规则 - Inbound rules for security groups 是否可以将对负载均衡器的入站/入口访问限制为源安全组? - is it possible to limit inbound/ingress access to a load balancer to a source security group? 为什么在 alb.ingress.kubernetes.io/security-groups 注释中提供的安全组上尝试删除 - Why delete is attempted on the security group provided in alb.ingress.kubernetes.io/security-groups annotation 安全组中的清除规则 - Clearing rules in Security Group
 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM