Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

fix: oras pull error empty response Docker-Content-Digest #237

Merged
merged 10 commits into from
Aug 25, 2022

Conversation

nima
Copy link
Contributor

@nima nima commented Jul 11, 2022

See #225 for details, but here's the tldr:

% oras pull 080565210187.dkr.ecr.us-west-2.amazonaws.com/my.repo:my.tag
Error: GET "https://080565210187.dkr.ecr.us-west-2.amazonaws.com/v2/my.repo/manifests/my.tag": empty response Docker-Content-Digest

The expected outcome (what this PR claims to fix):

% oras pull 080565210187.dkr.ecr.us-west-2.amazonaws.com/my.repo:my.tag
Downloading 3cd22ae067a3
Downloaded empty artifact
Pulled 080565210187.dkr.ecr.us-west-2.amazonaws.com/my.repo:my.tag
Digest: sha256:32aef68c20b6f25d69ecbc2f3f98e28f6f6fdacade75ee879459b61f610583f0

Resolves #225

@nima nima force-pushed the issues/225 branch 2 times, most recently from 0fba8f2 to f43a780 Compare July 11, 2022 16:35
@nima nima marked this pull request as draft July 11, 2022 16:47
@nima
Copy link
Contributor Author

nima commented Jul 12, 2022

repro prior to the change:

➜  DoodleContainers git:(mainline) ✗ make setup start main
#------------------------------------------------------------------------------- oci:/home/ntd/docker/config.json
aws --profile ntd@ecr --region us-west-2 ecr get-login-password | docker login --username AWS --password-stdin 080565210187.dkr.ecr.us-west-2.amazonaws.com
WARNING! Your password will be stored unencrypted in /home/ntd/.docker/config.json.
Configure a credential helper to remove this warning. See
https://docs.docker.com/engine/reference/commandline/login/#credentials-store

Login Succeeded

#------------------------------------------------------------------------------- oci:/home/ntd/docker/config.json
aws --profile ntd@ecr --region us-west-2 ecr get-login-password | oras login --username AWS --password-stdin 080565210187.dkr.ecr.us-west-2.amazonaws.com
Login Succeeded

#------------------------------------------------------------------------------- oci:setup
aws --profile ntd@ecr --region us-west-2 ecr create-repository --repository-name my.repo --image-scanning-configuration scanOnPush=true | jq .
{
  "repository": {
    "repositoryUri": "080565210187.dkr.ecr.us-west-2.amazonaws.com/my.repo",
    "imageScanningConfiguration": {
      "scanOnPush": true
    },
    "encryptionConfiguration": {
      "encryptionType": "AES256"
    },
    "registryId": "080565210187",
    "imageTagMutability": "MUTABLE",
    "repositoryArn": "arn:aws:ecr:us-west-2:080565210187:repository/my.repo",
    "repositoryName": "my.repo",
    "createdAt": 1657835189
  }
}

#------------------------------------------------------------------------------- oci:setup
docker image build --tag my.repo:my.tag .
Sending build context to Docker daemon  371.2kB
Step 1/8 : FROM alpine:latest
 ---> e66264b98777
Step 2/8 : RUN mkdir -p /docked
 ---> Running in d2183399b150
Removing intermediate container d2183399b150
 ---> 56d7cf077766
Step 3/8 : WORKDIR /docked
 ---> Running in 36bac997e4ab
Removing intermediate container 36bac997e4ab
 ---> 8c7179532383
Step 4/8 : RUN apk add --no-cache socat
 ---> Running in 902e75a3a394
fetch https://dl-cdn.alpinelinux.org/alpine/v3.16/main/x86_64/APKINDEX.tar.gz
fetch https://dl-cdn.alpinelinux.org/alpine/v3.16/community/x86_64/APKINDEX.tar.gz
(1/4) Installing ncurses-terminfo-base (6.3_p20220521-r0)
(2/4) Installing ncurses-libs (6.3_p20220521-r0)
(3/4) Installing readline (8.1.2-r0)
(4/4) Installing socat (1.7.4.3-r0)
Executing busybox-1.35.0-r13.trigger
OK: 7 MiB in 18 packages
Removing intermediate container 902e75a3a394
 ---> 671c5e9f24a1
Step 5/8 : EXPOSE 1234
 ---> Running in fec0ca2cc0aa
Removing intermediate container fec0ca2cc0aa
 ---> 6480cf48acca
Step 6/8 : EXPOSE 4321
 ---> Running in 99961c605283
Removing intermediate container 99961c605283
 ---> 8ca79f8cdfcd
Step 7/8 : ENTRYPOINT [ "socat" ]
 ---> Running in 11b11566b05a
