From a494a75cd258b0c7b2293c58c9dd33612ae55904 Mon Sep 17 00:00:00 2001 From: Ian Ballou Date: Wed, 31 Jul 2024 16:33:42 -0400 Subject: [PATCH] Fixes #37705 - 404 v1 search with v2 container clients --- .../container_gateway_api.rb | 4 ++-- test/container_gateway_api_test.rb | 10 ++++++++-- 2 files changed, 10 insertions(+), 4 deletions(-) diff --git a/lib/smart_proxy_container_gateway/container_gateway_api.rb b/lib/smart_proxy_container_gateway/container_gateway_api.rb index 0ad12b3..dc4641b 100644 --- a/lib/smart_proxy_container_gateway/container_gateway_api.rb +++ b/lib/smart_proxy_container_gateway/container_gateway_api.rb @@ -90,10 +90,10 @@ class Api < ::Sinatra::Base end get '/v1/search/?' do - # Checks for podman client and issues a 404 in that case. Podman + # Checks for v2 client and issues a 404 in that case. Podman # examines the response from a /v1/search request. If the result # is a 4XX, it will then proceed with a request to /_catalog - if !request.env['HTTP_USER_AGENT'].nil? && request.env['HTTP_USER_AGENT'].downcase.include?('libpod') + if request.env['HTTP_DOCKER_DISTRIBUTION_API_VERSION'] == 'registry/2.0' halt 404, "not found" end diff --git a/test/container_gateway_api_test.rb b/test/container_gateway_api_test.rb index d7202f1..a6e121c 100644 --- a/test/container_gateway_api_test.rb +++ b/test/container_gateway_api_test.rb @@ -193,6 +193,12 @@ def test_put_repository_list assert last_response.ok? end + def test_v1_search_v2_client + header 'DOCKER_DISTRIBUTION_API_VERSION', 'registry/2.0' + get '/v1/search' + assert last_response.status == 404 + end + def test_v1_search_with_user user_id = @database.connection[:users].insert(name: 'test_user') catalog = ["test_repo"] @@ -210,7 +216,7 @@ def test_v1_search_with_user } ).to_return(:body => foreman_auth_response.to_json) - header 'HTTP_USER_AGENT', 'notpodman' + header 'DOCKER_DISTRIBUTION_API_VERSION', 'registry/1.0' # Basic test_user:test_password header "AUTHORIZATION", "Basic dGVzdF91c2VyOnRlc3RfcGFzc3dvcmQ=" @@ -224,7 +230,7 @@ def test_v1_search_with_no_user @container_gateway_main.expects(:catalog).with(nil).returns(catalog) catalog.expects(:limit).returns(catalog) catalog.expects(:select_map).returns(catalog) - header 'HTTP_USER_AGENT', 'notpodman' + header 'DOCKER_DISTRIBUTION_API_VERSION', 'registry/1.0' get '/v1/search' assert last_response.ok? assert_equal [{ "description" => "", "name" => "test_repo" }].sort, JSON.parse(last_response.body)["results"].sort