Commit Graph

133 Commits

Author SHA1 Message Date
Nalin Dahyabhai 435aa93e14 Disable partial pulls (zstd:chunked) by default
Disable the storage.options.pull_options.enable_partial_images option by
default, so that it will have to be explicitly enabled in order to be
used.

Update the apply-diff-from-staging-directory integration test to call
the test helper binary directly, so that the configuration file the test
writes won't have its settings overridden by command line options that
the storage() test helper function adds.

Signed-off-by: Nalin Dahyabhai <nalin@redhat.com>
2024-11-04 13:52:48 -05:00
Giuseppe Scrivano 8b5dadb045
chunked: close payload stream
The payload stream must be closed after being used.

Reported here: https://github.com/containers/storage/pull/2041#discussion_r1690061874

Signed-off-by: Giuseppe Scrivano <gscrivan@redhat.com>
2024-10-24 22:43:59 +02:00
Miloslav Trmač 82234e1a36 Fall back from partial pulls to ordinary pulls on VFS
... and other graph drivers which don't support partial pulls.

Signed-off-by: Miloslav Trmač <mitr@redhat.com>
2024-10-18 21:54:35 +02:00
Miloslav Trmač bdbd5ed90d Refactor getProperDiffer further
Use switch to handle the various TOC presence cases

Signed-off-by: Miloslav Trmač <mitr@redhat.com>
2024-10-18 21:54:27 +02:00
Miloslav Trmač da9f66a4ac Refactor getProperDiffer a bit
Instead of sharing the badRequestErr logic, duplicate it.
That's a bit ugly, but we get better debug messages and a more
traditional control flow.

Should not change behavior, except for debug messages.

Signed-off-by: Miloslav Trmač <mitr@redhat.com>
2024-10-18 21:54:06 +02:00
Miloslav Trmač 8e3938748f Split getProperDiffer from GetDiffer
... to centralize the fallback allowed / required logic.

Should not change behavior, apart from maybe some error text.

Signed-off-by: Miloslav Trmač <mitr@redhat.com>
2024-10-18 21:53:56 +02:00
Miloslav Trmač 1a8fde7e01 Don't discard the error reported by tarSizeFromTarSplit
Signed-off-by: Miloslav Trmač <mitr@redhat.com>
2024-10-16 00:36:13 +02:00
Miloslav Trmač f979bada64 Compute the layer size from tar-split for zstd:chunked layers
Signed-off-by: Miloslav Trmač <mitr@redhat.com>
2024-10-14 20:10:07 +02:00
Miloslav Trmač 71fc790550 Don't set UncompressedSize on chunked pull
The current value obtained by summing the sizes of regular file contents
does not match the size of the uncompressed layer tarball.

We don't have a convenient source to compute the correct size
for estargz without pulling the full layer and defeating the point;
so we must allow for the size being unknown.

For recent zstd:chunked images, we have the full tar-split,
so we can compute the correct size; that will happen in
the following commits.

Signed-off-by: Miloslav Trmač <mitr@redhat.com>
2024-10-14 20:10:07 +02:00
Giuseppe Scrivano ed132480d3
chunked: define error for partial pulls not available
define a new error type so that the caller can determine whether it is
safe to ignore the error and retrieve the resource fully.

Closes: https://github.com/containers/storage/issues/2115

Signed-off-by: Giuseppe Scrivano <gscrivan@redhat.com>
2024-10-02 17:13:25 +02:00
Giuseppe Scrivano 3bbd19c9dc
chunked: drop special handling for "< 64" ranges
Avoid handling cases where the server doesn't support at least 64
ranges in a request, in order to prevent falling back to the
traditional pull mechanism.

Signed-off-by: Giuseppe Scrivano <gscrivan@redhat.com>
2024-10-02 15:49:20 +02:00
Miloslav Trmač f4597cfee5 Use range iterations
... for the trivial cases where the loop body does not reference
the iteration variable at all.

