Commit Graph

38 Commits

Author SHA1 Message Date
Kir Kolyshkin e5aa22570f signature: fixup to silence codespell
s/doesnt/does-not/

Signed-off-by: Kir Kolyshkin <kolyshkin@gmail.com>
2024-08-02 13:23:54 -07:00
Miloslav Trmač d218ff3d46 Allow accepting multiple GPG keyrings via signedBy.keyPaths
Signed-off-by: Miloslav Trmač <mitr@redhat.com>
2022-07-13 16:34:30 +02:00
Miloslav Trmač 03c8d799d0 Remove repetition in tests
... to make it easier to add more cases.

Should not change (test) behavior.

Signed-off-by: Miloslav Trmač <mitr@redhat.com>
2022-07-13 16:34:30 +02:00
Miloslav Trmač e37f4dbf3e Use more valid data in TestPRSignedByIsSignatureAuthorAccepted
... to make sure we are exercising exactly the failure pathss we are
trying to test.

Signed-off-by: Miloslav Trmač <mitr@redhat.com>
2022-07-13 16:33:44 +02:00
Miloslav Trmač 64756915ba Add Cosign verification support
type: cosignSigned, with the usual keyData/keyPath.
Fulcio/Rekor is not currently implemented.

NOTE: This only allows a single public key, not a keyring,
unlike simple signing. That seems problematic, there are
known users of that. But we can fix that later by adding
keyDirectory and the like.

NOTE: Cosign interoperability requires use of
signedIdentity: matchRepository. The fairly useful
signedIdentity: remapIdentity has no repository-match
functionality.

NOTE: Multi-arch images need to be signed by cosign
with --recursive to be accepted; c/image enforces
signatures per platform.

Signed-off-by: Miloslav Trmač <mitr@redhat.com>
2022-07-08 18:38:45 +02:00
Miloslav Trmač bdb2613fe6 Add private.UnparsedImage, use it for signature handling
Signed-off-by: Miloslav Trmač <mitr@redhat.com>
2022-07-07 18:38:27 +02:00
Miloslav Trmač 94a2667e94 Introduce mocks.ForbiddenImageReference, use it to simplify tests
Should not change (test) behavior.

Signed-off-by: Miloslav Trmač <mitr@redhat.com>
2022-06-13 23:53:14 +02:00
Miloslav Trmač 320a1ff585 Move all internal users of image/v5/image to image/v5/internal/image
... to skip the compatibility layer.

Signed-off-by: Miloslav Trmač <mitr@redhat.com>
2022-06-11 01:25:44 +02:00
Miloslav Trmač 7152f888b9 Update users of deprecated io/ioutil
Mostly just name changes that should not change behavior,
apart from ioutil.ReadDir -> os.ReadDir avoiding per-item
lstat(2) in some cases.

Signed-off-by: Miloslav Trmač <mitr@redhat.com>
2022-04-13 20:46:48 +02:00
Miloslav Trmač 9a9904944d Use testing.T.TempDir()
... to simplify tests.

Signed-off-by: Miloslav Trmač <mitr@redhat.com>
2022-03-17 20:35:00 +01:00
Miloslav Trmač f0d818b27c Use Testing.T.Cleanup() to simplify tests
Signed-off-by: Miloslav Trmač <mitr@redhat.com>
2022-03-17 20:35:00 +01:00
Josh Soref 111bf164be Spelling
* about
* appropriate
* busybox
* candidate
* candidates
* certificate
* config
* configuration
* containers
* decompression
* directory
* does-not/match
* does/not/exist
* doesnot
* doesnotexist
* exemplary
* garbage
* gzipped
* identify
* initially
* kubernetes
* length
* marshaling
* maximum
* mybetaproduct
* overridden
* parameter
* permissive
* policyconfiguration
* protocols
* reference
* referenceable
* requirement
* response
* simultaneously
* slashes
* subobject
* successfully
* this
* uncompressed
* unmarshaled
* unmarshaler
* unmarshaling it
* unmarshaller
* valid

