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

ggcr: remote.Referrers returns http not found error directly #1647

Closed
otms61 opened this issue Apr 15, 2023 · 0 comments · Fixed by #1648
Closed

ggcr: remote.Referrers returns http not found error directly #1647

otms61 opened this issue Apr 15, 2023 · 0 comments · Fixed by #1648
Labels
bug Something isn't working

Comments

@otms61
Copy link
Contributor

otms61 commented Apr 15, 2023

Describe the bug

When fetching referrers in an OCI registry that does not support the referrers API, an error is returned before handling the exception for errors in retrieving referrers.

When trying to get referrers for an image with no referrers, an transport.Error error is returned directly.

// The registry doesn't support the Referrers API endpoint, so we'll use the fallback tag scheme.
b, _, err := f.fetchManifest(ctx, fallbackTag(d), []types.MediaType{types.OCIImageIndex})
if err != nil {
return nil, err
}
var terr *transport.Error
if ok := errors.As(err, &terr); ok && terr.StatusCode == http.StatusNotFound {
// Not found just means there are no attachments yet. Start with an empty manifest.
return &v1.IndexManifest{MediaType: types.OCIImageIndex}, nil
}
var im v1.IndexManifest
if err := json.Unmarshal(b, &im); err != nil {
return nil, err
}

To Reproduce

call remote.Referrers on an image with the following conditions:

  • registered in an OCI registry that does not support the referrers API
  • the image has no referrers

For further details, see the test in the following PR:
#1648

Expected behavior

Return an empty manifest when the OCI registry returns a 404.

Additional context

I've been developing a tool that uses referrers API. I noticed that I need extra error handling when fetching referrers for an OCI registry that does not support referrers API.

aquasecurity/trivy-plugin-referrer#7

@otms61 otms61 added the bug Something isn't working label Apr 15, 2023
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
bug Something isn't working
Projects
None yet
Development

Successfully merging a pull request may close this issue.

1 participant