Skip to content

chore(ec2): IMDSv2 강제로 IMDSv1 차단#5

Merged
yeounhyeok merged 1 commit into
devfrom
chore/imdsv2-required
Jun 5, 2026
Merged

chore(ec2): IMDSv2 강제로 IMDSv1 차단#5
yeounhyeok merged 1 commit into
devfrom
chore/imdsv2-required

Conversation

@yeounhyeok

Copy link
Copy Markdown
Contributor

개요

EC2 인스턴스 메타데이터 서비스를 IMDSv2(토큰 필수)로 강제합니다.

배경

런타임 점검 중 현재 dev 인스턴스에서 IMDSv1이 활성(토큰 없이 http://169.254.169.254/latest/meta-data/ 접근 가능)인 것을 확인했습니다. 앱에 SSRF 취약점이 하나라도 존재하면 IMDS를 통해 인스턴스에 연결된 IAM 역할(sw-hub-dev-app-role)의 임시 자격증명이 탈취될 수 있습니다.

변경 사항

  • aws_instancemetadata_options 추가
    • http_tokens = "required" — IMDSv2 강제(토큰 없는 IMDSv1 차단)
    • http_endpoint = "enabled", http_put_response_hop_limit = 1
  • hop_limit=1: 앱이 host 네트워크로 동작하므로 1홉이면 IMDS 접근에 충분

영향

  • 기존 인스턴스에 대해 in-place 업데이트(인스턴스 재생성 없음).
  • AWS SDK/CLI는 IMDSv2를 기본 지원하므로 앱 동작 영향 없음.

적용

  • terraform apply 로 반영. (또는 즉시 차단이 필요하면 아래 CLI 후 apply 시 drift 없음)
    aws ec2 modify-instance-metadata-options --instance-id i-0fa0e4a4342acb626 --http-tokens required --http-put-response-hop-limit 1
    

비고 (후속 참고)

  • 8080은 SG에 없어 외부 노출 아님(양호). 앱의 0.0.0.0:8080 바인딩을 127.0.0.1로 좁히는 건 앱(BE) 설정이며, cloudflared가 host 네트워크로 localhost:8080에 접속하므로 안전하게 적용 가능.
  • cloudflared 터널 토큰이 컨테이너 실행 인자로 노출되어 있음. 시크릿 파일/로테이션 고려 권장.

- 토큰 없는 IMDSv1 접근을 막아 SSRF를 통한 IAM 역할 임시 자격증명 탈취를 방지
- 앱이 host 네트워크로 동작하므로 hop_limit=1이면 IMDS 접근에 충분
@yeounhyeok yeounhyeok merged commit 6738327 into dev Jun 5, 2026
2 checks passed
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

1 participant