camallo / dkregistry-rs

A pure-Rust asynchronous library for Docker Registry API v2
Apache License 2.0
62 stars 39 forks source link

Does not work with GCR with default settings #161

Closed MikailBag closed 4 years ago

MikailBag commented 4 years ago

get_manifest fails, because GCR returns error 404. Response body is

{"errors":[{"code":"MANIFEST_UNKNOWN","message":"Manifest with tag 'latest' has media type 'application/vnd.docker.distribution.manifest.v2+json', but client accepts 'application/vnd.docker.distribution.manifest.v2+json; q=0.5,application/vnd.docker.distribution.manifest.v1+prettyjws; charset=utf-8; q=0.4'."}]}

I am not sure if I right, but it seems like incorrect parsing of Accept HTTP header on GCR side. What do you think?

MikailBag commented 4 years ago

I've done some tests: Accept:application/vnd.docker.distribution.manifest.v2+json;q=0.5,application/vnd.docker.distribution.manifest.v1+prettyjws; charset=utf-8; q=0.4: produces error as above. Accept:application/vnd.docker.distribution.manifest.v2+json,application/vnd.docker.distribution.manifest.v1+prettyjws; charset=utf-8; q=0.4: works (successfully returns manifest). (Second Accept string has q=0.5 portion removed). I used httpie for experiments.

From this information I believe that Google Container Registry parses Accept header literally, splitting it by ,. It does not strip q parameter. So it observes that "application/vnd.docker.distribution.manifest.v2+json;q=1"!="application/vnd.docker.distribution.manifest.v2+json" and returns error.

I will try to investigate if passing q parameter is allowed by Docker Registry API.

steveej commented 4 years ago

I just had a play with this and it seems like skipping the q key is enough to make GCR happy. The following works here:

http --verbose 'https://gcr.io/v2/jjs-dev/jjs-apiserver/manifests/latest' 'Accept:application/vnd.docker.distribution.manifest.v2+json,application/vnd.docker.distribution.manifest.v1+prettyjws; charset=utf-8'

I also tried with just the ...v1+prettyjws type and it fails, so I recognize that they only support the v2+json at this time. I'd be in favor in baking these kind of workarounds into dkregistry over making the headers overridable as #162.