Signed-off-by: Josh Soref <jsoref@users.noreply.github.com>
2021-03-23 14:37:37 -04:00
Ivan Voronchihin 620d71de0a Handle checking error in dirImageMockWithRef
Signed-off-by: Ivan Voronchihin <bege13mot@gmail.com>
2019-11-26 18:15:17 +04:00
Miloslav Trmač 7d9cde7252 Update to major version v5
> gomove github.com/containers/image/v4 github.com/containers/image/v5
+ a manual edit of go.mod

Signed-off-by: Miloslav Trmač <mitr@redhat.com>
2019-10-25 22:27:45 +02:00
Miloslav Trmač e568c94ef3 Correctly use a c/image/v4 module namespace
... so that major-version-aware Go module import
(as opposed to vX.Y.Z+incompatible, which does not allow different
packages to use different versions) works right.

Also requires adding some more GO111MODULE=on options to Makefile.

Signed-off-by: Miloslav Trmač <mitr@redhat.com>
2019-10-03 22:54:27 +02:00
Mike Lundy 369c44212b Put context.Context arguments on almost everything
- Network IO paths should react to cancels now.
- File IO paths generally still won't.
- `SystemContext` objects have been renamed to `sys` to leave `ctx`
  available for the stdlib context objects.

Signed-off-by: Mike Lundy <mike@fluffypenguin.org>
2018-04-07 04:34:51 -07:00
Miloslav Trmač 32374d9fa9 Do not Close the ImageSource in UnparsedImage/Image
Remove the .Close() methods from UnparsedImage/Image, which closed the
underlying ImageSource.  Instead, just require the caller to ensure
that the ImageSource is not closed as long as the UnparsedImage/Image
are used.

This allows using several independent UnparsedImage/Image instances
for a shared ImageSource; notably independent Image objects for the
individual image instances in a manifest list.  (copy.Image is already
simpler although it is only using a single instance.)

To keep ImageReference.NewImage simple and not to break all the external
callers of this, also add a simple ImageCloser wrapper which retains
the ImageSource closing functionality, and return it from image.FromSource
and ImageReference.NewImage implementations.

(It's very likely many of the NewImage callers would be surprised by how this
handles manifest lists, and it is very tempting to break this API, at least
by renaming, to force the callers to consider this; however, this would be
better done after eliminating the need of ImageReference.NewImage entirely,
by replacing the specialized types.Image extensions with something else, first.)

Signed-off-by: Miloslav Trmač <mitr@redhat.com>
2017-11-15 20:06:05 +01:00
Miloslav Trmač f3c08267ea Support instanceDigest in types.UnparsedImage and types.Image
A types.UnparsedImage is now created by image.UnparsedInstance, with the
caller specifying nil or a digest.

A types.Image is (preferably) created by image.FromUnparsedImage based
on a specific instance.  For continuity/compatibility, image.FromSource
continues working the old way, i.e. using the default instance, and
transparently parsing data from a chosen instance (but still returning
the manifest list in .Manifest()).

Signed-off-by: Miloslav Trmač <mitr@redhat.com>
2017-11-15 20:06:05 +01:00
Owen W. Taylor 56b61acbe8 ImageReference.NewImageSource: remove requestedManifestMIMETypes parameter
The requestedManifestMIMETypes parameter was added because a destination
might not support all manifest MIME types that the the source supports,
but the original use case now passes all manifest types and lets
containers/image convert internally. In generally, internal conversion
may be more comprehensive, is more predictable, and avoids bypassing
internal checks.

Fixes: #331
Signed-off-by: Owen W. Taylor <otaylor@fishsoup.net>
2017-09-05 07:56:42 -04:00
Miloslav Trmač ecdd233c84 Copy github.com/docker/distribution/reference to docker/reference
This replaces the copy of github.com/docker/docker/reference in the same
place, which we have just gotten rid of, and allows using this package
even in consumers which insist on an incompatible version of
docker/distribution.

