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

Add index.json validation #51

Merged
merged 3 commits into from
Jul 21, 2017
Merged

Conversation

zhouhao3
Copy link

if the ManifestList exists, it needs to be validated
Signed-off-by: zhouhao zhouhao@cn.fujitsu.com

@zhouhao3 zhouhao3 force-pushed the test-mlist branch 2 times, most recently from 13a1d21 to bf107ce Compare October 25, 2016 09:10
@vbatts
Copy link
Member

vbatts commented Oct 25, 2016

LGTM
for a first pass

Copy link
Contributor

@wking wking left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

The validation approach here is strange. Instead of:

  1. Walk from the initial descriptor to a manifest, validating the manifest if you find one.
  2. Walk from the initial descriptor to a manifest list, validating the manifest list if you find one.
  3. Walk from the initial descriptor to …

I'd rather land opencontainers/image-spec#403 and use:

  1. Get an initial descriptor.
  2. Fetch the object referenced by the descriptor.
  3. Run the appropriate intra-blob validation on it (schema: Use Validators map and prepare to extend beyond JSON Schema image-spec#403).
  4. For any children referenced from the blob, recurse to (2).

return nil
}

func checkPlatform(m Manifests) error {
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

The consensus seems to be that this sort of intra-JSON-blob validation should live in image-spec.

Platform Platform `json:"platform"`
}

