From ad8f41eb82ae688648bab40fe02bb98a83d4bb08 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?=EC=A1=B0=EC=9E=AC=EC=A4=91?= <126754298+m-a-king@users.noreply.github.com> Date: Thu, 15 Oct 2026 07:16:25 +0900 Subject: [PATCH] =?UTF-8?q?infra:=20dev=20=EC=95=B1=20=EC=84=9C=EB=B2=84?= =?UTF-8?q?=20=EB=B3=B4=EC=95=88=20=EA=B7=B8=EB=A3=B9=20=EB=B6=84=EB=A6=AC?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit - dev 전용 보안 그룹 piki-dev-app-sg 를 만들고 piki-dev-app 을 옮김 - 입구는 prod 와 같은 80·443, 나가는 방향 전체 - prod 앱 서버·prod DB 보안 그룹은 그대로 - 결과: prod DB 의 MySQL·Redis 인바운드가 prod 앱 서버에서만 닿음 - 이전: 같은 그룹을 쓰는 dev 앱 서버도 닿음 - 원인: dev 는 자기 서버의 MySQL·Redis 를 씀 (SSM db-host·redis-host 172.17.0.1). prod DB 연결이 필요 없음 - dev 를 옮기고 prod 를 남김 - 대안: prod 전용 그룹을 새로 만들고 prod 를 옮김 - 기각: prod DB·extractor·renderer 참조를 함께 바꿔야 하고 순서가 어긋나면 prod 가 끊김 - 비용: prod 그룹 이름의 team3-dev 는 옛 이름 그대로 --- terraform/db_ec2.tf | 2 +- terraform/ec2.tf | 4 ++-- terraform/security_groups.tf | 42 +++++++++++++++++++++++++++++++++++- 3 files changed, 44 insertions(+), 4 deletions(-) diff --git a/terraform/db_ec2.tf b/terraform/db_ec2.tf index 0516a3f6..7e7aec0a 100644 --- a/terraform/db_ec2.tf +++ b/terraform/db_ec2.tf @@ -18,7 +18,7 @@ # ----------------------------------------------------------------------------- # DB 박스 Security Group # -# 3306(MySQL)·6379(Redis) 는 앱 EC2 SG(prod·dev 앱 박스 공용) 에서만 받는다(폐기된 RDS SG 가 지키던 것과 같은 규율) — DB 를 +# 3306(MySQL)·6379(Redis) 는 prod 앱 EC2 SG 에서만 받는다(폐기된 RDS SG 가 지키던 것과 같은 규율) — DB 를 # 인터넷에 직접 노출하지 않는다. SSH 는 SSM 경유라 22 번이 없다(#1196). # # egress 는 열어 둔다. RDS 와 달리 이 박스는 스스로 바깥에 나가야 한다 — SSM 에서 DB 자격증명을 diff --git a/terraform/ec2.tf b/terraform/ec2.tf index f91a2543..a17cd0be 100644 --- a/terraform/ec2.tf +++ b/terraform/ec2.tf @@ -97,14 +97,14 @@ resource "aws_instance" "app" { # ----------------------------------------------------------------------------- # 개발(dev) EC2 — 신규 인스턴스. -# 동일 VPC/서브넷/SG 를 공유하며, 별도 EIP 와 도메인(dev.*)으로 분리. +# 동일 VPC/서브넷을 쓰고, SG·EIP·도메인(dev.*)은 분리. # ----------------------------------------------------------------------------- resource "aws_instance" "dev_app" { ami = var.ec2_ami_id != null ? var.ec2_ami_id : data.aws_ami.ubuntu_2404_arm64[0].id instance_type = var.ec2_instance_type_dev subnet_id = aws_subnet.public.id availability_zone = var.azs[0] - vpc_security_group_ids = [aws_security_group.ec2.id] + vpc_security_group_ids = [aws_security_group.dev_app.id] # dev 전용 키페어 — prod(team3-SE-1)와 분리해 dev 키 유출이 prod 접근으로 번지지 않게 한다. # AWS 콘솔에서 미리 생성(.pem 다운로드)해 두고 이름으로 참조. 개인키는 dev env EC2_SSH_KEY 로 주입. key_name = "team3-dev-SE-1" diff --git a/terraform/security_groups.tf b/terraform/security_groups.tf index 11222d42..ccd567a1 100644 --- a/terraform/security_groups.tf +++ b/terraform/security_groups.tf @@ -1,5 +1,6 @@ # ----------------------------------------------------------------------------- -# EC2 Security Group — HTTP(80) + HTTPS(443). SSH 는 SSM 경유라 22 번이 없다(#1196). +# prod 앱 EC2 Security Group — HTTP(80) + HTTPS(443). SSH 는 SSM 경유라 22 번이 없다(#1196). +# 이름의 team3-dev 는 옛 이름이다. 바꾸면 SG 가 새로 만들어져 prod DB·extractor·renderer 의 참조가 함께 바뀌어야 한다. # # 앱 포트는 외부에 노출하지 않는다. 박스의 nginx 가 TLS 를 종료하고 127.0.0.1 에 바인딩된 # blue·green 슬롯으로 forward 한다(포트 정본: TeamPiKi/infra contracts/ports.json). @@ -44,5 +45,44 @@ resource "aws_security_group" "ec2" { } } +# ----------------------------------------------------------------------------- +# dev 앱 EC2 Security Group — prod 앱 SG 와 같은 입구(80·443)를 갖되 그룹을 나눈다. +# prod DB SG 는 prod 앱 SG 만 참조하므로, 그룹을 나눈 것만으로 dev 박스에서 prod DB 로 가는 길이 닫힌다(#1213). +# dev 는 자기 박스의 MySQL·Redis 를 쓴다. 이 그룹을 참조하는 쪽은 extractor 인바운드뿐이다. +# ----------------------------------------------------------------------------- +resource "aws_security_group" "dev_app" { + name = "piki-dev-app-sg" + description = "dev app EC2: HTTP/HTTPS in, all out" + vpc_id = aws_vpc.main.id + + ingress { + description = "HTTP (redirect to HTTPS at reverse proxy layer)" + from_port = 80 + to_port = 80 + protocol = "tcp" + cidr_blocks = ["0.0.0.0/0"] + } + + ingress { + description = "HTTPS" + from_port = 443 + to_port = 443 + protocol = "tcp" + cidr_blocks = ["0.0.0.0/0"] + } + + egress { + description = "Allow all outbound" + from_port = 0 + to_port = 0 + protocol = "-1" + cidr_blocks = ["0.0.0.0/0"] + } + + tags = { + Name = "piki-dev-app-sg" + } +} + # RDS Security Group 은 #898 로 RDS 자체를 폐기하면서 함께 제거했다. # 그 자리를 대신하는 것은 db_ec2.tf 의 aws_security_group.db_ec2 다.