fix(clean): Fix clean cmd for private registries #3446
Merged
Add this suggestion to a batch that can be applied as a single commit.
This suggestion is invalid because no changes were made to the code.
Suggestions cannot be applied while the pull request is closed.
Suggestions cannot be applied while viewing a subset of changes.
Only one suggestion per line can be applied in a batch.
Add this suggestion to a batch that can be applied as a single commit.
Applying suggestions on deleted lines is not supported.
You must change the existing code in this line in order to create a valid suggestion.
Outdated suggestions cannot be applied.
This suggestion has been applied or marked resolved.
Suggestions cannot be applied from pending reviews.
Suggestions cannot be applied on multi-line comments.
Suggestions cannot be applied while the pull request is queued to merge.
Suggestion cannot be applied right now. Please check back later.
Without this patch, running
cosign clean
on an image in a private registry uses the wrong object reference and fails to delete artifacts for the image.On Dockerhub, it is sufficient to call DELETE directly on an object name:
On registry version v2.3 and greater, this does not work. Instead, we need to perform a GET to retrieve the object digest, and call DELETE on that:
Since we can't know what type of registry we're dealing with, we try the original version first, and the new version as a fallback.
See the GitHub issue[1] which explains the issue, and the API documentation[2].
This also fixes a minor formatting issue in the error message.
[1] distribution/distribution#1579
[2] https://github.com/distribution/distribution/blob/main/docs/content/spec/api.md#deleting-an-image
Fixes #2265
Summary
See above
Release Note
Fixed the "clean" command for private registries.
Documentation
n/a