[英]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.