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

Use the correct Docker digest when checking for updates #3060

Merged
merged 1 commit into from
Feb 4, 2021

Conversation

jurre
Copy link
Member

@jurre jurre commented Feb 1, 2021

Previously, Dependabot would use the Docker registry manifest
endpoint
with the
application/vnd.docker.distribution.manifest.v2+json Media Type:

dt=$(curl "https://auth.docker.io/token?service=registry.docker.io&scope=repository:library/python:pull" | jq -r .access_token)
curl curl --get -v https://registry.hub.docker.com:443/v2/library/python/manifests/slim --header "Authorization: Bearer $dt" --header "Accept: application/vnd.docker.distribution.manifest.v2+json"
< HTTP/1.1 200 OK
< Content-Length: 1370
< Content-Type: application/vnd.docker.distribution.manifest.v2+json
< Docker-Content-Digest: sha256:af2d64e6de9f891bd5958a498bd2394389143749b3c57ffcc8c2aec054b28ad5

However, the digest that is returned in the header here, is actually
that of the first platform that's listed.

When we install that latest image, we see the digest should actually be:

docker images --digests | grep python
python slim sha256:50328b4efe5ff8ef8bb2e62e088a4cefeace39062c483c04987f5820e7cf73b1

When using the
application/vnd.docker.distribution.manifest.list.v2+json media type:

dt=$(curl "https://auth.docker.io/token?service=registry.docker.io&scope=repository:library/python:pull" | jq -r .access_token)
curl curl --get -v https://registry.hub.docker.com:443/v2/library/python/manifests/slim --header "Authorization: Bearer $dt" --header "Accept: application/vnd.docker.distribution.manifest.list.v2+json"

< HTTP/1.1 200 OK
< Content-Length: 1862
< Content-Type: application/vnd.docker.distribution.manifest.list.v2+json
< Docker-Content-Digest: sha256:50328b4efe5ff8ef8bb2e62e088a4cefeace39062c483c04987f5820e7cf73b1

We get the expected digest, and when inspecting the body, we can see
that we previously got the digest for amd64:

{
  "manifests": [
    {
      "digest": "sha256:af2d64e6de9f891bd5958a498bd2394389143749b3c57ffcc8c2aec054b28ad5",
      "mediaType": "application/vnd.docker.distribution.manifest.v2+json",
      "platform": {
        "architecture": "amd64",
        "os": "linux"
      },
      "size": 1370
    },

The tests have remained unchanged in this PR, because (unfortunately)
all the requests and responses are stubbed out.

Fixes #2962

@jurre jurre requested a review from a team as a code owner February 1, 2021 18:12
@jurre jurre force-pushed the jurre/use-correct-docker-digest branch from c2d393f to 5fa6576 Compare February 2, 2021 08:46
@jurre jurre force-pushed the jurre/use-correct-docker-digest branch from 5fa6576 to e437258 Compare February 2, 2021 11:17
Previously, Dependabot would use the [Docker registry manifest
endpoint](https://docs.docker.com/registry/spec/api/#manifest) with the
`application/vnd.docker.distribution.manifest.v2+json` Media Type:

```
dt=$(curl "https://auth.docker.io/token?service=registry.docker.io&scope=repository:library/python:pull" | jq -r .access_token)
curl curl --get -v https://registry.hub.docker.com:443/v2/library/python/manifests/slim --header "Authorization: Bearer $dt" --header "Accept: application/vnd.docker.distribution.manifest.v2+json"
< HTTP/1.1 200 OK
< Content-Length: 1370
< Content-Type: application/vnd.docker.distribution.manifest.v2+json
< Docker-Content-Digest: sha256:af2d64e6de9f891bd5958a498bd2394389143749b3c57ffcc8c2aec054b28ad5
```

However, the digest that is returned in the header here, is actually
that of the first platform that's listed.

When we install that latest image, we see the digest should actually be:

```
docker images --digests | grep python
python slim sha256:50328b4efe5ff8ef8bb2e62e088a4cefeace39062c483c04987f5820e7cf73b1
```

When using the
`application/vnd.docker.distribution.manifest.list.v2+json` media type:

```
dt=$(curl "https://auth.docker.io/token?service=registry.docker.io&scope=repository:library/python:pull" | jq -r .access_token)
curl curl --get -v https://registry.hub.docker.com:443/v2/library/python/manifests/slim --header "Authorization: Bearer $dt" --header "Accept: application/vnd.docker.distribution.manifest.list.v2+json"

< HTTP/1.1 200 OK
< Content-Length: 1862
< Content-Type: application/vnd.docker.distribution.manifest.list.v2+json
< Docker-Content-Digest: sha256:50328b4efe5ff8ef8bb2e62e088a4cefeace39062c483c04987f5820e7cf73b1
```

We get the expected digest, and when inspecting the body, we can see
that we previously got the digest for amd64:

```json
{
  "manifests": [
    {
      "digest": "sha256:af2d64e6de9f891bd5958a498bd2394389143749b3c57ffcc8c2aec054b28ad5",
      "mediaType": "application/vnd.docker.distribution.manifest.v2+json",
      "platform": {
        "architecture": "amd64",
        "os": "linux"
      },
      "size": 1370
    },
```

The tests have remained unchanged in this PR, because (unfortunately)
all the requests and responses are stubbed out.
@jurre jurre force-pushed the jurre/use-correct-docker-digest branch from e437258 to 58b2624 Compare February 2, 2021 11:31
@jurre jurre requested a review from feelepxyz February 2, 2021 13:23
Copy link
Contributor

@feelepxyz feelepxyz left a comment

Choose a reason for hiding this comment

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

👍 should we be upstreaming this change to the gem?

@jurre
Copy link
Member Author

jurre commented Feb 4, 2021

👍 should we be upstreaming this change to the gem?

Yeah, good shout. I'll open an issue to see what they think

@jurre jurre merged commit de65930 into main Feb 4, 2021
@jurre jurre deleted the jurre/use-correct-docker-digest branch February 4, 2021 15:53
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.

docker - incorrect update of manifest list sha to amd64 manifest sha
2 participants