Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

fix(clean): Fix clean cmd for private registries #3446

Merged
merged 1 commit into from
Jan 4, 2024

Conversation

cmurphy
Copy link
Contributor

@cmurphy cmurphy commented Dec 18, 2023

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:

DELETE /v2/namespace/repo/manifests/sha256-deadbeef.sig

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:

GET /v2/namespace/repo/manifests/sha256-deadbeef.sig
=> ... Docker-Content-Digest: sha256:cafeb0ba
DELETE /v2/namespace/repo/manifests/sha256:cafeb0ba

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

Copy link

codecov bot commented Dec 18, 2023

Codecov Report

Attention: 24 lines in your changes are missing coverage. Please review.

Comparison is base (da53b08) 30.23% compared to head (9d43875) 29.88%.
Report is 37 commits behind head on main.

Files Patch % Lines
cmd/cosign/cli/clean.go 0.00% 21 Missing ⚠️
pkg/oci/remote/remote.go 62.50% 2 Missing and 1 partial ⚠️
Additional details and impacted files
@@            Coverage Diff             @@
##             main    #3446      +/-   ##
==========================================
- Coverage   30.23%   29.88%   -0.35%     
==========================================
  Files         155      155              
  Lines        9958    10004      +46     
==========================================
- Hits         3011     2990      -21     
- Misses       6497     6581      +84     
+ Partials      450      433      -17     

☔ View full report in Codecov by Sentry.
📢 Have feedback on the report? Share it here.

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:

```
DELETE /v2/namespace/repo/manifests/sha256-deadbeef.sig
```

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:

```
GET /v2/namespace/repo/manifests/sha256-deadbeef.sig
=> ... Docker-Content-Digest: sha256:cafeb0ba
DELETE /v2/namespace/repo/manifests/sha256:cafeb0ba
```

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 sigstore#2265

Signed-off-by: Colleen Murphy <colleenmurphy@google.com>
Copy link
Contributor

@haydentherapper haydentherapper left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Looks great!

@imjasonh Did you have any comments?

@haydentherapper haydentherapper merged commit 286a98a into sigstore:main Jan 4, 2024
28 checks passed
@github-actions github-actions bot added this to the v2.3.0 milestone Jan 4, 2024
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

Successfully merging this pull request may close these issues.

Cosign Clean Response is "DIGEST_INVALID: provided digest did not match uploaded content"
2 participants