func findManifest_list(w walker, d *descriptor) (*manifest_list, error) {
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Mixing camelCase and underscores is strange. This should probably be findManifestList, although now that we have #29's (r *tarReader) Get and will hopefully soon have #5's CAS engine, I don't see much point to the find* functions.


func (ml *manifestlist) validate(w walker) error {
for _, d := range ml.Manifests {
if err := d.Descriptor.validate(w, []string{v1.MediaTypeImageConfig}); err != nil {
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

This is currently raising:

d.Descriptor.validate undefined (type "github.com/opencontainers/image-tools/vendor/github.com/opencontainers/image-spec/specs-go".Descriptor has no field or method validate)

That's because this repo currently defines it's own descriptor type which has a validate method, but you're using the spec's Descriptor which does not have that method. Validating descriptors will become easier with opencontainers/image-spec#403, but until then you'll want to convert your image-spec Descriptor to an image-tools descriptor before calling the local validate method.

Copy link
Author

@zhouhao3 zhouhao3 Oct 31, 2016

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

But the manifest also have spec's Descriptor, it can use validate ,I think as long as the manifest file to the Descriptor as specific, you can call.

@wking
Copy link
Contributor

wking commented Oct 28, 2016

The ManifestsManifestDescriptor change has hidden my earlier comment, but I think it's important enough to re-post with more visibility:

The consensus seems to be that this sort of intra-JSON-blob validation should live in image-spec. So I think checkPlatform belongs in image-spec, and not here.

@coolljt0725
Copy link
Member

@q384566678 build failed

image/image.go:98: cannot use err (type error) as type string in argument to strings.Contains
image/manifest_list.go:37: undefined: io in io.Reader
image/manifest_list.go:42: undefined: ioutil in ioutil.ReadAll
image/manifest_list.go:47: undefined: bytes in bytes.NewReader
image/manifest_list.go:72: d.Descriptor.validate undefined (type "github.com/opencontainers/image-tools/vendor/github.com/opencontainers/image-spec/specs-go".Descriptor has no field or method validate)

@zhouhao3
Copy link
Author

I know,I'm trying to fix that @coolljt0725

@wking
Copy link
Contributor

wking commented Oct 31, 2016

On Mon, Oct 31, 2016 at 01:54:49AM -0700, Zhou Hao wrote:

  • if err := d.Descriptor.validate(w, []string{v1.MediaTypeImageConfig}); err != nil {
    

But the manifest also have spec's
Descriptor
,
it can use
validate
,I think as long as the manifest file to the Descriptor as specific,
you can call.

That validate call is using the image-tools-specific manifest 1,
which uses the image-tools-specific descriptor 2. I don't think
image-tools-specific types are a good pattern to follow, but you'll
need to convert v1.Descriptors to image-tools-specific descriptors
before you can call the image-tools-specific-descriptor's Validate
3. Ideally these would all be functions that took the image-spec
types.

@zhouhao3 zhouhao3 force-pushed the test-mlist branch 2 times, most recently from c1c6538 to 0317d75 Compare November 1, 2016 06:52
image/image.go Outdated
return err
}
} else {
if !strings.Contains(string(err), "manifestlist not found") {
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

At the moment, the manifest list is OPTIONAL(https://github.com/opencontainers/image-spec/blob/master/manifest-list.md#oci-image-manifest-list-specification) , so we should not error out if there is no manifest list

Copy link
Author

@zhouhao3 zhouhao3 Nov 1, 2016

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Yes, I was in accordance with the idea to write, I first made a judgment on the error message, if it is because there is no manifest list and return, not error out.(There is one“!” symbol follows the if)

image/image.go Outdated
return err
}
}

if out != nil {
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Should we findManifestList first and if manifest_list exists, then extract the manifest from the manifest_list and then validate the manifest?

I +1 with @wking 's proposal

I'd rather land opencontainers/image-spec#403 and use:

Get an initial descriptor.
Fetch the object referenced by the descriptor.
Run the appropriate intra-blob validation on it (opencontainers/image-spec#403).
For any children referenced from the blob, recurse to (2).

@zhouhao3 zhouhao3 force-pushed the test-mlist branch 5 times, most recently from 17713f4 to d38a4ba Compare November 2, 2016 07:13
Copy link
Member

@coolljt0725 coolljt0725 left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

You need to fix the exist test:

  1. createRefFile needs to point to the manifest list
  2. add a createManifestlistFile to add a manifest list blob which contains the manifest.

image/image.go Outdated
@@ -87,6 +87,16 @@ func validate(w walker, refs []string, out *log.Logger) error {
if err := m.validate(w); err != nil {
return err
}

ml, err := findManifestList(w, d)
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

This seems not correct, findManifestList(w, d) here just assume the d is a manifest list, but actually, d could be manifest or manifest list. This is why the test failed.

--- FAIL: TestValidateLayout (0.03s)
    image_test.go:175: blobs/sha256/3b6be0edf862ac9e6e790fb010cf26770d9ab266f3ff81b5b82f0cf8d6f7d1a6: manifestlist validation failed: [manifests: manifests is required]

I think we should check the d after d.validate(w, validRefMediaTypes), if it is a manifest, then go to findManifest, if it is a manifest list, then go to findManifestList

Copy link
Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Nice,I will do that.Thank you for your suggestion.

@zhouhao3 zhouhao3 force-pushed the test-mlist branch 3 times, most recently from 77f3953 to 052ade8 Compare November 4, 2016 06:56
@coolljt0725
Copy link
Member

test failed

go test -race -cover github.com/opencontainers/image-tools/cmd/oci-create-runtime-bundle github.com/opencontainers/image-tools/cmd/oci-image-validate github.com/opencontainers/image-tools/cmd/oci-unpack github.com/opencontainers/image-tools/image
?       github.com/opencontainers/image-tools/cmd/oci-create-runtime-bundle [no test files]
?       github.com/opencontainers/image-tools/cmd/oci-image-validate    [no test files]
?       github.com/opencontainers/image-tools/cmd/oci-unpack    [no test files]
--- FAIL: TestValidateLayout (0.03s)
    image_test.go:175: blobs/sha256/f175ad817b1c75958e74e224f57b17d3a3e746bc434737b1bde837dbe7d33409: manifest validation failed: [config: config is required layers: layers is required]
FAIL
coverage: 29.3% of statements
FAIL    github.com/opencontainers/image-tools/image 0.096s
make: *** [test] Error 1

@zhouhao3 zhouhao3 force-pushed the test-mlist branch 2 times, most recently from a622eaf to 428027f Compare July 17, 2017 07:31
@zhouhao3
Copy link
Author

@vbatts @coolljt0725 @cyphar @xiekeyang @stevvooe @jonboulle I updated test file, PTAL.

@@ -95,5 +97,9 @@ var createCommand = cli.Command{
Value: "rootfs",
Usage: "A directory representing the root filesystem of the container in the OCI runtime bundle. It is strongly recommended to keep the default value.",
},
cli.StringSliceFlag{
Name: "platform",
Usage: "The platform contains os and arch. Filter manifests according to the conditions provided. Only applicable if reftype is index.",
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I still don't know how to use this from this description. Is there an example?

@@ -20,6 +20,11 @@ oci-image-tool unpack \- Unpack an image or image source layout
**--type**=""
Type of the file to unpack. If unset, oci-image-tool will try to auto-detect the type. One of "imageLayout,image"

**--platform**=""
Specify the os and architecture of the manifest, format is OS:Architecture.
e.g. --platform linux:amd64
Copy link
Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

@stevvooe I have modified the introduction of information and added examples. PTAL

@zhouhao3
Copy link
Author

reping @opencontainers/image-tools-maintainers

@cyphar
Copy link
Member

cyphar commented Jul 18, 2017

Just to make sure, if I want to validate an entire image with ./oci-image-tool validate --type imageLayout it will still work? In other words, is the --platform filter the same as the --ref filter in that they don't filter anything if you don't specify them?

image/image.go Outdated
return manifests, nil
}

if len(platform) != 2 {
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Either this should be checked far earlier (when you do the splitting) or you should only split it here. I would prefer if you just passed the string down to filterManifest and then you verify the arguments here.

Copy link
Author

@zhouhao3 zhouhao3 Jul 18, 2017

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

updated.Thanks for your advice.

@zhouhao3
Copy link
Author

Just to make sure, if I want to validate an entire image with ./oci-image-tool validate --type imageLayout it will still work?

Yes.

In other words, is the --platform filter the same as the --ref filter in that they don't filter anything if you don't specify them?

Yes, just to filter the manifest in certain circumstances.

@cyphar
Copy link
Member

cyphar commented Jul 18, 2017

LGTM, thanks.

Approved with PullApprove

@zhouhao3
Copy link
Author

ping @coolljt0725 @xiekeyang @stevvooe

@xiekeyang
Copy link
Contributor

xiekeyang commented Jul 19, 2017

LGTM

It is OK from my side, PTAL from others.

Approved with PullApprove

@zhouhao3
Copy link
Author

If someone else has no objection, I will merge it tomorrow.

zhouhao added 2 commits July 20, 2017 14:34
Signed-off-by: zhouhao <zhouhao@cn.fujitsu.com>
Signed-off-by: zhouhao <zhouhao@cn.fujitsu.com>
Signed-off-by: zhouhao <zhouhao@cn.fujitsu.com>
@zhouhao3
Copy link
Author

@cyphar @xiekeyang @coolljt0725 rebased, PTAL, thanks

@zhouhao3
Copy link
Author

reping @vbatts @coolljt0725 @xiekeyang @cyphar @stevvooe PTAL

@xiekeyang
Copy link
Contributor

xiekeyang commented Jul 21, 2017

LGTM

Approved with PullApprove

@cyphar
Copy link
Member

cyphar commented Jul 21, 2017

LGTM.

Approved with PullApprove

@cyphar cyphar merged commit 3c7c0e7 into opencontainers:master Jul 21, 2017
cyphar added a commit that referenced this pull request Jul 21, 2017
@zhouhao3 zhouhao3 deleted the test-mlist branch July 21, 2017 04:09
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Projects
None yet
Development

Successfully merging this pull request may close these issues.

7 participants