Removing intermediate container 11b11566b05a
 ---> 134e5e444ce0
Step 8/8 : CMD [ "TCP4-LISTEN:1234", "TCP4-LISTEN:4321" ]
 ---> Running in afb7185f1033
Removing intermediate container afb7185f1033
 ---> 4b8f7040c20e
Successfully built 4b8f7040c20e
Successfully tagged my.repo:my.tag

#------------------------------------------------------------------------------- oci:setup
docker image tag my.repo:my.tag 080565210187.dkr.ecr.us-west-2.amazonaws.com/my.repo:my.tag

#------------------------------------------------------------------------------- oci:setup
docker image push 080565210187.dkr.ecr.us-west-2.amazonaws.com/my.repo:my.tag
The push refers to repository [080565210187.dkr.ecr.us-west-2.amazonaws.com/my.repo]
8e2e4e6d1ed9: Pushed
980e95506b86: Pushed
24302eb7d908: Pushed
my.tag: digest: sha256:f8f0e94c24b562c0a5059a6c5d1c23f3f15c16381e912798531522d32d496df4 size: 945

#------------------------------------------------------------------------------- oci:start
docker container run --detach --rm --name my.container --publish 1234:1234 --publish 4321:4321 my.repo:my.tag
2e9752460dc4862f0dafbbf1f1b29fe1521ce771cd58ae9208e82a1ca6ecde72

#------------------------------------------------------------------------------- oci:main
oras pull 080565210187.dkr.ecr.us-west-2.amazonaws.com/my.repo:my.tag
Error: GET "https://080565210187.dkr.ecr.us-west-2.amazonaws.com/v2/my.repo/manifests/my.tag": empty response Docker-Content-Digest

make: *** [main] Error 1
➜  DoodleContainers git:(mainline) ✗

run test again...

➜  DoodleContainers git:(mainline) ✗ make
################################################################################
#------------------------------------------------------------------------------- oci:/home/nima/docker/config.json
aws --profile nima@ecr --region us-west-2 ecr get-login-password | docker login --username AWS --password-stdin 12345678901.dkr.ecr.us-west-2.amazonaws.com
WARNING! Your password will be stored unencrypted in /home/nima/.docker/config.json.
Configure a credential helper to remove this warning. See
https://docs.docker.com/engine/reference/commandline/login/#credentials-store

Login Succeeded

#------------------------------------------------------------------------------- oci:/home/nima/docker/config.json
aws --profile nima@ecr --region us-west-2 ecr get-login-password | oras login --username AWS --password-stdin 12345678901.dkr.ecr.us-west-2.amazonaws.com
Login Succeeded

#------------------------------------------------------------------------------- oci:setup
aws --profile nima@ecr --region us-west-2 ecr create-repository --repository-name my.repo --image-scanning-configuration scanOnPush=true | jq .
{
  "repository": {
    "repositoryUri": "12345678901.dkr.ecr.us-west-2.amazonaws.com/my.repo",
    "imageScanningConfiguration": {
      "scanOnPush": true
    },
    "encryptionConfiguration": {
      "encryptionType": "AES256"
    },
    "registryId": "12345678901",
    "imageTagMutability": "MUTABLE",
    "repositoryArn": "arn:aws:ecr:us-west-2:12345678901:repository/my.repo",
    "repositoryName": "my.repo",
    "createdAt": 1657595026
  }
}

#------------------------------------------------------------------------------- oci:setup
docker image build --tag my.repo:my.tag .
Sending build context to Docker daemon    276kB
Step 1/8 : FROM alpine:latest
 ---> e66264b98777
Step 2/8 : RUN mkdir -p /docked
 ---> Using cache
 ---> b70ff30822c5
Step 3/8 : WORKDIR /docked
 ---> Using cache
 ---> adbf13e74342
Step 4/8 : RUN apk add --no-cache socat
 ---> Using cache
 ---> 10673949eac4
Step 5/8 : EXPOSE 1234
 ---> Using cache
 ---> fe6e2db39608
Step 6/8 : EXPOSE 4321
 ---> Using cache
 ---> 69b73391ecf3
Step 7/8 : ENTRYPOINT [ "socat" ]
 ---> Using cache
 ---> 7ed365f9b91e
Step 8/8 : CMD [ "TCP4-LISTEN:1234", "TCP4-LISTEN:4321" ]
 ---> Using cache
 ---> cffeefdfa844
Successfully built cffeefdfa844
Successfully tagged my.repo:my.tag

#------------------------------------------------------------------------------- oci:setup
docker image tag my.repo:my.tag 12345678901.dkr.ecr.us-west-2.amazonaws.com/my.repo:my.tag

