Content-Type for Dependency Proxy is incorrect for pulled images

Summary

Dependency proxy uses incorrect Content-Type, which prevents usage with Kaniko, Crane, etc. Seems to be same issues as formerly fixed issue #299566 (closed).

Steps to reproduce

Same reproducer as in ticket linked above. This bug seems to have been re-introduced.

Example Project

Same as in linked ticket.

What is the current bug behavior?

Content-Type header in response for an image that is already cached is text/plain; charset=utf-8 instead of the appropriate type like application/vnd.docker.distribution.manifest.v2+json.

What is the expected correct behavior?

Content-Type matches what Docker Hub gives and the actual mediaType.

Relevant logs and/or screenshots

See also logs from linked ticket. The below is from running the following job within GitLab CI:

dep-proxy-test:
  image:
    name: gcr.io/go-containerregistry/crane:debug
    entrypoint: [""]
  needs: []
  script:
    - crane auth login -u "$CI_DEPENDENCY_PROXY_USER" -p "$CI_DEPENDENCY_PROXY_PASSWORD" "$CI_DEPENDENCY_PROXY_SERVER"
    - crane pull -v ${CI_DEPENDENCY_PROXY_DIRECT_GROUP_IMAGE_PREFIX}/eclipse-temurin:17.0.10_7-jdk jdk.tar

Output from crane pull (hosts redacted).

2024/02/08 19:51:15 GET /v2/test/dependency_proxy/containers/eclipse-temurin/manifests/17.0.10_7-jdk HTTP/1.1
Host: gitlab.example.com:443
User-Agent: crane/ea19b579661d99bc753c92e93730b8aab6ecd31b go-containerregistry/(devel)
Accept: application/vnd.docker.distribution.manifest.v1+json,application/vnd.docker.distribution.manifest.v1+prettyjws,application/vnd.docker.distribution.manifest.v2+json,application/vnd.oci.image.manifest.v1+json,application/vnd.docker.distribution.manifest.list.v2+json,application/vnd.oci.image.index.v1+json
Authorization: <redacted>
Accept-Encoding: gzip
2024/02/08 19:51:16 <-- 200 https://gitlab.example.com:443/v2/test/dependency_proxy/containers/eclipse-temurin/manifests/17.0.10_7-jdk (692.907799ms)
2024/02/08 19:51:16 HTTP/2.0 200 OK
Cache-Control: no-cache
Content-Disposition: 
Content-Md5: TmV7eabbMTjQzFx3yDiNhA==
Content-Security-Policy: 
Content-Type: text/plain; charset=utf-8
Date: Thu, 08 Feb 2024 19:51:16 GMT
Docker-Content-Digest: sha256:9b7aa20276a61013d7f8ce6f5e7b7e7c51a9ec20a9c96f8bd0c677aee2a289fa
Docker-Distribution-Api-Version: registry/2.0
Etag: W/"0x8DC28D2AB11336C"
Last-Modified: Thu, 08 Feb 2024 18:20:45 GMT
Permissions-Policy: interest-cohort=()
Referrer-Policy: strict-origin-when-cross-origin
Server: nginx
Set-Cookie: _gitlab_session=a9278676624432cddab0eced3e2fc61e; path=/; secure; HttpOnly; SameSite=None
Strict-Transport-Security: max-age=63072000
Vary: Accept-Encoding
X-Content-Type-Options: nosniff
X-Download-Options: noopen
X-Frame-Options: SAMEORIGIN
X-Gitlab-Meta: {"correlation_id":"01HP54CF4G7E9YGKZ820EQ51P7","version":"1"}
X-Ms-Blob-Type: BlockBlob
X-Ms-Copy-Completion-Time: Thu, 08 Feb 2024 18:20:45 GMT
X-Ms-Copy-Id: 56c05bf5-388d-4289-8bed-c282d96d4824
X-Ms-Copy-Progress: 1700/1700
X-Ms-Copy-Source: https://stjhucoampcommon.blob.core.usgovcloudapi.net/gitlab-dependency-proxy/tmp/uploads/1707416445-3208385-0002-9203-56d4729d4754ba6af84299af7a2d43d0
X-Ms-Copy-Status: success
X-Ms-Creation-Time: Thu, 08 Feb 2024 18:20:45 GMT
X-Ms-Lease-State: available
X-Ms-Lease-Status: unlocked
X-Ms-Request-Id: 1ad4290f-b01e-0007-28c8-5ac917000000
X-Ms-Server-Encrypted: true
X-Ms-Version: 2018-11-09
X-Permitted-Cross-Domain-Policies: none
X-Request-Id: 01HP54CF4G7E9YGKZ820EQ51P7
X-Runtime: 0.667890
X-Ua-Compatible: IE=edge
X-Xss-Protection: 1; mode=block
{"manifests":[{"digest":"sha256:ea9fa95d08ebe9be6709b036088603db68ded9902692755e489fa64954491e14","mediaType":"application\/vnd.docker.distribution.manifest.v2+json","platform":{"architecture":"amd64","os":"linux"},"size":1368},{"digest":"sha256:e70e9319a4c3ff846a348f393cb9bb70cb23f3584b752db0ffafa64c58dacb5c","mediaType":"application\/vnd.docker.distribution.manifest.v2+json","platform":{"architecture":"arm","os":"linux","variant":"v7"},"size":1368},{"digest":"sha256:cea8b177ad564c588b33615042fd5ab9e77c1ada49d446e27e2ead2be8a5709b","mediaType":"application\/vnd.docker.distribution.manifest.v2+json","platform":{"architecture":"arm64","os":"linux","variant":"v8"},"size":1368},{"digest":"sha256:403a37008d2565d92b854cfabe2e6029658fada94332636f06c3616a72591b04","mediaType":"application\/vnd.docker.distribution.manifest.v2+json","platform":{"architecture":"ppc64le","os":"linux"},"size":1368},{"digest":"sha256:c636b5779879126af65b82da9fcec486670665e25a32936f71c80fbf88707166","mediaType":"application\/vnd.docker.distribution.manifest.v2+json","platform":{"architecture":"s390x","os":"linux"},"size":1368},{"digest":"sha256:6847bb6f0595bc38d4cf188e04e95fe14537ff4cdb026eaf0e9e74e72ed25226","mediaType":"application\/vnd.docker.distribution.manifest.v2+json","platform":{"architecture":"amd64","os":"windows","os.version":"10.0.20348.2227"},"size":1791},{"digest":"sha256:52d04f010919a2e7196a5b4e265426e5108dfe885932172a58f424e54e6e26b0","mediaType":"application\/vnd.docker.distribution.manifest.v2+json","platform":{"architecture":"amd64","os":"windows","os.version":"10.0.17763.5329"},"size":1792}],"mediaType":"application\/vnd.docker.distribution.manifest.list.v2+json","schemaVersion":2}
2024/02/08 19:51:16 Unexpected media type for Image(): text/plain; charset=utf-8