The copy has been edited to drop a reference to
github.com/docker/distribution/digestset .

Signed-off-by: Miloslav Trmač <mitr@redhat.com>
2017-02-07 15:25:27 +01:00
Miloslav Trmač a81649c9c7 API transition: Drop reference.XParseNamed
Instead call distreference.ParseNormalizedNamed directly.

(This looks bigger than it really is because so many files now don't
need c/i/docker/reference, so they are dropping the “distreference”
qualifier for docker/distribution/reference.)

Signed-off-by: Miloslav Trmač <mitr@redhat.com>
2017-02-07 15:25:27 +01:00
Miloslav Trmač dda360d9ec API separation: Add an 'X' to all public names from c/i/docker/daemon/reference
This is an intermediate step which will eventually go away.

The goal of this PR is to get rid of c/i/docker/daemon/reference and to
replace uses of it by direct calls to docker/distribution/reference.

We can't do that safely and easily, because the two have different
semantics for reference.Named.Name() and reference.Named.String(): we
return a minimized version, e.g. "busybox", upstream returns an expanded
version, e.g. "docker.io/library/busybox".

BEFORE this commit the difference is hidden by using
docker/distribution/reference.WithName, which allows using the minimized
version, and works with it correctly; but because we want to use the
upstream canonicalization code, which will change semantics, we can't
just mix and match.

To make the distinction explicit, this commmit adds an X to ALL public
names from c/i/docker/daemon/reference.  E.g. a reference.XNamed type,
which has methods XName and XString.

This is pretty large, but does not change behavior at all.  By
inspection it is clear to see that reference.XNamed and subtypes does
not expose any of the non-X, conflicting, method names.

Using e.g.
> git diff --word-diff-regex=.|grep -F '{+'|grep -v '^\([^{]\|{+X+}\)*{\?$'
it is possible to see that most lines in this diff only add a single X
letter, and manually inspect the few lines which don't match the regexp.

The only REALLY new code is an explicit definition of namedRef.XName()
and namedRef.XString(), and two newly added casts to namedRef in cases
where we need to use the underlying distreference.Reference within
a reference.XNamed value.  Strictly speaking these changes change
behavior, in that third-party implementations of reference.XNamed are no
longer accepted; but we broke them by renaming at all.

Signed-off-by: Miloslav Trmač <mitr@redhat.com>
2017-02-07 15:24:14 +01:00
Antonio Murdaca 6021224098
docker: fork docker/dockerreference pkg
Signed-off-by: Antonio Murdaca <runcom@redhat.com>
2016-10-11 16:53:40 +02:00
Miloslav Trmač ad294f1c4b Split image.UnparsedImage from image.genericImage
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č <mitr@redhat.com>
2016-10-11 13:00:27 +02:00
Miloslav Trmač b8751d89dc Add types.UnparsedImage
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č <mitr@redhat.com>
2016-10-11 13:00:27 +02:00
Miloslav Trmač 45037ddc47 Add ImageSource.Close and Image.Close
These methods are necessary to clean up the temporary tar file copy in
daemonImageSource.

Signed-off-by: Miloslav Trmač <mitr@redhat.com>
2016-09-05 22:46:45 +02:00
Miloslav Trmač dff447c638 Move manifest MIME type selection from GetManifest to ImageSource creation
This allows the selection to be consistent across GetManifest and
GetSignatures (which will be needed by Docker lookaside).

The API change causes lots of churn, but ultimately it just moves the
real origin of the value from image.FromSource() to transport.NewImageSource(),
both of which are static for the life of the ImageSource.

Does not change behavior.

Signed-off-by: Miloslav Trmač <mitr@redhat.com>
2016-08-31 21:13:31 +02:00
Miloslav Trmač 8ad0cad4ea Use types.SystemContext in NewImage*
... instead of Docker-specific certPath and tlsVerify.

Also invert the sense of tlsVerify to make the default secure.

