Skip to content

Commit b5e202e

Browse files
committed
Do the isMultiImage decision already on an UnparsedImage, not an Image
We don't actually need to parse the image to make this decision. Also, we are going to do signature checking on the individual images in the list in the future, so the list/non-list decision needs to happen before signature checking. Signed-off-by: Miloslav Trmač <[email protected]>
1 parent d44066f commit b5e202e

File tree

1 file changed

+9
-8
lines changed

1 file changed

+9
-8
lines changed

copy/copy.go

Lines changed: 9 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -142,8 +142,17 @@ func Image(policyContext *signature.PolicyContext, destRef, srcRef types.ImageRe
142142
}
143143
}
144144
}()
145+
multiImage, err := isMultiImage(unparsedImage)
146+
if err != nil {
147+
return errors.Wrapf(err, "Error determining manifest MIME type for %s", transports.ImageName(srcRef))
148+
}
149+
if multiImage {
150+
return errors.Errorf("can not copy %s: manifest contains multiple images", transports.ImageName(srcRef))
151+
}
145152

146153
// Please keep this policy check BEFORE reading any other information about the image.
154+
// (the multiImage check above only matches the MIME type, which we have received anyway.
155+
// Actual parsing of anything should be deferred.)
147156
if allowed, err := policyContext.IsRunningImageAllowed(unparsedImage); !allowed || err != nil { // Be paranoid and fail if either return value indicates so.
148157
return errors.Wrap(err, "Source image rejected")
149158
}
@@ -162,14 +171,6 @@ func Image(policyContext *signature.PolicyContext, destRef, srcRef types.ImageRe
162171
return err
163172
}
164173

165-
multiImage, err := isMultiImage(src)
166-
if err != nil {
167-
return errors.Wrapf(err, "Error determining manifest MIME type for %s", transports.ImageName(srcRef))
168-
}
169-
if multiImage {
170-
return errors.Errorf("can not copy %s: manifest contains multiple images", transports.ImageName(srcRef))
171-
}
172-
173174
var sigs [][]byte
174175
if options.RemoveSignatures {
175176
sigs = [][]byte{}

0 commit comments

Comments
 (0)