-
Notifications
You must be signed in to change notification settings - Fork 677
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
oci-image-tool: validate descriptors MediaType #262
Changes from all commits
File filter
Filter by extension
Conversations
Jump to
Diff view
Diff view
There are no files selected for viewing
Original file line number | Diff line number | Diff line change |
---|---|---|
|
@@ -73,7 +73,17 @@ func findDescriptor(w walker, name string) (*descriptor, error) { | |
} | ||
} | ||
|
||
func (d *descriptor) validate(w walker) error { | ||
func (d *descriptor) validate(w walker, mts []string) error { | ||
var found bool | ||
for _, mt := range mts { | ||
if d.MediaType == mt { | ||
found = true | ||
break | ||
} | ||
} | ||
if !found { | ||
return fmt.Errorf("invalid descriptor MediaType %q", d.MediaType) | ||
} | ||
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. if inner func is better here? if !func(dmt string, mts []string) bool {
for _, mt := range mts {
if dmt == mt {
return true
}
}
return false
}(d.MediaType, mts) {
return fmt.Errorf("invalid descriptor MediaType %q", d.MediaType)
} There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. I honestly don't like it, happy to change it if the majority thinks otherwise, I don't like it cause it isn't readable as the plain version I wrote There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. You can just exit in line. No need for flag variable. |
||
switch err := w.walk(func(path string, info os.FileInfo, r io.Reader) error { | ||
if info.IsDir() { | ||
return nil | ||
|
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
I don't think this is the right API. There interesting descriptor-validation cases for each descriptor property:
a. The referenced blob is exists in (or is missing from) CAS (
digest
).b. The media type can (or cannot) be validated by this package (
mediaType
).c. The referenced blob exists in CAS with the right (or wrong) size (
size
).Those also apply recursively, if you want to walk the Merkle tree of blob ancestors.
If the user wants to validate a descriptor, they should just be able to call
image.ValidateDescriptor(walker, descriptor, recursive)
or some such. If they also want to restrict the media type of the root descriptor, they can do that outside ofValidateDescriptor
(because there's not a convenient way to specify those restrictions recursively, i.e. “if an ancestor contains a manifest, only allow layer types from {set}”).If you have an image-layout with a ref with an image/png media type pointing to a valid PNG blob, I
oci-image-tool validate image.tar png-ref
could do any of:i. Print something like “unrecognized media type 'image/png'" and exit nonzero (“I don't know”).
ii. Confirm that the referenced blob is a PNG of the right size and exit zero (“This is valid”).
iii. Print something like “invalid media type 'image/png'" and exit nonzero (“This is not valid”).
It is a valid reference (so (i) and (ii) are ok, but (iii) is not). The PNG is just not a reference that
oci-image-tool unpack
can handle. I think the right API for that is to have a separate “unpackable” check bound to a flag. So the following all pass:and the following all fail:
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Isn't it better to open another issue tracking this?
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
On Wed, Sep 07, 2016 at 12:00:38AM -0700, Antonio Murdaca wrote:
You're adding ‘mts’ here, and I don't think we want it ;). If folks
feel like the rest of this PR is a step forward, I'm ok with this
landing and me filing a subsequent PR to roll this part back out in
favor of --unpackable.