mirror of
https://github.com/containerd/containerd.git
synced 2026-08-13 17:07:26 +00:00
chore: Add explicit digest requirement to docker pusher
The `push` function below assumes that digest and mediatypes are populated and set. If they aren't, then the requests made are malformed, attempting to invoke `HEAD /blobs/` (instead of `HEAD /blobs/<digest>`). Additionally, if we *were* to move past this point, we'd then populate an empty digest in the query parameter, and even provide invalid HTTP mediatypes. However, the `WithDescriptor` `WriterOpt` specifically notes that "Write does not require any field of desc to be set". It's very easy for the caller to read this as an optional field, to skip it, and then get confusing HTTP errors from inside the `push` function. We can avoid this by explicitly validating that the descriptor is valid and provide early feedback. Signed-off-by: Justin Chadwell <me@jedevc.com>
This commit is contained in:
committed by
Maksym Pavlenko
parent
c4f7fa1dd2
commit
4f35b756e2
@@ -60,6 +60,12 @@ func (p dockerPusher) Writer(ctx context.Context, opts ...content.WriterOpt) (co
|
||||
if wOpts.Ref == "" {
|
||||
return nil, fmt.Errorf("ref must not be empty: %w", errdefs.ErrInvalidArgument)
|
||||
}
|
||||
if wOpts.Desc.Digest == "" {
|
||||
return nil, fmt.Errorf("descriptor digest must not be empty: %w", errdefs.ErrInvalidArgument)
|
||||
}
|
||||
if wOpts.Desc.MediaType == "" {
|
||||
return nil, fmt.Errorf("descriptor media type must not be empty: %w", errdefs.ErrInvalidArgument)
|
||||
}
|
||||
return p.push(ctx, wOpts.Desc, wOpts.Ref, true)
|
||||
}
|
||||
|
||||
|
||||
Reference in New Issue
Block a user