![](/img/trans.png)
[英]Terraform: create resource(aws_security_group) successfully but it takes ingress/egress rules from all given security groups
[英]Terraform AWS Security Group settings to allow all ports between all VMS
我有点难过。 我有一个自定义服务(名为 bacalhau)在 54545 的安全组中的每三台机器上运行。我还在所有机器上运行 SSH。 这是我的 terraform 的样子:
resource "aws_security_group" "allow_ssh_and_bacalhau" {
vpc_id = aws_vpc.bacalhau_vpc.id
name = "allow_ssh_and_bacalhau"
description = "security group that allows ssh and bacalhau and all egress traffic"
}
resource "aws_security_group_rule" "egress_all" {
type = "egress"
from_port = 0
to_port = 0
protocol = "-1"
cidr_blocks = ["0.0.0.0/0"]
security_group_id = aws_security_group.allow_ssh_and_bacalhau.id
}
resource "aws_security_group_rule" "ingress_ssh" {
type = "ingress"
from_port = 22
to_port = 22
protocol = "-1"
cidr_blocks = ["0.0.0.0/0"]
security_group_id = aws_security_group.allow_ssh_and_bacalhau.id
}
resource "aws_security_group_rule" "ingress_bacalhau" {
type = "ingress"
from_port = 54545
to_port = 54545
protocol = "-1"
self = true
security_group_id = aws_security_group.allow_ssh_and_bacalhau.id
}
SSH 工作正常 - 包括机器之间的内部流量,但没有显示 bacalhau (54545) 服务。
例如
ubuntu@ip-10-0-1-219:~$ nmap ec2-18-202-245-138.eu-west-1.compute.amazonaws.com
Starting Nmap 7.80 ( https://nmap.org ) at 2022-03-19 18:07 UTC
Nmap scan report for ec2-18-202-245-138.eu-west-1.compute.amazonaws.com (10.0.1.237)
Host is up (0.0022s latency).
rDNS record for 10.0.1.237: ip-10-0-1-237.eu-west-1.compute.internal
Not shown: 999 closed ports
PORT STATE SERVICE
22/tcp open ssh
Nmap done: 1 IP address (1 host up) scanned in 0.08 seconds
ubuntu@ip-10-0-1-219:~$
编辑nmap 从安全组内的虚拟机运行。
难道我做错了什么? 这是安全组、vpc 还是 ec2 的错误? 我可以通过本地主机环回从节点本身访问服务。
编辑 2确认这是一个安全组问题 - 我打开了接受来自任何地方 [0.0.0.0/0] 的入站并且它工作正常。
对于ingress_bacalhau
安全组规则,您已设置参数self = true
。 这将只允许来自另一个实例的流量,该实例也附加了allow_ssh_and_bacalhau
安全组。
相反,对于具有ingress_ssh
规则的 SSH,您允许来自整个 inte.net 的流量( cidr_blocks = ["0.0.0.0/0"]
)
您没有明确指定从哪个实例执行了nmap
扫描。 如果此实例没有附加allow_ssh_and_bacalhau
安全组,则不允许来自它的流量。
声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.