#------------------------------------------------------------------------------- oci:setup
docker image push 12345678901.dkr.ecr.us-west-2.amazonaws.com/my.repo:my.tag
The push refers to repository [12345678901.dkr.ecr.us-west-2.amazonaws.com/my.repo]
336abb34c67c: Pushed
26a6b0d4e0cf: Pushed
24302eb7d908: Pushed
my.tag: digest: sha256:b9b2c380a97b8b4ab2acfd3d88850bc3ce2b95e803af33ac382e002b6683fbfd size: 945

#------------------------------------------------------------------------------- oci:main
docker image rm my.repo:my.tag
Untagged: my.repo:my.tag

#------------------------------------------------------------------------------- oci:main
oras pull 12345678901.dkr.ecr.us-west-2.amazonaws.com/my.repo:my.tag
Downloaded empty artifact
Pulled 12345678901.dkr.ecr.us-west-2.amazonaws.com/my.repo:my.tag
Digest:

#------------------------------------------------------------------------------- oci:teardown
docker image rm my.repo:my.tag
Error: No such image: my.repo:my.tag

make: [oci.teardown] Error 1 (ignored)
#------------------------------------------------------------------------------- oci:teardown
docker image rm 12345678901.dkr.ecr.us-west-2.amazonaws.com/my.repo:my.tag
Error response from daemon: conflict: unable to remove repository reference "12345678901.dkr.ecr.us-west-2.amazonaws.com/my.repo:my.tag" (must force) - container 799004d623e6 is using its referenced image cffeefdfa844

make: [oci.teardown] Error 1 (ignored)
#------------------------------------------------------------------------------- oci:teardown
aws --profile nima@ecr --region us-west-2 ecr batch-delete-image --repository-name my.repo --image-ids imageTag=my.tag | jq .
{
  "failures": [],
  "imageIds": [
    {
      "imageTag": "my.tag",
      "imageDigest": "sha256:b9b2c380a97b8b4ab2acfd3d88850bc3ce2b95e803af33ac382e002b6683fbfd"
    }
  ]
}

#------------------------------------------------------------------------------- oci:teardown
aws --profile nima@ecr --region us-west-2 ecr delete-repository --repository-name my.repo | jq .
{
  "repository": {
    "repositoryUri": "12345678901.dkr.ecr.us-west-2.amazonaws.com/my.repo",
    "registryId": "12345678901",
    "imageTagMutability": "MUTABLE",
    "repositoryArn": "arn:aws:ecr:us-west-2:12345678901:repository/my.repo",
    "repositoryName": "my.repo",
    "createdAt": 1657595026
  }
}

GUIDE            : https://www.freecodecamp.org/news/the-docker-handbook/
DEMO             : oci
TARGET           : oci
ORAS_CLIENT_PATH : /home/nima/bin/oras
ORAS_CLIENT      : 0.13.0+unreleased
DOCKER_CLIENT    : 20.10.7
DOCKER_SERVER    : 20.10.7
################################################################################
➜  DoodleContainers git:(mainline) ✗

internal/ioutil/io.go Outdated Show resolved Hide resolved
@Wwwsylvia
Copy link
Member

Thanks @nima for the PR! Please let us know if this is ready for review. 😀

@nima
Copy link
Contributor Author

nima commented Jul 16, 2022

Thanks @nima for the PR! Please let us know if this is ready for review. 😀

Thanks for taking a look @Wwwsylvia -- I have another PR out now, it's not intended to be approved, only to be inspected because I'm still not sure how to deal with the current issue. I'm maintaining a log of my thoughts in a thread in the #oras slack channel, and also in the git commit message body.

@nima nima force-pushed the issues/225 branch 8 times, most recently from bfe9480 to 1d4fbdb Compare July 19, 2022 07:22
@nima nima force-pushed the issues/225 branch 3 times, most recently from 3521041 to 2fa1eb0 Compare August 18, 2022 02:45
@nima
Copy link
Contributor Author

nima commented Aug 18, 2022

[INFO] Current slack thread for this round.

@nima nima marked this pull request as ready for review August 18, 2022 03:32
@nima
Copy link
Contributor Author

nima commented Aug 18, 2022

I've set this to R4R despite the failure to expose the PR. The failure is due to the fact that one of the dependencies of this package, go-digest, has also been modified as part of this change. Locally, I've been using thereplace directive in go.mod to point it to the locally modified version, but I'm not sure how to go about it here, other than get that change separately approved and merged in first, then continue with this.

@shizhMSFT
Copy link
Contributor