Signed-off-by: Miloslav Trmač <mitr@redhat.com>
2024-09-05 18:56:35 +02:00
Miloslav Trmač 28f531e5f6 Remove the context parameter from file loaders
Conceptually, these read from the network and _should_ be interruptible.
But we could, at best, interrupt the wait on the channels returned by
GetBlobAt; we would then still get a ReadCloser where we can call
Read() but not concurrently notice a cancellation.

The cancellation needs to happen at the HTTP client side, i.e. inside
the c/image private.ImageSourceInternalOnly.GetBlobAt call (not ImageSourceSeekable),
and, although it seems not to be quite documented, the http stack's http.NewRequestWithContext
does cause the HTTP body transport to be terminated on a context cancellation.

I.e. it is out of control of this codebase anyway; so don't pretend to handle it.

Signed-off-by: Miloslav Trmač <mitr@redhat.com>
2024-07-10 23:54:30 +02:00
Miloslav Trmač 412ff916c2 Remove various unused parameters
Should not change behavior.

Signed-off-by: Miloslav Trmač <mitr@redhat.com>
2024-07-10 23:54:30 +02:00
Giuseppe Scrivano 28cba3014b
chunked: store compressed digest if validated
if the compressed digest was validated, as it happens when
'pull_options = {convert_images = "true"}' is set, then store it as
well so that reusing the blob by its compressed digest works.

Previously, when an image converted to zstd:chunked was pulled a
second time, it would not be recognized by its compressed digest,
resulting in the need to re-pull the image again.

Signed-off-by: Giuseppe Scrivano <gscrivan@redhat.com>
2024-07-10 09:41:41 +02:00
Jan Rodák fb91f385f4 Fix errcheck: error return value of `unix.Mkdirat` is not checked
Signed-off-by: Jan Rodák <hony.com@seznam.cz>
2024-07-09 16:46:49 +02:00
Jan Rodák 8c11a68185 Fix errcheck: error return value of `c.zstdReader.Reset` is not checked
Signed-off-by: Jan Rodák <hony.com@seznam.cz>
2024-07-09 16:46:49 +02:00
Giuseppe Scrivano f35833c88d
chunked: set correctly the xattr for ForceMask
and also fix a segfault when the xattr map is nil

Signed-off-by: Giuseppe Scrivano <gscrivan@redhat.com>
2024-06-19 23:20:21 +02:00
Giuseppe Scrivano e717273335
chunked: use FormatContainersOverrideXattr
Signed-off-by: Giuseppe Scrivano <gscrivan@redhat.com>
2024-06-19 11:25:05 +02:00
Giuseppe Scrivano eab40abdf1
chunked: honor store configuration
honor the pull_options configuration set for the current store instead
of using the default configuration.

Needed by Podman to override the pull options from the command line
for a single command.

Signed-off-by: Giuseppe Scrivano <gscrivan@redhat.com>
2024-06-12 12:37:31 +02:00
Giuseppe Scrivano 4ba330fb40
chunked: differ stores only pullOptions
Signed-off-by: Giuseppe Scrivano <gscrivan@redhat.com>
2024-06-12 12:30:32 +02:00
Giuseppe Scrivano bb44c4e806
chunked: uses directly the pull options map
needed by a future commit, should not change the behavior.

Signed-off-by: Giuseppe Scrivano <gscrivan@redhat.com>
2024-06-12 12:22:53 +02:00
Giuseppe Scrivano 672a685012
chunked: use existing buffer for io.Copy
utilize the existing pre-allocated buffer instead of allocating a new
one in io.Copy().

Signed-off-by: Giuseppe Scrivano <gscrivan@redhat.com>
2024-06-11 13:13:05 +02:00
Akihiko Odaki b3a2f6a07a idtools: Use SetContainersOverrideXattr()
Signed-off-by: Akihiko Odaki <odaki@rsg.ci.i.u-tokyo.ac.jp>
2024-06-11 15:36:10 +09:00
Giuseppe Scrivano 0af0d21625
chunked: use fs.PathError for errors from unix pkg
Signed-off-by: Giuseppe Scrivano <gscrivan@redhat.com>
2024-06-10 15:20:47 +02:00
Giuseppe Scrivano 097fcb9be6
chunked: return PathError for appendHole errors
Signed-off-by: Giuseppe Scrivano <gscrivan@redhat.com>
2024-06-07 17:25:27 +02:00
Colin Walters cfde71b024 chunked: Add helpers for /proc/self/fd accesses
It's not hard to grep for /proc/self/fd, but this way is a bit
cleaner and avoids typos, etc.