Output of checks

Results of GitLab environment info

Expand for output related to GitLab environment info

System information
System:		Debian 11
Proxy:		no
Current User:	git
Using RVM:	no
Ruby Version:	3.1.4p223
Gem Version:	3.4.22
Bundler Version:2.5.4
Rake Version:	13.0.6
Redis Version:	7.0.15
Sidekiq Version:7.1.6
Go Version:	unknown

GitLab information
Version:	16.8.1-ee
Revision:	1242b447720
Directory:	/opt/gitlab/embedded/service/gitlab-rails
DB Adapter:	PostgreSQL
DB Version:	13.12
URL:		https://gitlab.example.com
HTTP Clone URL:	https://gitlab.example.com/some-group/some-project.git
SSH Clone URL:	git@gitlab.example.com:some-group/some-project.git
Elasticsearch:	no
Geo:		no
Using LDAP:	no
Using Omniauth:	yes
Omniauth Providers: openid_connect

GitLab Shell
Version:	14.33.0
Repository storages:
- default: 	unix:/var/opt/gitlab/gitaly/gitaly.socket
GitLab Shell path:		/opt/gitlab/embedded/service/gitlab-shell

Gitaly
- default Address: 	unix:/var/opt/gitlab/gitaly/gitaly.socket
- default Version: 	16.8.1
- default Git Version: 	2.42.0

Results of GitLab application Check

Expand for output related to the GitLab application check

Checking GitLab subtasks ...

Checking GitLab Shell ...

GitLab Shell: ... GitLab Shell version >= 14.33.0 ? ... OK (14.33.0) Running /opt/gitlab/embedded/service/gitlab-shell/bin/check Internal API available: OK Redis available via internal API: OK gitlab-shell self-check successful

Checking GitLab Shell ... Finished

Checking Gitaly ...

Gitaly: ... default ... OK

Checking Gitaly ... Finished

Checking Sidekiq ...

Sidekiq: ... Running? ... yes Number of Sidekiq processes (cluster/worker) ... 1/3

Checking Sidekiq ... Finished

Checking Incoming Email ...

Incoming Email: ... Reply by email is disabled in config/gitlab.yml

Checking Incoming Email ... Finished

Checking LDAP ...

LDAP: ... LDAP is disabled in config/gitlab.yml

Checking LDAP ... Finished

Checking GitLab App ...

Database config exists? ... yes Tables are truncated? ... skipped All migrations up? ... yes Database contains orphaned GroupMembers? ... no GitLab config exists? ... yes GitLab config up to date? ... yes Cable config exists? ... yes Resque config exists? ... yes Log directory writable? ... yes Tmp directory writable? ... yes Uploads directory exists? ... yes Uploads directory has correct permissions? ... yes Uploads directory tmp has correct permissions? ... yes Systemd unit files or init script exist? ... skipped (omnibus-gitlab has neither init script nor systemd units) Systemd unit files or init script up-to-date? ... skipped (omnibus-gitlab has neither init script nor systemd units) Projects have namespace: ... 8/1 ... yes 8/2 ... yes 8/3 ... yes 11/4 ... yes Redis version >= 6.0.0? ... yes Ruby version >= 3.0.6 ? ... yes (3.1.4) Git user has default SSH configuration? ... yes Active users: ... 4 Is authorized keys file accessible? ... yes GitLab configured to store new projects in hashed storage? ... yes All projects are in hashed storage? ... yes Elasticsearch version 7.x-8.x or OpenSearch version 1.x ... skipped (Advanced Search is disabled) All migrations must be finished before doing a major upgrade ... skipped (Advanced Search is disabled)

Checking GitLab App ... Finished

Checking GitLab subtasks ... Finished

Edited by Trent Nadeau