Skip to content

Include IPv6 addresses in task and container metadata v4 responses for bridge mode#4581

Merged
amogh09 merged 1 commit intoaws:devfrom
amogh09:ipv6-tmds-container-metadata
Apr 18, 2025
Merged

Include IPv6 addresses in task and container metadata v4 responses for bridge mode#4581
amogh09 merged 1 commit intoaws:devfrom
amogh09:ipv6-tmds-container-metadata

Conversation

@amogh09
Copy link
Copy Markdown
Contributor

@amogh09 amogh09 commented Apr 18, 2025

Summary

This change makes container and task metadata v4 responses include IPv6 container addresses for bridge mode tasks. IPv6 addresses are already included for awsvpc mode tasks. This change extends that functionality to bridge mode tasks as we prepare for IPv6-only support.

Testing

New tests cover the changes: yes

Ran a bridge mode task on an instance with IPv6 enabled on the bridge network and observed the response of TMDS v4 container metadata endpoint.

$ docker exec c4d296f8cc07 sh -c 'curl -s $ECS_CONTAINER_METADATA_URI_V4' | jq '.'
{
  "DockerId": "c4d296f8cc072dc324d8d5f03a8efb8ac67b2c9bbf424917bf077c8b4a8337fc",
  "Name": "al",
  "DockerName": "ecs-myamazonlinux-6-al-b0def3e7f1cd889c9401",
  "Image": "REDACTED.dkr.ecr.us-west-2.amazonaws.com/myamazonlinux:latest",
  "ImageID": "sha256:04272a0ef08164bb5174f827f628b678c8e161c9d8494cfce1a8453e8b4a9f3f",
  "Labels": {
    "com.amazonaws.ecs.cluster": "sc-test",
    "com.amazonaws.ecs.container-name": "al",
    "com.amazonaws.ecs.task-arn": "arn:aws:ecs:us-west-2:REDACTED:task/sc-test/86c6c13a6b6b48489caaaa9cdf7a9533",
    "com.amazonaws.ecs.task-definition-family": "myamazonlinux",
    "com.amazonaws.ecs.task-definition-version": "6"
  },
  "DesiredStatus": "RUNNING",
  "KnownStatus": "RUNNING",
  "Limits": {
    "CPU": 2,
    "Memory": 50
  },
  "CreatedAt": "2025-04-18T19:20:07.667231431Z",
  "StartedAt": "2025-04-18T19:20:08.299773401Z",
  "Type": "NORMAL",
  "ContainerARN": "arn:aws:ecs:us-west-2:REDACTED:container/sc-test/86c6c13a6b6b48489caaaa9cdf7a9533/f8e2a653-983d-4e93-a1e7-6995c4d5e76a",
  "Networks": [
    {
      "NetworkMode": "bridge",
      "IPv4Addresses": [
        "172.17.0.2"
      ],
      "IPv6Addresses": [
        "2001:db8:1::242:ac11:2"
      ]
    }
  ]
}

Did the same for v4 task metadata -

ipv6dev ❱ docker exec c4d296f8cc07 sh -c 'curl -s $ECS_CONTAINER_METADATA_URI_V4/task' | jq '.'
{
  "Cluster": "sc-test",
  "TaskARN": "arn:aws:ecs:us-west-2:979604884904:task/sc-test/86c6c13a6b6b48489caaaa9cdf7a9533",
  "Family": "myamazonlinux",
  "Revision": "6",
  "DesiredStatus": "RUNNING",
  "KnownStatus": "RUNNING",
  "PullStartedAt": "2025-04-18T19:20:07.5571128Z",
  "PullStoppedAt": "2025-04-18T19:20:07.652753773Z",
  "AvailabilityZone": "us-west-2a",
  "LaunchType": "EC2",
  "Containers": [
    {
      "DockerId": "c4d296f8cc072dc324d8d5f03a8efb8ac67b2c9bbf424917bf077c8b4a8337fc",
      "Name": "al",
      "DockerName": "ecs-myamazonlinux-6-al-b0def3e7f1cd889c9401",
      "Image": "979604884904.dkr.ecr.us-west-2.amazonaws.com/myamazonlinux:latest",
      "ImageID": "sha256:04272a0ef08164bb5174f827f628b678c8e161c9d8494cfce1a8453e8b4a9f3f",
      "Labels": {
        "com.amazonaws.ecs.cluster": "sc-test",
        "com.amazonaws.ecs.container-name": "al",
        "com.amazonaws.ecs.task-arn": "arn:aws:ecs:us-west-2:979604884904:task/sc-test/86c6c13a6b6b48489caaaa9cdf7a9533",
        "com.amazonaws.ecs.task-definition-family": "myamazonlinux",
        "com.amazonaws.ecs.task-definition-version": "6"
      },
      "DesiredStatus": "RUNNING",
      "KnownStatus": "RUNNING",
      "Limits": {
        "CPU": 2,
        "Memory": 50
      },
      "CreatedAt": "2025-04-18T19:20:07.667231431Z",
      "StartedAt": "2025-04-18T19:20:08.299773401Z",
      "Type": "NORMAL",
      "ContainerARN": "arn:aws:ecs:us-west-2:979604884904:container/sc-test/86c6c13a6b6b48489caaaa9cdf7a9533/f8e2a653-983d-4e93-a1e7-6995c4d5e76a",
      "Networks": [
        {
          "NetworkMode": "bridge",
          "IPv4Addresses": [
            "172.17.0.2"
          ],
          "IPv6Addresses": [
            "2001:db8:1::242:ac11:2"
          ]
        }
      ]
    }
  ],
  "VPCID": "vpc-00808932ec3144058",
  "FaultInjectionEnabled": false
}

