Skip to content

Conversation

@mtrmac
Copy link
Collaborator

@mtrmac mtrmac commented Oct 6, 2016

@runcom PTAL.

This is a pretty big refactoring of image/, see individual commits for details. The overall ideas:

  • Signature verification happens on UnparsedImage, which structurally prevents interpreting too much before we know the image is admissible.
  • genericImage becomes sourcedImage, a very thin layer over UnparsedImage and genericManifest
  • Instead of UpdatedManifest, we now have UpdatedImage. This does not change much now, but will be a way to return also config.json and other objects.

I haven’t actually updated the schema conversion work to take advantage of UpdatedImage yet, but I expect it to help with the API shape noticeably.

Tests pass in https://github.com/mtrmac/skopeo/tree/image-refactor-test , although note that that includes mtrmac@364c110 as a defeat device for #115, not to be merged.

@runcom
Copy link
Member

runcom commented Oct 7, 2016

👍 I like these distinctions

Approved with PullApprove

mtrmac added 11 commits October 11, 2016 13:00
In particular, do not even look at the manifest type; we might not event
want to fetch the manifest if required signatures are missing, so
loading it and possibly guessing the MIME type is not needed either.

Signed-off-by: Miloslav Trmač <[email protected]>
Currently we use a types.Image, which supports lots of parsing, for
verification processing in in signature.PolicyContext.

In the future, we will want that types.Image to do significantly more
processing at initialization time (e.g. determine manifest type and
fully parse it), which is undesirable for signature verification
— there we would _really_ prefer to first find a signature which
cryptographically verifies, before even _downloading_ the manifest,
let alone processing it in any way.

So, split the minimum functionality desired for processing unsigned
images (manifest and signature caching) into a separate UnparsedImage
type.

Right now, this does not affect any Image or UnparsedImage
implementation (apart from dropping a few panic()ing mock functions).

(Note that for some more advanced processing, signature/* may create a
types.Image out of the given types.UnparsedImage in the future — but
that would be an intentional action after the signature code determines
that there is enough presumed trust to even start parsing anything.)

Signed-off-by: Miloslav Trmač <[email protected]>
Now that types.UnparsedImage is split from types.Image, also split the
implementations.  In particular, copy.Image uses an UnparsedImage for
signature verification.

This structural separation allows us to remove the “It is essential for
signature verification”… comments all over the place in favor of a
single one in the choke point where an UnparsedImage turns into a full
genericImage.

Also, split the manifest type guessing (which involves parsing) so that
it does not happen in UnparsedImage.  This needs ugly fields like
trueManifestMIMETypeSet, which will go away momentarily.

Signed-off-by: Miloslav Trmač <[email protected]>
image/manifest.go now contains genericManifest without caring about
genericImage, and image/image.go contains genericImage only.

Signed-off-by: Miloslav Trmač <[email protected]>
Just a bit of pointless pedantry, sorry :)

Signed-off-by: Miloslav Trmač <[email protected]>
This means that image.FromUnparsedImage can now fail, OTOH later methods
which refer to a manifest cannot.  This is an intermediate step to also
parsing the manifest at that time already.

Signed-off-by: Miloslav Trmač <[email protected]>
…Image

Another step towards simplifying the types.Image/genericManifest
relationship: Now every genericImage always has a genericManifest.

Signed-off-by: Miloslav Trmač <[email protected]>
Update types.Image to drop unnecessary error return values, and modify
genericManifest to be more suitable; then embed a genericManfest into
genericImage as an anonymous member implementing most of the interface.

genericImage has now become a tiny wrapper over UnparsedImage and
genericManifest.

Signed-off-by: Miloslav Trmač <[email protected]>
… immediately before we introduce another kind of image.

Signed-off-by: Miloslav Trmač <[email protected]>
Right now this does not really do anything, except add a whole lot of
do-nothing infrastructure in memoryImage, but it will make it much
easier to return extra data (like a newly generated config.json) from
UpdatedImage.

Signed-off-by: Miloslav Trmač <[email protected]>
Instead, make it a responsibility of genericManifest to provide the MIME
type.  This simplifies creation of a memoryImage, and removes a field
which may be redundant, e.g. with manifestSchema2.MediaType.

Signed-off-by: Miloslav Trmač <[email protected]>
@mtrmac
Copy link
Collaborator Author

mtrmac commented Oct 11, 2016

(Rebased, added 9e7a5bf , and skopeo tests are running in containers/skopeo#230 ).

@mtrmac
Copy link
Collaborator Author

mtrmac commented Oct 11, 2016

👍

Approved with PullApprove

@mtrmac mtrmac merged commit 0bbc487 into containers:master Oct 11, 2016
@mtrmac mtrmac deleted the image-refactor branch October 11, 2016 13:40
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.

2 participants