Skip to content

Commit

Permalink
Fixes #38103 - disallow direct container tar uploads
Browse files Browse the repository at this point in the history
  • Loading branch information
ianballou committed Dec 13, 2024
1 parent b551d41 commit c35b116
Show file tree
Hide file tree
Showing 3 changed files with 8 additions and 1 deletion.
Original file line number Diff line number Diff line change
Expand Up @@ -15,6 +15,7 @@ class Api::V2::ContentUploadsController < Api::V2::ApiController
param :content_type, RepositoryTypeManager.uploadable_content_types(false).map(&:label), :required => false, :desc => N_("content type ('deb', 'docker_manifest', 'file', 'ostree_ref', 'rpm', 'srpm')")
def create
fail Katello::Errors::InvalidRepositoryContent, _("Cannot upload Ansible collections.") if @repository.ansible_collection?
fail Katello::Errors::InvalidRepositoryContent, _("Cannot upload container content via Hammer/API. Use podman push instead.") if @repository.docker?
content_type = params[:content_type] || ::Katello::RepositoryTypeManager.find(@repository.content_type)&.default_managed_content_type&.label
RepositoryTypeManager.check_content_matches_repo_type!(@repository, content_type)
if ::Katello::RepositoryTypeManager.generic_content_type?(content_type)
Expand Down
1 change: 0 additions & 1 deletion lib/katello/repository_types/docker.rb
Original file line number Diff line number Diff line change
Expand Up @@ -27,7 +27,6 @@
:priority => 1,
:pulp3_service_class => ::Katello::Pulp3::DockerManifest,
:removable => true,
:uploadable => true,
:primary_content => true
content_type Katello::DockerManifestList,
:priority => 2,
Expand Down
7 changes: 7 additions & 0 deletions test/controllers/api/v2/content_uploads_controller_test.rb
Original file line number Diff line number Diff line change
Expand Up @@ -46,6 +46,13 @@ def test_create_generic_upload_request
assert_response :success
end

def test_create_container_upload_request
container_repo = katello_repositories(:busybox)
post :create, params: { :repository_id => container_repo.id, :size => 100, :checksum => 'test_checksum2' }
assert_response :error
assert_match 'Cannot upload container content via Hammer/API. Use podman push instead.', @response.body
end

def test_create_collection_upload_request
ansible_collection_repo = katello_repositories(:pulp3_ansible_collection_1)
post :create, params: { :repository_id => ansible_collection_repo.id, :size => 100, :checksum => 'test_checksum' }
Expand Down

0 comments on commit c35b116

Please sign in to comment.