Help us improve the AWS re:Post Knowledge Center by sharing your feedback in a brief survey. Your input can influence how we create and update our content to better support your AWS journey.
EKS 환경에서 특정 컨테이너의 IMDS v1 통신 확인
IMDS v1 통신은 기본적으로 CloudWatch의 MetadataNoToken 메트릭을 통해 확인할 수 있지만, 컨테이너를 특정하기 어렵기 때문에 해당 문서에서는 특정 노드의 컨테이에서 IMDS v1 통신을 식별하는 방법을 설명합니다.
사용중인 EKS 노드를 IMDS v1에서 IMDS v2로의 전환을 계획하고 있을 때, EKS Pod에서 IMDS v1 호출을 식별하여 마이그레이션 대상 혹은 전환 후에 정상적으로 동작하는지 확인할 필요가 있을 수 있습니다. 기본적으로 EC2 인스턴스의 메트릭 지표 중 MetadataNoToken를 통해 인스턴스에서 IMDS v1을 사용하는지 여부를 확인할 수 있습니다.
EKS Pod에서 IMDS v1을 사용하게 될 때, 네트워크 흐름은 다음과 같습니다.
- EKS Pod Request metadata - http://169.254.169.254/latest/meta-data/
- EKS Node Request metadata - http://169.254.169.254/latest/meta-data
- EKS Node Request EC2 API - https://ec2.ap-northeast-2.amazonaws.com/
- External Traffic: EKS Node IP to EC2 API IP
해당 흐름은 아래와 같은 방법으로 확인할 수 있습니다.
1. Pod에서 IMDS v1을 통해 EC2의 메타데이터를 조회합니다.
$ curl http://169.254.169.254/latest/meta-data/
2. TCP Dump와 같은 도구로 노드에서 발생하는 패킷을 확인할 수 있습니다.
# Request Pod IMDS v1
02:31:01.494635 eni In IP (tos 0x0, ttl 127, id 41331, offset 0, flags [DF], proto TCP (6), length 148)
<Pod IP>.44604 > 169.254.169.254.80: Flags [P.], cksum 0xf9ad (incorrect -> 0xb6c3), seq 1:97, ack 1, win 502, options [nop,nop,TS val 1884111155 ecr 2087348021], length 96: HTTP, length: 96
GET /latest/meta-data/ HTTP/1.1
Host: 169.254.169.254
User-Agent: curl/8.14.1
Accept: */*
# Request Node IMDS v1
02:31:01.494644 ens5 Out IP (tos 0x0, ttl 126, id 41331, offset 0, flags [DF], proto TCP (6), length 148)
<Node IP>.43858 > 169.254.169.254.80: Flags [P.], cksum 0xf802 (incorrect -> 0xbb58), seq 1:97, ack 1, win 502, options [nop,nop,TS val 1884111155 ecr 2087348021], length 96: HTTP, length: 96
GET /latest/meta-data/ HTTP/1.1
Host: 169.254.169.254
User-Agent: curl/8.14.1
Accept: */*
# Response EC2 API to Node IP
02:31:01.495085 ens5 In IP (tos 0x0, ttl 255, id 0, offset 0, flags [DF], proto TCP (6), length 566)
169.254.169.254.80 > <Node IP>.43858: Flags [P.], cksum 0x8771 (correct), seq 1:515, ack 97, win 493, options [nop,nop,TS val 2087348021 ecr 1884111155], length 514: HTTP, length: 514
HTTP/1.1 200 OK
Content-Type: text/plain
Accept-Ranges: none
Last-Modified: Wed, 22 Oct 2025 02:00:51 GMT
Content-Length: 310
Date: Wed, 22 Oct 2025 02:31:01 GMT
Server: EC2ws
Connection: close
ami-id
ami-launch-index
ami-manifest-path
autoscaling/
block-device-mapping/
events/
hostname
iam/
identity-credentials/
instance-action
instance-id
instance-life-cycle
instance-type
local-hostname
local-ipv4
mac
metrics/
network/
placement/
profile
public-keys/
reservation-id
security-groups
services/
system
# Response EC2 API to Pod IP
02:31:01.495089 eni Out IP (tos 0x0, ttl 254, id 0, offset 0, flags [DF], proto TCP (6), length 566)
169.254.169.254.80 > <Pod IP>.44604: Flags [P.], cksum 0x82dc (correct), seq 1:515, ack 97, win 493, options [nop,nop,TS val 2087348021 ecr 1884111155], length 514: HTTP, length: 514
HTTP/1.1 200 OK
Content-Type: text/plain
Accept-Ranges: none
Last-Modified: Wed, 22 Oct 2025 02:00:51 GMT
Content-Length: 310
Date: Wed, 22 Oct 2025 02:31:01 GMT
Server: EC2ws
Connection: close
ami-id
ami-launch-index
ami-manifest-path
autoscaling/
block-device-mapping/
events/
hostname
iam/
identity-credentials/
instance-action
instance-id
instance-life-cycle
instance-type
local-hostname
local-ipv4
mac
metrics/
network/
placement/
profile
public-keys/
reservation-id
security-groups
services/
system
3. 이 때, CloudWatch의 해당 인스턴스의 MetadataNoToken 메트릭 Count가 1개 증가합니다.
4. 이 때, VPC Flow Log를 활성화 하였다면 아래의 통신 이력을 확인할 수 있습니다.
- Source IP: Node IP
- Destination IP: EC2 API IP (Public IP or VPCe IP)
위와 같이 Pod에서 IMDS v1 트래픽이 발생하였을 때, 해당 Pod를 식별하기 위해 aws-imds-packet-analyzer를 통해 Pod의 IMDS v1 통신 이력을 분석할 수 있습니다. OS별 설치 과정은 aws-imds-packet-analyzer Github 저장소에서 확인할 수 있으며, 다음과 같이 aws-imds-packet-analyzer를 활용할 수 있습니다.
1. AL2023에서 Git, BCC 도구를 설치합니다.
$ sudo dnf install bcc-tools
$ sudo yum install git
2. Git 저장소에서 코드를 Clone 합니다.
$ git clone https://github.com/aws/aws-imds-packet-analyzer.git
3. Root 권한으로 다음의 스크립트를 실행합니다.
$ cd aws-imds-packet-analyzer
$ sudo python3 src/imds_snoop.py
4. 실행 후 IMDS v1 호출을 할 경우에 아래의 출력 결과를 얻을 수 있습니다.
[2025-10-22 02:55:40,993] [WARNING] imdsv1(!) (pid:69745:curl argv:curl http://169.254.169.254/latest/meta-data/) called by -> (pid:11793:bash argv:/bin/bash) -> (pid:3436:containerd-shim argv:/usr/bin/containerd-shim-runc-v2 -namespace k8s.io -id b9241836f34d163ebab24a4b3e06ee452e05dff53b95b3333983894574618d70 -address /run/containerd/containerd.sock) -> (pid:1:systemd argv:/usr/lib/systemd/systemd --switched-root --system --deserialize=32) req details: get /latest/meta-data/ http/1.1, host: 169.254.169.254, user-agent: curl/8.14.1, accept: */*,
5. 출력된 결과에서 -id 정보를 토대로 Containerd의 Pod 정보를 확인합니다.
$ nerdctl inspect b9241836f34d163ebab24a4b3e06ee452e05dff53b95b3333983894574618d70
...
"io.kubernetes.pod.name": "<PodName>",
...
6. aws-imds-packet-analyzer를 노드의 백그라운드로 실행하실 경우, 다음과 같이 실행할 수 있습니다.
$ cd aws-imds-packet-analyzer
$ sudo bash activate-tracer-service.sh
# 서비스 실행 확인
$ systemctl status -l imds_tracer_tool.service
참고: 실행 중인 서비스의 로그는 /var/log/imds/ 하위에 저장됩니다.
고려 사항
노드에서 aws-imds-packet-analyzer를 실행할 경우에는 노드에 얘기치 못한 부하가 발생할 수 있기 때문에 성능에 영향을 줄 수 있습니다. 이 점을 유의하셔서 사용해야 합니다. 1차적으로 EC2 인스턴스의 MetadataNoToken 메트릭 지표를 통해 노드에서 IMDS v1 호출 여부를 확인하고 Pod를 식별하기 위해 aws-imds-packet-analyzer를 활용할 수 있습니다.
- 주제
- 컨테이너
- 언어
- 한국어
