-
Notifications
You must be signed in to change notification settings - Fork 638
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
Conversation
} | ||
if !found { | ||
return fmt.Errorf("invalid descriptor MediaType %q", d.MediaType) | ||
} |
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.
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 comment
The 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 comment
The reason will be displayed to describe this comment to others. Learn more.
You can just exit in line. No need for flag variable.
I like this 👍 |
@runcom @coolljt0725 well, it is just my private custom, which brings little benefit. |
/cc @vbatts |
Signed-off-by: Antonio Murdaca <runcom@redhat.com>
Signed-off-by: Antonio Murdaca <runcom@redhat.com>
Signed-off-by: Antonio Murdaca <runcom@redhat.com>
Signed-off-by: Antonio Murdaca <runcom@redhat.com>
rebased! |
1 similar comment
On Tue, Sep 06, 2016 at 01:28:02AM -0700, Antonio Murdaca wrote:
This commit should also replace the current ‘descriptor’ (in |
@@ -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 { |
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 of ValidateDescriptor
(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:
$ oci-image-tool validate --recursive --unpackable image.tar $VALID_MANIFEST_REF
$ oci-image-tool validate --unpackable image.tar $BUSTED_ANCESTOR_MANIFEST_REF
$ oci-image-tool validate --recursive image.tar $VALID_LAYER_REF
$ oci-image-tool validate --recursive image.tar $VALID_CONFIG_REF
$ oci-image-tool validate image.tar $VALID_MANIFEST_REF
$ oci-image-tool validate image.tar $BUSTED_ANCESTOR_MANIFEST_REF
$ oci-image-tool validate image.tar $VALID_LAYER_REF
$ oci-image-tool validate image.tar $VALID_CONFIG_REF
and the following all fail:
$ oci-image-tool validate --recursive --unpackable image.tar $BUSTED_ANCESTOR_MANIFEST_REF
$ oci-image-tool validate --recursive --unpackable image.tar $VALID_LAYER_REF
$ oci-image-tool validate --recursive --unpackable image.tar $VALID_CONFIG_REF
$ oci-image-tool validate --unpackable image.tar $VALID_LAYER_REF
$ oci-image-tool validate --unpackable image.tar $VALID_CONFIG_REF
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:
@@ -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 {Isn't it better to open another issue tracking this?
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.
On Wed, Sep 07, 2016 at 12:05:13AM -0700, Antonio Murdaca wrote:
If you don't feel like covering it in this PR, it can land with #159,
#159 has floated for a lot longer than I'd initial expected. I may |
@runcom LGTM 👍 |
Fix #260
/cc @coolljt0725 @s-urbaniak @xiekeyang