aws-cdk: aws_ecr_assets: produces invalid tasks by linking to empty "attestation" image layer

Describe the bug

I started getting the following error when trying to run my Fargate tasks:

“StoppedReason”: “CannotPullContainerError: ref pull has been retried 1 time(s): failed to unpack image on snapshotter overlayfs: failed to extract layer sha256:c02342326b04a05fa0fc4c703c4aaa8ffb46cc0f2eda269c4a0dee53c8296182: failed to get stream processor for application/vnd.in-toto+json: no processor for media-type: unknown”

If I go into AWS web ui to the task definition I can find the id of the ECR image that it points to

Then if I look at that ECR image I can see it has 0 size:

Screenshot 2024-05-17 at 17 12 22

I can see in my ECR images list that since 10 May every CDK deployment has pushed a zero size image to ECR instead of the expected one: Screenshot 2024-05-17 at 17 14 48

I have the following CDK code:

        django_command_img = ecr_assets.DockerImageAsset(
            self,
            "Django Command Image",
            directory="./",
            target="fargate-task",
            build_args={
                "python_version": global_task_config.python_version,
            },
            platform=ecr_assets.Platform.LINUX_ARM64
            if is_arm64
            else ecr_assets.Platform.LINUX_AMD64,
        )

        _task = ecs.FargateTaskDefinition(
            self,
            "Django Command Task",
            cpu=config.cpu,
            memory_limit_mib=config.memory_size,
            runtime_platform=ecs.RuntimePlatform(
                cpu_architecture=ecs.CpuArchitecture.ARM64
                if is_arm64
                else ecs.CpuArchitecture.X86_64,
                operating_system_family=ecs.OperatingSystemFamily.LINUX,
            ),
            family=f"{resource_prefix}-task-django-command",
        )
        container_name = f"{resource_prefix}-container-django-command"
        _task.add_container(
            "Django Command Container",
            image=ecs.ContainerImage.from_docker_image_asset(django_command_img),
            container_name=container_name,
            environment={
                "ETL": "true",
                **common_django_env,
            },
            # health_check=ecs.HealthCheck(),
            logging=ecs.LogDrivers.aws_logs(
                stream_prefix="containers",
                log_group=log_group,
            ),
        )

(Before 10 May I had previously deployed and ran Fargate tasks successfully from this definition)

Expected Behavior

A usable ECS task definition is deployed

Current Behavior

Inscrutable error message

It appears that CDK has created the task definition against an invalid ECR image

Reproduction Steps

See above

Additional Information/Context

I have located what seems to be the cause, with help from this issue thread: https://github.com/moby/moby/issues/45600

Using aws ecr batch-get-image I can see the following manifest in my problem zero sized image:

{
  "schemaVersion": 2,
  "mediaType": "application/vnd.oci.image.manifest.v1+json",
  "config": {
    "mediaType": "application/vnd.oci.image.config.v1+json",
    "digest": "sha256:1b22b41bc8846dc11d2718b173aa7481e06fe4e3893b410032e02f858da7d165",
    "size": 167
  },
  "layers": [
    {
      "mediaType": "application/vnd.in-toto+json",
      "digest": "sha256:875402577bcf06a0681056a91feeb0ce68f41fa30ad735ae802e555f1519351d",
      "size": 1464,
      "annotations": {
        "in-toto.io/predicate-type": "https://slsa.dev/provenance/v0.2"
      }
    }
  ]
}

This seems to relate to the error message and fit with the details in the moby issue linked above.

Basically when cdk deploy builds the image locally (via docker buildx) then extra “attestation” items are added to the root manifest (???)

I guess by themselves these aren’t harmful (they are part of OCI standard or whatever) but CDK is maybe not expecting them and ends up pushing and tagging the wrong thing into ECR

Possible Solution

BUILDX_NO_DEFAULT_ATTESTATIONS=1 cdk deploy worked for me (after adding an arbitrary change to my Dockerfile to force a rebuild)

I think it would be better if CDK explicitly adds --provenance=false in its calls to docker buildx

See https://docs.docker.com/reference/cli/docker/buildx/build/#provenance and https://docs.docker.com/build/attestations/attestation-storage/

CDK CLI Version

2.142.0 (build 289a1e3)

Framework Version

No response

Node.js Version

v18.18.0

OS

macOS 14.4.1

Language

Python

Language Version

3.11.5

Other information

No response

About this issue

  • Original URL
  • State: closed
  • Created 3 years ago
  • Reactions: 13
  • Comments: 15 (6 by maintainers)

Commits related to this issue

Most upvoted comments

I successfully reproduced it on my Mac M1 by the following steps:

  1. Use Docker Desktop
  2. Enable DockerDesktop setting -> General -> Use containerd for pulling and storing images
  3. Deploy a container image from CDK

According to the doc, the containerd settings are enabled by default nowadays on clean install of Docker Desktop, so there will be more and more people facing the issue.

The containerd image store is enabled by default in Docker Desktop version 4.34 and later, but only for clean installs or if you perform a factory reset. If you upgrade from an earlier version of Docker Desktop, or if you use an older version of Docker Desktop you must manually switch to the containerd image store.

Related issue: #31549