Also verified that v3 metadata endpoints do not return IPv6 addresses. Note that v2 metadata endpoints are not supported for bridge mode tasks.

ipv6dev ❱ docker exec c4d296f8cc07 sh -c 'curl -s $ECS_CONTAINER_METADATA_URI' | jq '.'
{
  "DockerId": "c4d296f8cc072dc324d8d5f03a8efb8ac67b2c9bbf424917bf077c8b4a8337fc",
  "Name": "al",
  "DockerName": "ecs-myamazonlinux-6-al-b0def3e7f1cd889c9401",
  "Image": "979604884904.dkr.ecr.us-west-2.amazonaws.com/myamazonlinux:latest",
  "ImageID": "sha256:04272a0ef08164bb5174f827f628b678c8e161c9d8494cfce1a8453e8b4a9f3f",
  "Labels": {
    "com.amazonaws.ecs.cluster": "sc-test",
    "com.amazonaws.ecs.container-name": "al",
    "com.amazonaws.ecs.task-arn": "arn:aws:ecs:us-west-2:979604884904:task/sc-test/86c6c13a6b6b48489caaaa9cdf7a9533",
    "com.amazonaws.ecs.task-definition-family": "myamazonlinux",
    "com.amazonaws.ecs.task-definition-version": "6"
  },
  "DesiredStatus": "RUNNING",
  "KnownStatus": "RUNNING",
  "Limits": {
    "CPU": 2,
    "Memory": 50
  },
  "CreatedAt": "2025-04-18T19:20:07.667231431Z",
  "StartedAt": "2025-04-18T19:20:08.299773401Z",
  "Type": "NORMAL",
  "Networks": [
    {
      "NetworkMode": "bridge",
      "IPv4Addresses": [
        "172.17.0.2"
      ]
    }
  ]
}

Also verified that v4 metadata response is unchanged for host network mode tasks as they do not have any container IP addresses.

Description for the changelog

Enhancement: Include container IPv6 addresses (if available) in container and task metadata v4 responses for bridge mode tasks.

Additional Information

Does this PR include breaking model changes? If so, Have you added transformation functions?

No

Does this PR include the addition of new environment variables in the README?

No

Licensing

By submitting this pull request, I confirm that my contribution is made under the terms of the Apache 2.0 license.

@amogh09 amogh09 changed the base branch from master to dev April 18, 2025 19:16
@amogh09 amogh09 changed the title Ipv6 tmds container metadata Include IPv6 addresses in task and container metadata v4 responses Apr 18, 2025
@amogh09 amogh09 changed the title Include IPv6 addresses in task and container metadata v4 responses Include IPv6 addresses in task and container metadata v4 responses for bridge mode Apr 18, 2025
@amogh09 amogh09 marked this pull request as ready for review April 18, 2025 19:33
@amogh09 amogh09 requested a review from a team as a code owner April 18, 2025 19:33
@amogh09 amogh09 force-pushed the ipv6-tmds-container-metadata branch from 4e8633c to 4526c7a Compare April 18, 2025 19:47
@amogh09 amogh09 enabled auto-merge (squash) April 18, 2025 22:47
Copy link
Copy Markdown
Contributor

@Yiyuanzzz Yiyuanzzz left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

lgtm

@amogh09 amogh09 merged commit e805e6b into aws:dev Apr 18, 2025
40 checks passed
timj-hh pushed a commit to timj-hh/amazon-ecs-agent that referenced this pull request Jul 19, 2025
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.

4 participants