Commit Graph

27 Commits

Author SHA1 Message Date
Miloslav Trmač 04deef6fe6 Call .Validate() before digest.Hex() / digest.Encoded()
... to prevent panics if the value does not contain a :, or other unexpected
values (e.g. a path traversal).

Don't bother on paths where we computed the digest ourselves, or it is already trusted
for other reasons.

Signed-off-by: Miloslav Trmač <mitr@redhat.com>
2024-05-09 15:59:32 +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č e3aa82e5c9 Document the unparsedToplevel parameter to Commit
... and acknowledge that various tests are strictly speaking
invalid, to reinforce that real callers must not pass nil.

Signed-off-by: Miloslav Trmač <mitr@redhat.com>
2021-06-22 21:45:50 +02: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
Nalin Dahyabhai ca5fe04cb3 Add manifest list support
Add the manifest.List interface, and implementations for OCIv1 Index and
Docker Schema2List documents.

Add an instanceDigest parameter to PutManifest(), PutSignatures(), and
LayerInfosForCopy, for symmetry with GetManifest() and GetSignatures().
Return an error if the instanceDigest is supplied to destinations which
don't support them, and add stubs that do so even to the transports
which would support it, so that we don't break compilation here.

Add a MultipleImages flag to copy.Options, and if the source for a copy
operation contains multiple images, copy all of the images if we can.
If we can't copy them all, but we were told to, return an error.

Use the generic manifest list API to select a single image to copy from
a list, so that we aren't just limited to the Docker manifest list
format for those cases.

When guessing at the type of a manifest, if the manifest contains a list
of manifests, use its declared MIME type if it included one, else assume
it's an OCI index, because an OCI index doesn't include its MIME type.

When copying, switch from using an encode-then-compare of the original
and updated versions of the list to checking if the instance list was
changed (one of the things we might have changed) or if its type has
changed due to conversion (the other change we might have made).  If
neither has changed, then we don't need to change the encoded value of
the manifest.

When copying, when checking for a digest mismatch in a target image
reference, ignore a mismatch between the digest in the reference and the
digest of the main manifest if we're copying one element from a list,
and the digest in the reference matches the digest of the manifest list.

When copying, if conversion of manifests for single images is being
forced, convert manifest lists to the corresponding list types.

When copying, supply the unparsed top level to Commit() by attaching the
value to the context.Context.

Support manifest lists in the directory transport by using the instance
digest as a prefix of the filename used to store a manifest or a piece
of signature data.

Support manifest lists in the oci-layout transport by accepting indexes
as we do images, and stop guessing about Platform values to add to the
top-level index.

Support storing manifest lists to registries in the docker: transport by
using the manifest digest when we're writing one image as part of
pushing a list of them, and by using the instance digest when reading or
writing signature data, when one is specified, or the cached digest of
the non-instanced digest when one is not specified.

Add partial support for manifest lists to the storage transport: when
committing one image from a list into storage, also add a copy of the
manifest list by extracting it from the context.Context.  The logic is
already in place to enable locating an image using any of multiple
manifest digests.

When writing an image that has an instanceDigest value (meaning it's a
secondary image), don't try to generate a canonical reference to add to
the image's list of names if the reference for the primary image doesn't
contain a name.  That should only happen if we're writing using just an
image ID, which is unlikely, but we still need to handle it.

Avoid computing the digest of the manifest, or retrieving the
either-a-tag-or-a-digest value from the target reference, if we're given
an instanceDigest, which would override them anyway.

Move the check for non-nil instanceDigest values up into the main
PutSignatures() method instead of duplicating it in the per-strategy
helpers.

Add mention of the instanceDigest parameter and its use to various
PutManifest, PutSignatures, and LayerInfosForCopy implementations and
their declarations in interfaces.

Signed-off-by: Nalin Dahyabhai <nalin@redhat.com>
2019-10-18 15:15:13 -04: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
umohnani8 2f131cc136 Remove .tar extension from blob and config file names
The config file was being saved as digest.tar for the directory transport.
This is misleading as the config file is not a tar archive.
Dropped the .tar extension from all files now, including blobs.
The user can use a tool like file to determine the format of the files in the directory.

Signed-off-by: umohnani8 <umohnani@redhat.com>
2018-02-20 13:54:30 -05:00
Urvashi Mohnani aa0676d506 Add manifest type conversion support for "dir" transport
Gives the user the option to switch between the oci, v2s1, and v2s2 manifests
Add directory creation if the directory doesn't exist
Add overwrite functionality only if the directory was a container image directory
Feature added for the pulp team