Signed-off-by: Miloslav Trmač <mitr@redhat.com>
2016-08-31 21:13:31 +02:00
Miloslav Trmač 3bf59a68cd Use PolicyConfigurationIdentity for all transports
Implement PolicyConfigurationIdentity and PolicyConfigurationNamespaces
for all transports, which makes them all possible to use in policy
configurations.

Then use Transport().Name instead of hard-coded "docker" in policy
transport lookup.

Signed-off-by: Miloslav Trmač <mitr@redhat.com>
2016-07-18 21:07:28 +02:00
Miloslav Trmač 9ccdcf8c40 Separate DockerReference-only mocks from policy mocks
This allows the DockerReference-only refImageReferenceMock to be a bit
tighter about rejecting unexpected calls, and it will be useful
soon when policy is handled separately from DockerReference.

At the moment this does not change much, separately commited primarily
to ease reviewing.

Signed-off-by: Miloslav Trmač <mitr@redhat.com>
2016-07-16 05:08:38 +02:00
Miloslav Trmač b462e18ca7 Replace IntendedDockerReference by Reference().DockerReference
Signed-off-by: Miloslav Trmač <mitr@redhat.com>
2016-07-16 05:08:38 +02:00
Miloslav Trmač 0a1111ca30 Add types.ImageTransport and types.ImageReference
This minimizes transport-specific knowledge in image name parsing
(as in cmd/skopeo/utils.go) and allows separation of reference parsing
and their use.

Existing public NewImage... API has been removed; callers are expected
to use any of
* types.ImageTransport.ParseReference().NewImage...
  (if they have a general string)
* transportpackage.ParseReference().NewImage...
  (if they have a transport-specific string)
* transportpackage.NewReference().NewImage...
  (if they have transport-specific raw values)

This usually adds an extra error checking step for the
ParseReference/NewReference call compared to the previous code; this is
considered not a big loss, especially because reporting “the reference
is invalid” and “the reference looks valid but connecting/using it
failed” as distinct failure modes seems quite useful for users.

The references are currently one-way (you can get a types.Image* from an
ImageReference, but not the other way around); that will be fixed soon.

Signed-off-by: Miloslav Trmač <mitr@redhat.com>
2016-07-16 05:08:38 +02:00
Miloslav Trmač ca400b95a2 Return a reference.Named instead of a string for Docker references
This is somewhat better typed, and avoids unnecessary roundtrips using
strings when both the producer and consumer want a reference.Named value
(like in PolicyContext.requirementsForImage).

This also forces us to explicitly handle IntendedDockerReference()
returning nil, when before we could rely on it returning "", which would
then be rejected by reference.ParseNamed as invalid input; anyway,
handling that case specially just allows for better error messages.

This adds two FIXMEs about error messages which do not tell the user
which image is being rejected; that will be fixed in the future
generalized reference work.

Signed-off-by: Miloslav Trmač <mitr@redhat.com>
2016-07-11 21:25:07 +02:00
Antonio Murdaca b89242619d directory: cleanup API
Signed-off-by: Antonio Murdaca <runcom@redhat.com>
2016-07-04 11:32:26 +02:00
Antonio Murdaca aa53132c87 *: add SupportedImageDestinationMIMEType to types.ImageDestination
Signed-off-by: Antonio Murdaca <runcom@redhat.com>
2016-06-29 17:21:08 +02:00
Antonio Murdaca e68e0e1110 move the project to a library
Signed-off-by: Antonio Murdaca <runcom@redhat.com>
2016-06-25 11:25:48 +02:00
Miloslav Trmač 96d6a58052 Move docker.genericImage to a separate skopeo/image subpackage
... making image.FromSource a public, stable, API.
2016-06-11 10:48:57 +02:00
Miloslav Trmač fd9c615d88 Add PolicyRequirement implementations
Also move the declaration of the type from the mostly-public
policy_types.go to policy_eval.go.
2016-06-02 16:12:10 +02:00