-
Notifications
You must be signed in to change notification settings - Fork 83
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
validate media type of manifest and its descendants #10
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 |
---|---|---|
|
@@ -51,7 +51,7 @@ func findManifest(w walker, d *descriptor) (*manifest, error) { | |
return errors.Wrapf(err, "%s: error reading manifest", path) | ||
} | ||
|
||
if err := schema.MediaTypeManifest.Validate(bytes.NewReader(buf)); err != nil { | ||
if err := ValidateManifestMediaType(bytes.NewReader(buf)); err != nil { | ||
return errors.Wrapf(err, "%s: manifest validation failed", path) | ||
} | ||
|
||
|
@@ -240,3 +240,33 @@ loop: | |
} | ||
return nil | ||
} | ||
|
||
// ValidateManifestMediaType validate the manifest schema media-type | ||
// and its descendants fields media type, such as config and layers, | ||
// to make sure they match to spec definition, or returns an error if | ||
// the validation failed. | ||
func ValidateManifestMediaType(r io.Reader) error { | ||
header := v1.Manifest{} | ||
|
||
buf, err := ioutil.ReadAll(r) | ||
if err != nil { | ||
return errors.Wrapf(err, "error reading the io stream") | ||
} | ||
|
||
err = json.Unmarshal(buf, &header) | ||
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. There is still no reason to read
And we all agreed that the
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. But if that we will meet the problem [1] that reader(pointer) is seek to end, and the next using reader is failed of EOF. How to avoid this? [1] #10 (comment) |
||
if err != nil { | ||
return errors.Wrap(err, "manifest format mismatch") | ||
} | ||
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 want an error-checked call to 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. fixed. 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 header.Config.MediaType != string(v1.MediaTypeImageConfig) { | ||
return fmt.Errorf("illegal config mediaType: %s", header.Config.MediaType) | ||
} | ||
|
||
for _, layer := range header.Layers { | ||
if layer.MediaType != string(v1.MediaTypeImageLayer) { | ||
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. This is probably way to strict. I'm not sure these media types are "illegal". |
||
return fmt.Errorf("illegal layer mediaType: %s", layer.MediaType) | ||
} | ||
} | ||
|
||
return schema.MediaTypeManifest.Validate(bytes.NewReader(buf)) | ||
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. The above function should be covered by this 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 seems to mean {
"annotations": null,
"config": {
"digest": "sha256:2b8fd9751c4c0f5dd266fcae00707e67a2545ef34f9a29354585f93dac906749",
"mediaType": "foo",
"size": 1459
},
"layers": [
{
"digest": "sha256:8ddc19f16526912237dd8af81971d5e4dd0587907234be2b83e249518d5b673f",
"mediaType": "bar",
"size": 667590
}
],
"mediaType": "application/vnd.oci.image.manifest.v1+json",
"schemaVersion": 2
}
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 don't see how this code is checking descendants. It decodes the manifest, then checks the mediatypes of the layers. It looks like there is a bug in the validation. Go fix that rather than just adding more code. 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. @stevvooe {
"mediaType": {
"id": "https://opencontainers.org/schema/image/mediaType",
"type": "string",
"pattern": "^[a-z]+/[0-9a-zA-Z.+]+$"
}
} JSON schema is third party to image tools, and we just want to fix bug for implementor tool. So we select to fix it here. 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 json schema doesn't meet our validation needs, we need to drop it. Adding a new function is not the right way to fix it. It is just adding extra code. The |
||
} |
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 see a reason to expose media-type validation as a separate thing. There's just “validation”, which includes checking media types against spec requirements as well as checking other parameter values against spec requirements. That probably means we want a comparison with the appropriate JSON Schema (to catch things like
schemaVersion
is unset) and additional checks for cases not covered by JSON Schema (e.g.schemaVersion != 2
). But I don't think a caller will care about picking and choosing particular subsets of validation.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.
However, validate command will call
schema.MediaTypeManifestList.Validate()
directly when validating signal manifest file. I think it is an efficient method to wrap descendants and schema checking in one function(ValidateManifestMediaType
).The callers are image layout validation and manifest file validation. According to current calling subsequence, they are checking schema. I present the new function to add descendants checking, make it efficient, and keep current checked subsets un-lost.
Am I missing something?
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.
With the call to
schema.MediaTypeManifest.Validate
at the end of this function, the name should probably just beValidateManifest
(since it covers descriptor media types locally and the JSON Schema viaschema.MediaTypeManifest.Validate
.