-
Notifications
You must be signed in to change notification settings - Fork 0
feat: 모니터링 시스템 인프라 구성 #14
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
base: main
Are you sure you want to change the base?
Conversation
feat: s3 default, upload bucket을 테라폼으로 관리하도록 상태 추가
- monitoring_stack 추가 - nginx 설정 추가 - secret 작성
📋 Walkthrough이 변경사항은 모니터링 스택 모듈을 새롭게 도입하는 인프라 업데이트입니다. monitoring_stack 모듈에 EC2 인스턴스, 보안 그룹, 클라우드 초기화 설정을 추가하고, Nginx 및 Let's Encrypt SSL 설정을 위한 스크립트 템플릿을 포함합니다. environment/monitoring 환경에서 이 모듈을 사용하기 위해 필수 변수들을 정의하고, 기존 app_stack 모듈의 Docker 설정 스크립트 경로를 공통 경로로 업데이트합니다. 또한 config/secrets 서브모듈 참조를 업데이트합니다. 🎯 Estimated code review effort🎯 3 (Moderate) | ⏱️ ~20 minutes Pre-merge checks and finishing touches❌ Failed checks (1 warning)
✅ Passed checks (4 passed)
✨ Finishing touches🧪 Generate unit tests (beta)
Thanks for using CodeRabbit! It's free for OSS, and your support helps us grow. If you like it, consider giving us a shout-out. Comment |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Actionable comments posted: 2
🧹 Nitpick comments (3)
modules/monitoring_stack/ec2.tf (1)
1-1: 데이터 소스 이름을 명확하게 변경 권장
app_init이라는 이름은 모니터링 스택 컨텍스트에서 혼란을 줄 수 있습니다.monitoring_init으로 변경하는 것이 가독성에 도움이 됩니다.🔎 제안하는 수정
-data "cloudinit_config" "app_init" { +data "cloudinit_config" "monitoring_init" { gzip = true base64_encode = true그리고 line 39도 함께 수정:
- user_data_base64 = data.cloudinit_config.app_init.rendered + user_data_base64 = data.cloudinit_config.monitoring_init.renderedenvironment/monitoring/main.tf (1)
1-4: 프로덕션 환경에서 기본 VPC 사용 검토 필요기본 VPC는 보통 모든 서브넷이 public이고 보안 설정이 느슨합니다. 프로덕션 모니터링 시스템이라면 별도의 VPC를 생성하고 private 서브넷에 배포하는 것을 권장합니다.
현재 환경이 개발/테스트용이라면 문제없지만, 프로덕션이라면 보안을 위해 전용 VPC 사용을 고려하세요.
modules/monitoring_stack/scripts/nginx_setup.sh.tftpl (1)
1-77: Nginx + SSL 설정 스크립트 전반적으로 우수함스크립트가 잘 구성되어 있습니다:
set -e로 에러 처리 적절- Certbot standalone 모드 전 nginx 중지 (올바른 순서)
- TLSv1.2/1.3 사용으로 보안성 확보
- 자동 갱신 cron job 설정
선택적 개선: 인증서 중복 발급 방지
Let's Encrypt에는 rate limit이 있으므로, 이미 인증서가 존재하는지 확인하는 로직을 추가하면 재실행 시 안전합니다:
# 3. SSL 인증서 발급 (이미 존재하면 스킵) if [ ! -d "/etc/letsencrypt/live/$DOMAIN" ]; then sudo systemctl stop nginx sudo certbot certonly --standalone \ --non-interactive \ --agree-tos \ --email "$EMAIL" \ -d "$DOMAIN" else echo "Certificate for $DOMAIN already exists, skipping..." fi이는 스크립트 재실행 시 안전장치가 됩니다.
📜 Review details
Configuration used: Repository UI
Review profile: CHILL
Plan: Pro
📒 Files selected for processing (10)
config/secretsenvironment/monitoring/main.tfenvironment/monitoring/variables.tfmodules/app_stack/ec2.tfmodules/common/scripts/docker_setup.shmodules/monitoring_stack/ec2.tfmodules/monitoring_stack/output.tfmodules/monitoring_stack/scripts/nginx_setup.sh.tftplmodules/monitoring_stack/security_groups.tfmodules/monitoring_stack/variables.tf
🧰 Additional context used
🪛 Checkov (3.2.334)
modules/monitoring_stack/ec2.tf
[medium] 30-56: Ensure that detailed monitoring is enabled for EC2 instances
(CKV_AWS_126)
[high] 30-56: EC2 instance should not have public IP.
(CKV_AWS_88)
[high] 30-56: Ensure Instance Metadata Service Version 1 is not enabled
(CKV_AWS_79)
🔇 Additional comments (8)
modules/monitoring_stack/output.tf (1)
1-7: LGTM!모니터링 인스턴스의 Public IP와 보안 그룹 ID를 적절히 노출하고 있습니다.
modules/monitoring_stack/security_groups.tf (1)
1-27: LGTM!동적 ingress 규칙을 사용하여 유연한 보안 그룹 구성이 가능하도록 잘 구현되어 있습니다. Egress 규칙은 모든 아웃바운드를 허용하는 일반적인 패턴을 따르고 있습니다.
modules/monitoring_stack/ec2.tf (2)
12-27: Nginx 설정 스크립트가 자동 실행되지 않음 - 의도 확인 필요Part 2는
text/cloud-config타입으로/home/ubuntu/setup_nginx.sh파일만 생성하고 실행하지 않습니다. 이것이 수동 실행을 위한 의도적인 설계인지 확인이 필요합니다. 만약 자동 실행이 필요하다면 Part 1처럼text/x-shellscript타입으로 변경해야 합니다.수동 실행이 의도된 것이 맞나요? 인스턴스 생성 후 수동으로
/home/ubuntu/setup_nginx.sh를 실행해야 SSL이 설정됩니다.
30-56: 보안 강화 권장사항 검토Static analysis 도구가 다음 보안 이슈들을 감지했습니다:
- Public IP 노출 (line 35): 모니터링 인프라가 공개 IP를 가지면 공격 표면이 증가합니다. VPN이나 bastion host를 통한 접근을 고려하세요.
- IMDSv2 미적용 (high): Instance Metadata Service v1이 활성화되어 있으면 SSRF 공격에 취약할 수 있습니다.
- 상세 모니터링 비활성화 (medium): CloudWatch 상세 모니터링이 비활성화되어 있습니다.
프로덕션 환경이라면 보안 강화를 권장합니다.
🔎 IMDSv2 강제 및 상세 모니터링 활성화 제안
resource "aws_instance" "monitoring_server" { ami = var.ami_id instance_type = var.instance_type key_name = var.key_name associate_public_ip_address = true vpc_security_group_ids = [aws_security_group.monitoring_sg.id] user_data_base64 = data.cloudinit_config.app_init.rendered user_data_replace_on_change = false private_ip = var.private_ip + + # Enable detailed CloudWatch monitoring + monitoring = true + + # Enforce IMDSv2 for better security + metadata_options { + http_endpoint = "enabled" + http_tokens = "required" + http_put_response_hop_limit = 1 + } tags = { Name = "solid-connection-monitoring" }Public IP 노출이 필요한 경우인지 아키텍처를 재검토해 주세요.
environment/monitoring/main.tf (1)
6-29: LGTM!모니터링 스택 모듈에 필요한 모든 입력값이 적절히 전달되고 있습니다.
environment/monitoring/variables.tf (1)
1-51: 변수 정의 적절함모니터링 환경에 필요한 모든 변수가 명확한 설명과 함께 적절한 타입으로 정의되어 있습니다.
modules/monitoring_stack/variables.tf (1)
1-56: LGTM!모니터링 스택 모듈에 필요한 모든 변수가 명확한 설명과 함께 적절히 정의되어 있습니다. 타입 정의도 정확하고, 특히
monitoring_ingress_rules의 객체 구조가 명확하여 사용하기 좋습니다.modules/app_stack/ec2.tf (1)
9-9: 공통 스크립트 경로로 리팩터링이 올바르게 완료됨Docker 설치 스크립트를 공통 경로로 이동하여 코드 중복을 제거한 점이 좋습니다.
modules/common/scripts/docker_setup.sh파일이 정상적으로 존재하며, 상대 경로${path.module}/../common/scripts/docker_setup.sh가 올바르게 해석됩니다.
| @@ -1 +1 @@ | |||
| Subproject commit c1cf69a9de6f6b766750395875cd5bdcb16a0e96 | |||
| Subproject commit 03c90ed5b009df392bf7a3b086f2bdb3242f7adc | |||
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
🧩 Analysis chain
🏁 Script executed:
# 1. .gitmodules 파일 확인 - config/secrets가 서브모듈인지 확인
echo "=== .gitmodules 내용 확인 ==="
if [ -f .gitmodules ]; then
cat .gitmodules
else
echo ".gitmodules 파일 없음"
fi
# 2. config/secrets 디렉토리 상태 확인
echo -e "\n=== config/secrets 상태 확인 ==="
if [ -d config/secrets ]; then
cd config/secrets
git log --oneline -5 2>/dev/null || echo "Git history unavailable"
cd - > /dev/null
else
echo "config/secrets 디렉토리 없음"
fi
# 3. git 상태에서 config/secrets 정보 확인
echo -e "\n=== Git status에서 config/secrets 정보 ==="
git ls-files --stage | grep config/secrets || echo "No submodule info found"
# 4. 최근 커밋에서 config/secrets 변경 확인
echo -e "\n=== 최근 커밋에서 config/secrets 변경 ==="
git diff HEAD~1 HEAD -- config/secrets 2>/dev/null || git show HEAD:config/secrets 2>/dev/null || echo "Unable to show config/secrets diff"Repository: solid-connection/solid-connection-infra
Length of output: 486
🏁 Script executed:
# 1. config/secrets의 git 로그 확인 - 이전 커밋 해시 검증
echo "=== config/secrets git 로그 확인 (최근 5개) ==="
git log --oneline --all -- config/secrets | head -10
# 2. 현재 HEAD의 이전 커밋에서 config/secrets 커밋 확인
echo -e "\n=== 이전 커밋에서의 config/secrets 상태 ==="
git show HEAD~1:config/secrets 2>/dev/null || echo "Cannot show previous commit state"
# 3. 서브모듈 초기화 및 내용 확인
echo -e "\n=== 서브모듈 내 파일 목록 ==="
if [ -d config/secrets ]; then
cd config/secrets
find . -type f -name "*.yaml" -o -name "*.yml" -o -name "*.json" -o -name "*.env*" -o -name "*.conf" | head -20
cd - > /dev/null
fi
# 4. 커밋 범위에서 변경된 파일 (from vs to)
echo -e "\n=== 커밋 간 변경 파일 확인 ==="
git log --oneline --all -- config/secrets | head -3
</parameter>Repository: solid-connection/solid-connection-infra
Length of output: 555
🏁 Script executed:
# 1. 서브모듈 변경을 git diff로 확인
echo "=== Git diff로 submodule 변경 확인 ==="
git diff HEAD~1 HEAD config/secrets
# 2. 현재 HEAD의 config/secrets 상태
echo -e "\n=== 현재 HEAD config/secrets 상태 ==="
git show HEAD:config/secrets
# 3. 전체 commit 로그에서 c1cf69a 해시 검색
echo -e "\n=== 커밋 로그에서 c1cf69a 검색 ==="
git log --all --grep="c1cf69a" --oneline 2>/dev/null || git log --all --oneline | grep "c1cf69a" || echo "Hash not found in logs"
# 4. config/secrets 에 대한 모든 commit 확인
echo -e "\n=== config/secrets 관련 모든 커밋 ==="
git log --all --oneline -- config/secretsRepository: solid-connection/solid-connection-infra
Length of output: 684
🏁 Script executed:
# 1. 현재 저장소 상태 확인
echo "=== 현재 브랜치 및 상태 ==="
git status
git branch -a | head -10
# 2. PR 또는 HEAD 정보 확인
echo -e "\n=== 최근 커밋 정보 ==="
git log -1 --oneline
git log -1 --format="%H %s"
# 3. config/secrets 서브모듈의 실제 참조 정보
echo -e "\n=== Git config에서 submodule 정보 ==="
git config --file .gitmodules --get-regexp config/secrets
# 4. 저장소의 index에서 config/secrets 정보
echo -e "\n=== Index에서 config/secrets 정보 ==="
git ls-files --stage -- config/secrets
# 5. 서브모듈 원격 저장소 URL 확인
echo -e "\n=== 서브모듈 원격 URL 접근 가능 확인 ==="
SUBMODULE_URL=$(git config --file .gitmodules --get submodule.config/secrets.url)
echo "Submodule URL: $SUBMODULE_URL"
git ls-remote "$SUBMODULE_URL" 2>&1 | head -10 || echo "Remote access failed"Repository: solid-connection/solid-connection-infra
Length of output: 946
서브모듈 저장소에 접근할 수 없습니다.
https://github.com/solid-connection/solid-connection-infra-secret.git 저장소가 없거나 접근 불가 상태입니다. 이 상태에서는 다른 개발자들이 저장소를 클론할 수 없으므로 이 문제를 먼저 해결해야 합니다. 서브모듈 저장소가 존재하는지, 올바른 URL인지, 접근 권한이 있는지 확인해주세요.
🤖 Prompt for AI Agents
In config/secrets around lines 1 to 1, the submodule URL
https://github.com/solid-connection/solid-connection-infra-secret.git is missing
or inaccessible; verify the repository exists and the URL is correct, then
update the submodule reference accordingly (edit .gitmodules or config/secrets
entry to the correct URL or SSH form), ensure the CI/developers have access
(public repo, correct org membership, or use a personal access token/SSH key),
run git submodule sync && git submodule update --init --recursive to validate,
and commit the corrected submodule configuration.
| variable "ebs_volume_size" { | ||
| description = "Disk size for Prometheus TSDB (GB)" | ||
| type = number | ||
| default = 50 | ||
| } |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
🧩 Analysis chain
🏁 Script executed:
#!/bin/bash
# First, let's explore the repository structure
echo "=== Repository structure ==="
git ls-files | head -20
echo -e "\n=== Check if modules/monitoring_stack exists ==="
find . -type d -name "monitoring_stack" 2>/dev/null
echo -e "\n=== List files in monitoring_stack directory ==="
find . -path "*/monitoring_stack/*" -type f 2>/dev/null | head -20Repository: solid-connection/solid-connection-infra
Length of output: 1014
🏁 Script executed:
#!/bin/bash
# Search for ebs_volume_size usage across the entire repository
echo "=== Searching for ebs_volume_size usage ==="
rg -n "ebs_volume_size" --type tf
echo -e "\n=== Also search in all files (not just .tf) ==="
rg -n "ebs_volume_size"Repository: solid-connection/solid-connection-infra
Length of output: 311
🏁 Script executed:
#!/bin/bash
# Check the specific ec2.tf file in monitoring_stack
echo "=== Looking for ec2.tf files ==="
fd "ec2.tf"
echo -e "\n=== Content of monitoring_stack ec2.tf (if exists) ==="
if find . -path "*/monitoring_stack/ec2.tf" -type f 2>/dev/null | grep -q "ec2.tf"; then
cat "$(find . -path '*/monitoring_stack/ec2.tf' -type f 2>/dev/null | head -1)"
fiRepository: solid-connection/solid-connection-infra
Length of output: 1494
미사용 변수 제거 필요
ebs_volume_size 변수가 정의되어 있지만 코드베이스 어디에서도 사용되지 않습니다. modules/monitoring_stack/ec2.tf의 aws_instance.monitoring_server 리소스에서 이 변수가 참조되지 않고 있으며 ebs_block_device 블록도 없습니다. 변수를 제거하거나, 향후 사용할 계획이 있다면 EC2 리소스에 EBS 볼륨 구성을 추가하세요.
🤖 Prompt for AI Agents
In environment/monitoring/variables.tf around lines 32 to 36, the variable
`ebs_volume_size` is defined but unused; either remove this variable definition
to avoid dead configuration, or wire it into modules/monitoring_stack/ec2.tf by
adding an `ebs_block_device` (or `root_block_device` modification) on
`aws_instance.monitoring_server` that references var.ebs_volume_size and
updating any module input variables accordingly so the EC2 resource actually
uses the defined size.
관련 이슈
작업 내용
특이 사항
리뷰 요구사항 (선택)