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:
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:
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
- fix: Handle buildx output with BUILDX_NO_DEFAULT_ATTESTATIONS=1 Related reading as to why attestations can be disabled by users: https://github.com/aws/aws-cdk/issues/30258, https://stackoverflow.com... — committed to tobni/pants by tobni 2 years ago
- fix: Handle buildx output with BUILDX_NO_DEFAULT_ATTESTATIONS=1 Related reading as to why attestations can be disabled by users: https://github.com/aws/aws-cdk/issues/30258, https://stackoverflow.com... — committed to tobni/pants by tobni 2 years ago
- fix: Handle buildx output with BUILDX_NO_DEFAULT_ATTESTATIONS=1 (#21735) Related reading as to why attestations can be disabled by users: https://github.com/aws/aws-cdk/issues/30258, https://stackove... — committed to pantsbuild/pants by tobni 2 years ago
- fix: Handle buildx output with BUILDX_NO_DEFAULT_ATTESTATIONS=1 (#21735) Related reading as to why attestations can be disabled by users: https://github.com/aws/aws-cdk/issues/30258, https://stackove... — committed to pantsbuild/pants by tobni 2 years ago
- fix: Handle buildx output with BUILDX_NO_DEFAULT_ATTESTATIONS=1 (#21735) Related reading as to why attestations can be disabled by users: https://github.com/aws/aws-cdk/issues/30258, https://stackove... — committed to pantsbuild/pants by tobni 2 years ago
- fix: Handle buildx output with BUILDX_NO_DEFAULT_ATTESTATIONS=1 (Cherry-pick of #21735) (#21738) Related reading as to why attestations can be disabled by users: https://github.com/aws/aws-cdk/issues... — committed to pantsbuild/pants by WorkerPants 2 years ago
- fix: Handle buildx output with BUILDX_NO_DEFAULT_ATTESTATIONS=1 (Cherry-pick of #21735) (#21737) Related reading as to why attestations can be disabled by users: https://github.com/aws/aws-cdk/issues... — committed to pantsbuild/pants by WorkerPants 2 years ago
- fix: docker build attestations break cdk-assets (400 Bad Request) (#342) There are various issues in cdk that can be traced back to attestations in docker: https://github.com/aws/aws-cdk/issues/3025... — committed to cdklabs/cdk-assets by kaizencc 2 years ago
- fix: docker build attestations break cdk-assets (400 Bad Request) (#342) There are various issues in cdk that can be traced back to attestations in docker: https://github.com/aws/aws-cdk/issues/3025... — committed to cdklabs/cdk-assets by kaizencc 2 years ago
- chore(deps): update cdk-assets (#33415) The lastest cdk-assets is required in cdk to mitigate a ECR upload issue. It includes the following fix: https://github.com/cdklabs/cdk-assets/pull/342. The fo... — committed to aws/aws-cdk by kaizencc 2 years ago
- chore(deps): update cdk-assets (#33415) The lastest cdk-assets is required in cdk to mitigate a ECR upload issue. It includes the following fix: https://github.com/cdklabs/cdk-assets/pull/342. The fo... — committed to yashkh-amzn/aws-cdk by kaizencc 2 years ago
- chore(deps): update cdk-assets (#33415) The lastest cdk-assets is required in cdk to mitigate a ECR upload issue. It includes the following fix: https://github.com/cdklabs/cdk-assets/pull/342. The fo... — committed to shikha372/aws-cdk by kaizencc 2 years ago
I successfully reproduced it on my Mac M1 by the following steps:
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.
Related issue: #31549