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

oci-image-tool: validate descriptors MediaType #262

Merged
merged 4 commits into from
Sep 7, 2016

Conversation

runcom
Copy link
Member

@runcom runcom commented Sep 6, 2016

}
if !found {
return fmt.Errorf("invalid descriptor MediaType %q", d.MediaType)
}
Copy link
Contributor

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)
}

Copy link
Member Author

@runcom runcom Sep 6, 2016

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

Copy link
Contributor

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.

@coolljt0725
Copy link
Member

I like this 👍

@xiekeyang
Copy link
Contributor

xiekeyang commented Sep 6, 2016

@runcom @coolljt0725 well, it is just my private custom, which brings little benefit.

@runcom
Copy link
Member Author

runcom commented Sep 6, 2016

/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>
@runcom
Copy link
Member Author

runcom commented Sep 6, 2016

rebased!

@philips
Copy link
Contributor

philips commented Sep 6, 2016

LGTM

Approved with PullApprove

1 similar comment
@stevvooe
Copy link
Contributor

stevvooe commented Sep 6, 2016

LGTM

Approved with PullApprove

@wking
Copy link
Contributor

wking commented Sep 7, 2016

On Tue, Sep 06, 2016 at 01:28:02AM -0700, Antonio Murdaca wrote:

  • *: use types from specs-go/

This commit should also replace the current ‘descriptor’ (in
image/descriptor.go) with Descriptor (from specs-go/descriptor.go).
In #159, I do that in f2dc0e2 (replacing descriptor.validate with
validateDescriptor, although eventually we'll want a public function
for descriptor validation). That commit is also doing a lot of
walker→engine replacing, but feel free to borrow anything that helps
with descriptor→Descriptor replacing.

@@ -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 {
Copy link
Contributor

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

Copy link
Member Author

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?

Copy link
Contributor

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.

@runcom
Copy link
Member Author

runcom commented Sep 7, 2016

@wking, can we not block PRs if you already took care of using the right descriptor struct in your PR? Also, it's better to have a new PR altogether instead of embedding that in #159.

@wking
Copy link
Contributor

wking commented Sep 7, 2016

On Wed, Sep 07, 2016 at 12:05:13AM -0700, Antonio Murdaca wrote:

@wking, can we not block PRs if you already took care of using the
right descriptor struct in your PR?

If you don't feel like covering it in this PR, it can land with #159,
or via some other followup PR, or never ;). No big deal. It just
seemed like a natural fit for a “use types from specs-go” commit.

Also, it's better to have a new PR altogether instead of embedding
that in #159.

#159 has floated for a lot longer than I'd initial expected. I may
start splitting off smaller shifts like that, but I really don't like
walkers, so I'm trying to avoid touching them ;).

@s-urbaniak
Copy link
Collaborator

@runcom LGTM 👍

@vbatts
Copy link
Member

vbatts commented Sep 7, 2016

LGTM

Approved with PullApprove

@vbatts vbatts merged commit 9a93cca into opencontainers:master Sep 7, 2016
@runcom runcom deleted the fixies branch September 7, 2016 19:42
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.

8 participants