Signed-off-by: Urvashi Mohnani <umohnani@redhat.com>
2017-11-14 12:11:06 -05: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č 5ef4c10be2 Use /usr/share instead of /etc/skel for tests of PolicyConfigurationNamespaces
/etc/skel does not exist on macOS; /usr/share exists both on macOS and Linux.

Ultimately, for full portability, we should be using something within an ioutil.TempDir,
but in that case the test would have to compute the full set of parent directories,
essentially duplicating exactly the code we want to test; so, a hard-coded directory
which exists on all supported platforms is better, as long as we can get away with it.

Signed-off-by: Miloslav Trmač <mitr@redhat.com>
2017-08-31 21:33:55 +02:00
Miloslav Trmač 948812ac33 Make sure TMPDIR does not contain symlinks
Some tests directly or indirectly exercising the directory/explicitfilepath
subpackage expect the path returned by ioutil.TempDir to be canonical in the
directory/explicitfilepath sense (absolute, no symlinks, cleaned up).

ioutil.TempDir uses $TMPDIR by default, and on macOS, $TMPDIR is by
default set to /var/folders/…, with /var a symlink to /private/var ,
which does not match our expectations.  So, tests which want to use
ioutil.TempDir that way, can
import _ "github.com/containesr/image/internal/testing/explicitfilepath-tmpdir"
to ensure that $TMPDIR is canonical and usable as a base for testing
path canonicalization in its subdirectories.

Hide this canonicalization in a subpackage which can be just imported into
any tests which needs it.

(This also introduces the first use of the "internal" subdirectory,
for subpackages which should not be used by externals callers.)

Signed-off-by: Miloslav Trmač <mitr@redhat.com>
2017-08-31 21:33:55 +02:00
Antonio Murdaca d419460c34
image: verify schema1 manifest before fixing layers
Signed-off-by: Antonio Murdaca <runcom@redhat.com>
2016-10-28 18:34:14 +02:00
Miloslav Trmač 41f9cdc937 Fetch a manifest already in image.FromUnparsedImage
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č <mitr@redhat.com>
2016-10-11 13:00:27 +02:00
Miloslav Trmač 287c1321f6 Add ImageDestination.Close
This is necessary to close the socket to the daemon in
daemonImageDestination.

Signed-off-by: Miloslav Trmač <mitr@redhat.com>
2016-09-05 22:57:02 +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č be7e92f900 Move deleting images from ImageSource to ImageReference
For lookaside signature store, and separating the read and write URLs,
we need to set up read-only and read-write states differently; having
read-write “delete” in dockerImageSource is incovenient.

In tue future, ImageSource.Delete will be a really poor fit for
docker-daemon:, where initializing the ImageSource causes the tarball
to be copied from the daemon.  We could instead implement the
docker-daemon source so that it only copies the tarball on demand, but
not sharing the object is much simpler.

This leaves the Docker implementation in docker_image_src.go to make
reviewing easier.

Signed-off-by: Miloslav Trmač <mitr@redhat.com>
2016-08-31 21:13:31 +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č 9eac100d42 Validate directory paths in policy configuration scopes
Use filepath.Clean() to verify that the paths are in a canonical format,
to catch simple and easy to detect mistakes like double slashes etc.

Signed-off-by: Miloslav Trmač <mitr@redhat.com>
2016-08-02 17:40:56 +02:00
Miloslav Trmač 50104c854e Move the directory path helpers to dirReference
This improves on the dirReference encapsulation, and makes the methods
clearly related to dirReference instead of arbitrary strings.

Does not change behavior.

Signed-off-by: Miloslav Trmač <mitr@redhat.com>
2016-07-18 21:19:58 +02:00
Miloslav Trmač 55bcc37672 Add policy configuration scope validation
This e.g. rejects relative paths for directories.

Notably docker: transport is the only one which does not do any real
validation; we could copy&paste the character ranges and lengths
directly from docker/distribution/reference, which feels fairly ugly.

Signed-off-by: Miloslav Trmač <mitr@redhat.com>
2016-07-18 21:07:28 +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č be1e012a0f Add types.ImageReference.PolicyConfiguration{Identity,Namespaces}
This makes the core policy lookup logic Docker-independent,
with the underlying Docker-specific implementation moved to
docker/policyconfiguration/naming.go.

Does not change behavior, only docker: and atomic: transports
currently implement the policy configuration naming, in a compatible
way, and the policy configuration is still not transport-aware.  That
happens next.

Signed-off-by: Miloslav Trmač <mitr@redhat.com>
2016-07-18 20:50:11 +02:00
Miloslav Trmač 59edf8316f Add types.ImageReference.DockerReference()
This will consolidate Docker reference usage to all go through
types.ImageReference.

No users yet, will be migrated imminently.

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