Signed-off-by: Colin Walters <walters@verbum.org>
2024-06-07 09:30:55 -04:00
Giuseppe Scrivano 7c61cfaee7
chunked: refactor args to openFileUnderRoot()
follow the same pattern used by other functions.

Signed-off-by: Giuseppe Scrivano <gscrivan@redhat.com>
2024-06-06 22:33:43 +02:00
Giuseppe Scrivano 2278cb1e0e
chunked: provide constructor for seekableFile
Signed-off-by: Giuseppe Scrivano <gscrivan@redhat.com>
2024-06-06 21:37:13 +02:00
Giuseppe Scrivano 37800897ab
chunked: split file operations to a new file
Signed-off-by: Giuseppe Scrivano <gscrivan@redhat.com>
2024-06-06 13:11:46 +02:00
Colin Walters 661531fb0d chunked: Set O_CLOEXEC
I was just reading the code and I have a mental checklist item
for "invoking open without O_CLOEXEC" that triggered here.
(See also e.g.
https://github.com/containers/composefs/pull/185#discussion_r1322925050
)

It has security-relevant properties for us, xref
CVE-2024-21626 for example.

This isn't the only missing variant of this in this codebase,
just using this targeted PR to test the waters for more PRs.

Signed-off-by: Colin Walters <walters@verbum.org>
2024-06-05 09:20:07 -04:00
Giuseppe Scrivano 617a808a63
chunked: change auto merge threshold to 1024
Increase the threshold for auto-merging parts from 128 to 1024. This change
aims to reduce the number of parts in an HTTP multi-range request, thus
increasing the likelihood that the server will accept the request.

The previous threshold of 128 often resulted in a large number of small
ranges, which could lead to HTTP multi-range requests being rejected by
servers due to the excessive number of parts.

It partially addresses the reported issue.

Reported-by: https://github.com/containers/storage/issues/1928

Signed-off-by: Giuseppe Scrivano <gscrivan@redhat.com>
2024-06-03 15:00:35 +02:00
Miloslav Trmač dfb4b1ff87 Unmarshal the TOC already in readZstdChunkedManifest
Other TOC formats don't fill the data in.

For now, this only increases memory usage, but we will
need the data soon.

Signed-off-by: Miloslav Trmač <mitr@redhat.com>
2024-05-14 10:53:03 +02:00
Miloslav Trmač 9fbd0e0395 Don't look for the binary digest when pulling layers
This code path is usually never triggered because
the annotations are present; and it was broken until recently.

Remove it to simplify the code and analysis.

Signed-off-by: Miloslav Trmač <mitr@redhat.com>
2024-04-22 23:56:40 +02:00
openshift-merge-bot[bot] 2431799327
Merge pull request #1893 from giuseppe/convert-zstd-chunked-store-original-tarsize
chunked: store original tar size for converted layers
2024-04-20 10:33:32 +00:00
Giuseppe Scrivano 639f1a62f9
chunked: store original tar size for converted layers
if the layer was converted from an existing one, store the original
layer size.

Closes: https://github.com/containers/storage/issues/1892

Signed-off-by: Giuseppe Scrivano <gscrivan@redhat.com>
2024-04-19 21:30:37 +02:00
Miloslav Trmač 1f47b38c09 Only obtain the zstd:chunked TOC digest once
Make it structually clear that the code is all using the same value,
making it less likely for the verifier and other uses to get out of sync.

Also avoids some redundant parsing and error paths.
The conversion path looks longer, but that's just moving the parsing
from the called function (which is redundant for other callers).

Should not change behavior.

Signed-off-by: Miloslav Trmač <mitr@redhat.com>
2024-04-13 16:57:07 +02:00
Miloslav Trmač 3beea1e21e Only obtain the estargz TOC digest once
Make it structually clear that the code is all using the same value,
making it less likely for the verifier and other uses to get out of sync.

