Skip to content

Commit

Permalink
diable digest resolution for manifest v2 schema 1 manifests
Browse files Browse the repository at this point in the history
  • Loading branch information
Yiyuanzzz committed Jul 19, 2024
1 parent 8c85f33 commit 30e42d5
Show file tree
Hide file tree
Showing 4 changed files with 53 additions and 2 deletions.
24 changes: 24 additions & 0 deletions agent/engine/docker_task_engine.go
Original file line number Diff line number Diff line change
Expand Up @@ -114,6 +114,13 @@ const (
stopContainerBackoffJitter = 0.2
stopContainerBackoffMultiplier = 1.3
stopContainerMaxRetryCount = 5

// MediaTypeManifestV1 specifies the media type for v1 manifest
mediaTypeManifestV1 = "application/vnd.docker.distribution.manifest.v1+json"
// MediaTypeSignedManifestV1 specifies the media type for signed v1 manifest
mediaTypeSignedManifestV1 = "application/vnd.docker.distribution.manifest.v1+prettyjws"
// MediaTypeManifestV1 specifies the media type for v2 manifest
mediaTypeManifestV2 = "application/vnd.docker.distribution.manifest.v2+json"
)

var newExponentialBackoff = retry.NewExponentialBackoff
Expand Down Expand Up @@ -1295,6 +1302,7 @@ func (engine *DockerTaskEngine) pullContainerManifest(
},
}
}

imageManifestDigest = parsedDigest
logger.Info("Fetched image manifest digest for container from local image inspect", logger.Fields{
field.TaskARN: task.Arn,
Expand Down Expand Up @@ -1352,6 +1360,22 @@ func (engine *DockerTaskEngine) pullContainerManifest(
})
return dockerapi.DockerContainerMetadata{Error: manifestPullErr}
}
imageManifestMediatype := distInspect.Descriptor.MediaType
logger.Info("Fetched image manifest Mediatype for container from registry", logger.Fields{
field.TaskARN: task.Arn,
field.ContainerName: container.Name,
field.ImageMediatype: imageManifestMediatype,
field.Image: container.Image,
})
if strings.Contains(imageManifestMediatype, mediaTypeManifestV1) || strings.Contains(imageManifestMediatype, mediaTypeSignedManifestV1) {
logger.Info("skipping digest resolution for manifest v2 schema 1", logger.Fields{
field.TaskARN: task.Arn,
field.ContainerName: container.Name,
field.ImageMediatype: imageManifestMediatype,
field.Image: container.Image,
})
return dockerapi.DockerContainerMetadata{}
}
imageManifestDigest = distInspect.Descriptor.Digest
logger.Info("Fetched image manifest digest for container from registry", logger.Fields{
field.TaskARN: task.Arn,
Expand Down
29 changes: 27 additions & 2 deletions agent/engine/docker_task_engine_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -4195,6 +4195,23 @@ func TestPullContainerManifest(t *testing.T) {
},
expectedDigest: testDigest.String(),
},
{
name: "image pull required - skip digest resolution for schema1 image",
image: "myimage",
imagePullBehavior: config.ImagePullAlwaysBehavior,
setDockerClientExpectations: func(c *gomock.Controller, d *mock_dockerapi.MockDockerClient) {
versioned := mock_dockerapi.NewMockDockerClient(c)
versioned.EXPECT().
PullImageManifest(gomock.Any(), "myimage", nil).
Return(
registry.DistributionInspect{
Descriptor: ocispec.Descriptor{MediaType: MediaTypeManifestV1},
},
nil)
d.EXPECT().WithVersion(dockerclient.Version_1_35).Return(versioned, nil)
},
expectedResult: dockerapi.DockerContainerMetadata{},
},
{
name: "image pull required - required docker API version unsupported",
image: "myimage",
Expand Down Expand Up @@ -4229,7 +4246,12 @@ func TestPullContainerManifest(t *testing.T) {
versioned.EXPECT().
PullImageManifest(gomock.Any(), "myimage", nil).
Return(
registry.DistributionInspect{Descriptor: ocispec.Descriptor{Digest: testDigest}},
registry.DistributionInspect{
Descriptor: ocispec.Descriptor{
MediaType: mediaTypeManifestV2,
Digest: testDigest,
},
},
nil)
d.EXPECT().WithVersion(dockerclient.Version_1_35).Return(versioned, nil)
},
Expand Down Expand Up @@ -4261,7 +4283,10 @@ func TestPullContainerManifest(t *testing.T) {
PullImageManifest(gomock.Any(), "myimage", expectedRegistryAuthData).
Return(
registry.DistributionInspect{
Descriptor: ocispec.Descriptor{Digest: digest.Digest(testDigest.String())},
Descriptor: ocispec.Descriptor{
MediaType: mediaTypeManifestV2,
Digest: digest.Digest(testDigest.String()),
},
},
nil)
d.EXPECT().WithVersion(dockerclient.Version_1_35).Return(versioned, nil)
Expand Down

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

1 change: 1 addition & 0 deletions ecs-agent/logger/field/constants.go
Original file line number Diff line number Diff line change
Expand Up @@ -49,6 +49,7 @@ const (
ImageLastUsedAt = "imageLastUsedAt"
ImagePullSucceeded = "imagePullSucceeded"
ImageDigest = "imageDigest"
ImageMediaType = "imageMediaType"
ContainerName = "containerName"
ContainerImage = "containerImage"
ContainerExitCode = "containerExitCode"
Expand Down

0 comments on commit 30e42d5

Please sign in to comment.