Few general comments to make this PR better.

  • Please follow conventional commits for PR title and body.
  • Please link this PR to an issue.
  • It is better to have a ruler at 80 chars for comment blocks so that people with small screens can read the code easily.
  • Try not to modify the code of dependencies. If it is really needed, try proposing and merging the required changes to the upstream first.

@FeynmanZhou
Copy link
Member

Few general comments to make this PR better.

  • Please follow conventional commits for PR title and body.
  • Please link this PR to an issue.
  • It is better to have a ruler at 80 chars for comment blocks so that people with small screens can read the code easily.
  • Try not to modify the code of dependencies. If it is really needed, try proposing and merging the required changes to the upstream first.

The ORAS community also has a simple version of Git Conventions for references.

@shizhMSFT shizhMSFT linked an issue Aug 18, 2022 that may be closed by this pull request
registry/remote/repository.go Outdated Show resolved Hide resolved
registry/remote/repository.go Outdated Show resolved Hide resolved
registry/remote/repository.go Outdated Show resolved Hide resolved
registry/remote/repository.go Outdated Show resolved Hide resolved
nima added 8 commits August 24, 2022 20:49
That this issue existed is a side-effect of an earlier chronic issue.  At least
in the pull workflow, no where does the library (on behalf of the client)
attempt to verify the digest returned by the register/server.  By not doing so,
it also has taken an unhealthy dependency on a precariously OPTIONAL response
header, namely, `Docker-Content-Digest`.  All this has lead to issue oras-project#225.

Discussion thread on this has been opened up in Slack:

    https://cloud-native.slack.com/archives/CJ1KHJM5Z/p1657935407555609

Signed-off-by: Nima Talebi <github@nima.id.au>
Also drop dependency on go-digest changes, making this PR stand-alone.

Signed-off-by: Nima Talebi <github@nima.id.au>
Signed-off-by: Nima Talebi <github@nima.id.au>
Signed-off-by: Nima Talebi <github@nima.id.au>
Signed-off-by: Nima Talebi <github@nima.id.au>
Signed-off-by: Nima Talebi <github@nima.id.au>
Signed-off-by: Nima Talebi <github@nima.id.au>
Signed-off-by: Nima Talebi <github@nima.id.au>
Copy link
Contributor Author

@nima nima left a comment

Choose a reason for hiding this comment

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

Okay I think I've addressed all comments so far. Also expanded on what happens when expected is not length-checked.

registry/remote/repository.go Outdated Show resolved Hide resolved
registry/remote/repository.go Outdated Show resolved Hide resolved
registry/remote/repository.go Outdated Show resolved Hide resolved
registry/remote/repository.go Outdated Show resolved Hide resolved
registry/remote/repository_test.go Outdated Show resolved Hide resolved
registry/remote/repository.go Outdated Show resolved Hide resolved
registry/remote/repository.go Show resolved Hide resolved
Signed-off-by: Nima Talebi <github@nima.id.au>
@nima nima force-pushed the issues/225 branch 3 times, most recently from 9e662e6 to bcfd66f Compare August 25, 2022 05:33
Copy link
Contributor

@shizhMSFT shizhMSFT left a comment

Choose a reason for hiding this comment

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

LGTM

Copy link
Member

@Wwwsylvia Wwwsylvia left a comment

Choose a reason for hiding this comment

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

LGTM with s minor suggestion

registry/remote/repository.go Outdated Show resolved Hide resolved
@nima
Copy link
Contributor Author

nima commented Aug 25, 2022

And a final double-check...

% oras pull 080565210187.dkr.ecr.us-west-2.amazonaws.com/my.repo:my.tag
Downloaded empty artifact
Pulled 080565210187.dkr.ecr.us-west-2.amazonaws.com/my.repo:my.tag
Digest: sha256:410bc64c7dbbc3286211561a0f6ca43affdca5c92c568f838a37e34640f5f76e

Signed-off-by: Nima Talebi <github@nima.id.au>
Copy link
Member

@Wwwsylvia Wwwsylvia left a comment

Choose a reason for hiding this comment

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

LGTM!

@Wwwsylvia Wwwsylvia merged commit 98e72a2 into oras-project:main Aug 25, 2022
@nima nima deleted the issues/225 branch August 25, 2022 06:45
@gokarnm
Copy link

gokarnm commented Aug 25, 2022

Thanks @nima for chasing this issue down, and @shizhMSFT @Wwwsylvia for the reviews!
@shizhMSFT @FeynmanZhou do we plan to release this fix with a patch release?

@shizhMSFT
Copy link
Contributor

We plan to release this in the next rc release.

@michaelb990
Copy link

michaelb990 commented Oct 11, 2022 via email

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.

oras pull error: empty response Docker-Content-Digest
8 participants