Also avoids some redundant parsing and error paths.

Should not change behavior.

Signed-off-by: Miloslav Trmač <mitr@redhat.com>
2024-04-13 16:26:32 +02:00
Giuseppe Scrivano 1126d65aa7
chunked: skip file metadata for composefs files
if the file is created using the object-store flat directory format,
there is no need to set its inodes attributes, as anyway they are
ignored when creating the composefs binary blob.

Signed-off-by: Giuseppe Scrivano <gscrivan@redhat.com>
2024-03-20 15:47:38 +01:00
Giuseppe Scrivano 0f12ecea79
chunked: skip file metadata for hard links
if a file was deduplicated with a hard link, do not override its
metadata.

Signed-off-by: Giuseppe Scrivano <gscrivan@redhat.com>
2024-03-20 15:47:38 +01:00
Giuseppe Scrivano f52cbe08c1
chunked: add way to skip setting file metadata
when it is set, only the file payload is written, but the inode
attributes are ignored.

Signed-off-by: Giuseppe Scrivano <gscrivan@redhat.com>
2024-03-20 15:47:38 +01:00
Giuseppe Scrivano f6356d6ccd
chunked: refactor private fields to internal struct
Signed-off-by: Giuseppe Scrivano <gscrivan@redhat.com>
2024-03-20 15:47:37 +01:00
Giuseppe Scrivano 43b836e7e6
chunked: improve function to merge chunks
improve the function that combines neighbor chunks.  Instead of using
the number of parts, which also includes local files, use only the
number of chunks that must be retrieved from the network.

In addition, introduce a threshold limit to merge chunks so that we
further reduce the number of requested ranges.

Signed-off-by: Giuseppe Scrivano <gscrivan@redhat.com>
2024-03-01 17:09:47 +01:00
Giuseppe Scrivano 69aeb17257
chunked: preserve the original value for symlinks
the symlinks must preserve their original value without any
alteration.

Signed-off-by: Giuseppe Scrivano <gscrivan@redhat.com>
2024-02-27 21:36:19 +01:00
Giuseppe Scrivano 8c1cf34a37
storage: move check for enable_partial_images to GetDiffer
move the check for `enable_partial_images` to GetDiffer so that it
doesn't attempt any operation if the feature is disabled.

Signed-off-by: Giuseppe Scrivano <gscrivan@redhat.com>
2024-02-15 21:59:01 +01:00
Giuseppe Scrivano 23ff5f8c57
storage: enable partial images by default
by default enable pulling a partial image, it is still possible to
disable the feature through the configuration file.

Signed-off-by: Giuseppe Scrivano <gscrivan@redhat.com>
2024-02-15 21:58:57 +01:00
Giuseppe Scrivano 9343f9f792
chunked: report TOCDigest for converted layers
even if we validated the full layer, report the TOC Digest as well so
the upper layer can use both.

Signed-off-by: Giuseppe Scrivano <gscrivan@redhat.com>
2024-02-09 11:13:43 +01:00
Giuseppe Scrivano dc3f818a84
chunked: store UncompressedDigest if validated
store the UncompressedDigest when the original tarball was converted
to zstd:chunked, since its diffID was computed and validated.

In this way the layer can be reused as any other layer that was fully
retrieved and validated.

Before this change, a layer that was converted to zstd:chunked was
always retrieved since it has not a TOC Digest.

Signed-off-by: Giuseppe Scrivano <gscrivan@redhat.com>
2024-01-30 21:24:54 +01:00
Daniel J Walsh b9c7cc2267
Merge pull request #1806 from giuseppe/composefs-bugfixes
composefs: some fixes
2024-01-22 07:55:53 -05:00
Giuseppe Scrivano d800e0fae5
chunked: copy chunk struct
it prevents clobbering the chunk .Size element later.  This filed was
ignored previously, but composefs uses it to retrieve the file size.

Signed-off-by: Giuseppe Scrivano <gscrivan@redhat.com>
2024-01-19 18:51:25 +01:00