Commit Graph

133 Commits

Author SHA1 Message Date
Giuseppe Scrivano 81fc7c1214
chunked: calculate the file fs-verity when it is written
Signed-off-by: Giuseppe Scrivano <gscrivan@redhat.com>
2024-01-19 12:50:35 +01:00
Giuseppe Scrivano b7c31d234c
chunked: store the root dir more if present
propagate the mode for the current root directory if it is specified
in the tarball.

Signed-off-by: Giuseppe Scrivano <gscrivan@redhat.com>
2024-01-12 20:52:39 +01:00
Giuseppe Scrivano fa794cb997
chunked: validate converted images
validate that the retrieved data for converted images matches the
expected digest.

Signed-off-by: Giuseppe Scrivano <gscrivan@redhat.com>
2024-01-08 22:00:35 +01:00
Giuseppe Scrivano f435ce84a2
chunked: disallow both zstd:chunked and eStargz TOCs
reject a layer if it contains both a zstd:chunked and an eStargz TOC
since there are no guarantees that the two TOCs are consistent.

Signed-off-by: Giuseppe Scrivano <gscrivan@redhat.com>
2023-12-15 11:31:04 +01:00
Giuseppe Scrivano b0885dfba9
store: drop rootless from arguments
drop the rootless argument from DefaultStoreOptions and
UpdateStoreOptions since this can be retrieved internally through the
unshare package.

Signed-off-by: Giuseppe Scrivano <gscrivan@redhat.com>
2023-11-16 21:13:28 +01:00
Giuseppe Scrivano c1ccdf0d00
chunked: export toc as part of the Artifacts
so that the users of the function can get access to the already
unmarshalled TOC instead of having to unmarshal it again.

Signed-off-by: Giuseppe Scrivano <gscrivan@redhat.com>
2023-10-16 13:09:45 +02:00
Giuseppe Scrivano b737dc6caf
chunked: provide digest for empty files
if the file doesn't have a digest but its size is 0, we can hard code
the known sha256 digest.

Signed-off-by: Giuseppe Scrivano <gscrivan@redhat.com>
2023-10-16 13:09:45 +02:00
Giuseppe Scrivano 423c0dc207
chunked: move GetTOCDigest to a subpackage
The purpose of this move is to reduce dependencies for the new
package.

Signed-off-by: Giuseppe Scrivano <gscrivan@redhat.com>
2023-08-08 08:59:38 +02:00
Giuseppe Scrivano 58405a5940
chunked: skip validation for prefetched images
if the image is created locally there is no need to validate again the
files.

Signed-off-by: Giuseppe Scrivano <gscrivan@redhat.com>
2023-07-26 10:46:15 +02:00
Giuseppe Scrivano 303100391e
chunked: support converting existing images
if the "convert_images" option is set in the configuration file, then
convert traditional images to the chunked format on the fly.

This is very expensive at the moment since the entire zstd:chunked
file is created and then processed.

Signed-off-by: Giuseppe Scrivano <gscrivan@redhat.com>
2023-07-26 10:46:15 +02:00
Giuseppe Scrivano a50bb95770
chunked: support writing files in a flat dir format
so that they can be stored by their digest

Signed-off-by: Giuseppe Scrivano <gscrivan@redhat.com>
2023-07-04 17:45:41 +02:00
Giuseppe Scrivano 8bb5a087ab
driver: extend ApplyDiff with differOpts
Signed-off-by: Giuseppe Scrivano <gscrivan@redhat.com>
2023-07-04 17:45:41 +02:00
Giuseppe Scrivano 7a5f2bef36
chunked: file fd leak
The file descriptor was not closed before, thus leaking all the opened files.

Signed-off-by: Giuseppe Scrivano <gscrivan@redhat.com>
2023-07-04 17:45:41 +02:00
Giuseppe Scrivano 7304a21410
chunked: add function to retrieve TOC digest
Signed-off-by: Giuseppe Scrivano <gscrivan@redhat.com>
2023-06-17 00:31:40 +02:00
Giuseppe Scrivano 5d10b9459a
chunked: report used UIDs/GIDs
Signed-off-by: Giuseppe Scrivano <gscrivan@redhat.com>
2023-06-17 00:31:40 +02:00
Giuseppe Scrivano b007d1744d
driver: keep TOC digest
Signed-off-by: Giuseppe Scrivano <gscrivan@redhat.com>
2023-06-17 00:31:39 +02:00
Giuseppe Scrivano 7bbf6ed448
chunked: generate tar-split as part of zstd:chunked
change the file format to store the tar-split as part of the
zstd:chunked image.  This will allow clients to rebuild the entire
tarball without having to download it fully.

also store the uncompressed digest for the tarball, so that it can be
stored into the storage database.

Needs: https://github.com/containers/image/pull/1976

Signed-off-by: Giuseppe Scrivano <gscrivan@redhat.com>
2023-06-17 00:31:39 +02:00
Giuseppe Scrivano 7846152fde
chunked: drop superfluous variable
Signed-off-by: Giuseppe Scrivano <gscrivan@redhat.com>
2023-06-17 00:31:39 +02:00
Kir Kolyshkin a4d8f720a2 Format sources with gofumpt
gofumpt is a superset of gofmt, enabling some more code formatting
rules.

This commit is brought to you by

	gofumpt -w .

Signed-off-by: Kir Kolyshkin <kolyshkin@gmail.com>
2023-05-26 16:17:31 -07:00
Daniel J Walsh a3204cf7e8
Move to golang 1.18 and later
Github.com is reporting security issues on older versions of
golang.

Signed-off-by: Daniel J Walsh <dwalsh@redhat.com>
2023-04-03 15:26:54 -04:00
Nalin Dahyabhai 769814edfe Fix typos in error messages
Two error messages suggest that podman-system-migrate is a binary that
can be run, when the command is "podman system migrate".

Signed-off-by: Nalin Dahyabhai <nalin@redhat.com>
2023-03-09 15:04:04 -05:00
Giuseppe Scrivano 39cac28763
chunked: report the correct size
report the correct size for a layer that was pulled
using the chunked package.

Signed-off-by: Giuseppe Scrivano <gscrivan@redhat.com>
2023-02-27 20:25:55 +01:00
Miloslav Trmač a1ccc9d862 Use os.WriteFile instead of ioutil.WriteFile
Signed-off-by: Miloslav Trmač <mitr@redhat.com>
2022-09-12 16:31:34 +02:00
Daniel J Walsh 3f8c0dc0de
Wrap errors properly with fmt.Errorf
Also returned errors should not begine with a capatalized errors.

Signed-off-by: Daniel J Walsh <dwalsh@redhat.com>
2022-07-12 13:26:10 -04:00
Sascha Grunert 3455d12729
Switch to golang native error wrapping
We now use the golang error wrapping format specifier `%w` instead of the
deprecated github.com/pkg/errors package.

Signed-off-by: Sascha Grunert <sgrunert@redhat.com>
2022-07-07 13:22:46 +02:00
Giuseppe Scrivano 268af00013
chunked: drop host dedup feature
drop host deduplication by just looking at the file path.  It could be
useful in very specific use cases, but it is too expensive for generic
images.  If the need arises, we first need to create an index of the
files that we can deduplicate so there is no need to calculate the
checksum on the fly.

Signed-off-by: Giuseppe Scrivano <gscrivan@redhat.com>
2022-06-07 15:32:34 +02:00
Giuseppe Scrivano 75fd4d6c7b
chunked: recalculate correctly the chunks to request
after the missing parts are merged, it is necessary to recalculate the
chunks to ask to the server.

Signed-off-by: Giuseppe Scrivano <gscrivan@redhat.com>
2022-05-11 17:21:38 +02:00
Giuseppe Scrivano 90fd24cd05
chunked: validate number of chunks received
Signed-off-by: Giuseppe Scrivano <gscrivan@redhat.com>
2022-05-11 17:21:38 +02:00
Valentin Rothberg f0324e1976 insufficient IDs errors: mention podman-system-migrate
Based on a conversation on the Podman mailing list:
Mentioning podman-system-migrate in the error message may help users
resolve their issues faster.

Signed-off-by: Valentin Rothberg <vrothberg@redhat.com>
2022-02-23 14:52:47 +01:00
Giuseppe Scrivano 33f973c732
Revert "chunked: use valyala/gozstd"
This reverts commit 5bb6d8e65e.

Signed-off-by: Giuseppe Scrivano <gscrivan@redhat.com>
2022-01-17 16:16:46 +01:00
Giuseppe Scrivano 198820877c
pkg/chunked: add support for sparse files
automatically detect holes in sparse files (the threshold is hardcoded
at 1kb for now) and add this information to the manifest file.

The receiver will create a hole (using unix.Seek and unix.Ftruncate)
instead of writing the actual zeros.

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

Signed-off-by: Giuseppe Scrivano <gscrivan@redhat.com>
2022-01-13 13:32:13 +01:00
Giuseppe Scrivano 5bb6d8e65e
chunked: use valyala/gozstd
Signed-off-by: Giuseppe Scrivano <gscrivan@redhat.com>
2022-01-10 11:28:15 +01:00
Giuseppe Scrivano 2edca4eb72
chunked: validate chunk digest
Signed-off-by: Giuseppe Scrivano <gscrivan@redhat.com>
2022-01-10 11:27:43 +01:00
Giuseppe Scrivano 63be926601
chunked: copy local files from multiple goroutines
Signed-off-by: Giuseppe Scrivano <gscrivan@redhat.com>
2022-01-10 11:27:42 +01:00
Giuseppe Scrivano 0d21b61022
chunked: use just created parent directory
Signed-off-by: Giuseppe Scrivano <gscrivan@redhat.com>
2022-01-10 11:27:42 +01:00
Giuseppe Scrivano 9b95fc1428
chunked: factor out function
Signed-off-by: Giuseppe Scrivano <gscrivan@redhat.com>
2022-01-10 11:27:42 +01:00
Giuseppe Scrivano ed714c799b
chunked: avoid duplicated file path in error message
Signed-off-by: Giuseppe Scrivano <gscrivan@redhat.com>
2022-01-10 11:27:42 +01:00
Giuseppe Scrivano 0621da79cc
chunked: improve json parsing
reduce the number of allocations done by the parser by reading into a
bytes.Buffer.

Signed-off-by: Giuseppe Scrivano <gscrivan@redhat.com>
2022-01-10 11:27:42 +01:00
Giuseppe Scrivano 048f7c08ad
chunked: use json-iterator
Signed-off-by: Giuseppe Scrivano <gscrivan@redhat.com>
2022-01-10 11:27:42 +01:00
Giuseppe Scrivano 10697a05a2
chunked: implement lookaside cache
avoid parsing each json TOC file for the layers in the local storage,
but attempt to create a lookaside cache in a custom format faster to
load (and potentially be mmap'able).

The same cache is used to lookup files, chunks and candidates for
deduplication with hard links.

There are 3 kind of digests stored:

- digest(file.payload))
- digest(digest(file.payload) + file.UID + file.GID + file.mode + file.xattrs)
- digest(i) for each i in chunks(file payload)

Signed-off-by: Giuseppe Scrivano <gscrivan@redhat.com>
2022-01-10 11:27:42 +01:00
Giuseppe Scrivano a5f0cddf2b
chunked: use just created parent directory
a reference to the just created parent directory is already opened, so
use it directly.

Signed-off-by: Giuseppe Scrivano <gscrivan@redhat.com>
2022-01-10 11:27:42 +01:00
Giuseppe Scrivano 834db5aab5
chunked: split appendCompressedStreamToFile
Signed-off-by: Giuseppe Scrivano <gscrivan@redhat.com>
2022-01-10 11:27:40 +01:00
Giuseppe Scrivano 12e9b991dc
chunked: optimize mergeTocEntries
avoid using slices.  I've seen a drop of ~20M in memory
usage with a fedora image.

Signed-off-by: Giuseppe Scrivano <gscrivan@redhat.com>
2022-01-10 11:26:15 +01:00
Giuseppe Scrivano b04b70a8bc
chunked: move file close to separate goroutine
Signed-off-by: Giuseppe Scrivano <gscrivan@redhat.com>
2022-01-10 11:26:15 +01:00
Giuseppe Scrivano 373605310d
chunked: use a static buffer for io operations
Signed-off-by: Giuseppe Scrivano <gscrivan@redhat.com>
2022-01-07 21:28:17 +01:00
Giuseppe Scrivano 4e8554e228
storage: reuse zstd decoder
Signed-off-by: Giuseppe Scrivano <gscrivan@redhat.com>
2022-01-07 21:28:16 +01:00
Giuseppe Scrivano 96fc5c872a
chunked: omit empty fields in json manifest
Signed-off-by: Giuseppe Scrivano <gscrivan@redhat.com>
2022-01-07 21:28:16 +01:00
Giuseppe Scrivano ba1c626d68
chunked: release zstd on termination 2022-01-07 21:28:16 +01:00
Giuseppe Scrivano 526c57d8b0
chunked: reuse cache
try to reuse an existing cache object, instead of creating it for
every layer.

Set a time limit on how long it can be reused so to clean up stale
references.

Signed-off-by: Giuseppe Scrivano <gscrivan@redhat.com>
2022-01-07 21:28:16 +01:00
Giuseppe Scrivano be4e8f622d
chunked: move copy logic to storage_linux.go
Signed-off-by: Giuseppe Scrivano <gscrivan@redhat.com>
2022-01-07 21:28:16 +01:00
Giuseppe Scrivano bfd9c8046e
chunked: chunk deduplication
Signed-off-by: Giuseppe Scrivano <gscrivan@redhat.com>
2022-01-07 21:28:15 +01:00
Giuseppe Scrivano f18141fa76
chunked: move cache to separate file
Signed-off-by: Giuseppe Scrivano <gscrivan@redhat.com>
2021-12-24 13:28:25 +01:00
Giuseppe Scrivano dce078f3ae
chunked: move discard call to outer scope
it solves a problem where the discard could be performed before the
compression handler was closed (through a deferred call).

Signed-off-by: Giuseppe Scrivano <gscrivan@redhat.com>
2021-12-24 13:28:25 +01:00
Giuseppe Scrivano 24b99d165f
chunked: support copy from uncompressed stream
Signed-off-by: Giuseppe Scrivano <gscrivan@redhat.com>
2021-12-24 13:28:25 +01:00
Giuseppe Scrivano 22ba9b01ef
chunked: add infra to dedup from partial file
Signed-off-by: Giuseppe Scrivano <gscrivan@redhat.com>
2021-12-24 13:28:25 +01:00
Giuseppe Scrivano 8e67467c2f
chunked: allow streaming to the same file
Signed-off-by: Giuseppe Scrivano <gscrivan@redhat.com>
2021-12-24 13:28:25 +01:00
Giuseppe Scrivano 20282b354b
chunked: rename types
Signed-off-by: Giuseppe Scrivano <gscrivan@redhat.com>
2021-12-23 14:11:16 +01:00
Giuseppe Scrivano 8fabddd147
chunked: drop argument mode
Signed-off-by: Giuseppe Scrivano <gscrivan@redhat.com>
2021-12-23 14:11:16 +01:00
Giuseppe Scrivano 2e6acd4035
chunked: move check to helper function
Signed-off-by: Giuseppe Scrivano <gscrivan@redhat.com>
2021-12-23 14:11:16 +01:00
Daniel J Walsh 13f2d571d1
Merge pull request #1077 from giuseppe/ignore-security-selinux
archive: ignore the security.selinux xattr
2021-11-29 10:59:56 -05:00
Giuseppe Scrivano ce5ea8e816
chunked: ignore security.selinux
Signed-off-by: Giuseppe Scrivano <gscrivan@redhat.com>
2021-11-26 11:00:59 +01:00
Giuseppe Scrivano 94c46e4cc6
chunked: add fallback for openat2
add a fallback mechanism when openat2 is not supported by the
underlying kernel.

If a call to openat2 fails with ENOSYS, then fallback to a user space
lookup.  Generally the user space lookup is not safe, since symlinks
lookups are vulnerable to TOCTOU attacks, but in this case where the
rootfs is being created, there are no other processes modifying it
thus such lookups can be considered safe.

Signed-off-by: Giuseppe Scrivano <gscrivan@redhat.com>
2021-11-26 09:29:55 +01:00
Giuseppe Scrivano 4be78487cb
chunked: refactor common code in a function
Signed-off-by: Giuseppe Scrivano <gscrivan@redhat.com>
2021-11-25 14:49:35 +01:00
Giuseppe Scrivano f26ed33fbf
chunked: wrap the correct underlying error
Signed-off-by: Giuseppe Scrivano <gscrivan@redhat.com>
2021-11-25 14:49:08 +01:00
Giuseppe Scrivano a72972c5ee
chunked: fix setting attributes for symlinks
when dealing with symlink, open the parent directory and use the
symlink basename to set its attributes.

Signed-off-by: Giuseppe Scrivano <gscrivan@redhat.com>
2021-11-23 21:13:23 +01:00
Giuseppe Scrivano 501611fd51
chunked: create missing parent directories
when creating a new file, handle the case where any of the parent
directories are missing and create them automatically if needed.

Signed-off-by: Giuseppe Scrivano <gscrivan@redhat.com>
2021-11-23 21:13:22 +01:00
Giuseppe Scrivano 8d6af4b7f0
chunked: improve error messages
add more context to the error messages generated while unpacking the
image.

Signed-off-by: Giuseppe Scrivano <gscrivan@redhat.com>
2021-11-23 21:13:22 +01:00
Giuseppe Scrivano da2733a4e4
pkg/chunked, pkg/idtools: adjust error message
since we now support reading additional IDs with libsubid, clarify
that the /etc/subuid and /etc/subgid files are honored only when
shadow-utils is configured to use them.

[NO TESTS NEEDED]

Signed-off-by: Giuseppe Scrivano <gscrivan@redhat.com>
2021-11-08 13:12:45 +01:00
Giuseppe Scrivano fff3e7117b
chunked: fix another occurrence of linkat
Using unix.AT_EMPTY_PATH requires CAP_DAC_READ_SEARCH.  Use an
equivalent variant that uses /proc/self/fd that can be used with
rootless.

Signed-off-by: Giuseppe Scrivano <gscrivan@redhat.com>
2021-11-03 10:32:55 +01:00
Giuseppe Scrivano a5a3c6020b
chunked: implement OSTree deduplication
if the option ostree_repos is set:

    [storage.options]
    pull_options = {enable_partial_images = "true", ostree_repos = "/foo:/bar"}

then attempt to deduplicate from the specified list of OSTree repositories.

In order to be usable, an OSTree repository must be configured to track
the checksum for its files payload (payload link), that is disabled by
default:

ostree config --repo=/path/to/repo set core.payload-link-threshold N

Where N is the minimum size for files to be tracked by their payload
and must be a nonzero value.

Signed-off-by: Giuseppe Scrivano <gscrivan@redhat.com>
2021-09-24 10:56:46 +02:00
Giuseppe Scrivano 980f24ec58
chunked: fix linkat for rootless
Using unix.AT_EMPTY_PATH requires CAP_DAC_READ_SEARCH.  Use an
equivalent variant that uses /proc/self/fd that can be used with
rootless.

Signed-off-by: Giuseppe Scrivano <gscrivan@redhat.com>
2021-09-06 10:37:16 +02:00
Giuseppe Scrivano 4ef5ee00ab
chunked: restrict dedup with hard links
before deduplicating with hard links make sure the two files share the
same UID, GID, file mode and extended attributes.

Signed-off-by: Giuseppe Scrivano <gscrivan@redhat.com>
2021-09-06 10:37:15 +02:00
Giuseppe Scrivano d00974a9aa
chunked: cache all the files with the same digest
this is a preparation change for the next commit.

Signed-off-by: Giuseppe Scrivano <gscrivan@redhat.com>
2021-09-03 13:03:03 +02:00
Giuseppe Scrivano 31d1330f74
chunked: do not store the digest if it is empty
Signed-off-by: Giuseppe Scrivano <gscrivan@redhat.com>
2021-09-03 12:26:19 +02:00
Giuseppe Scrivano 2855d17137
chunked: estargz support
in addition to zstd:chunked, add support for the estargz format.

estargz is maintained at github.com/containerd/stargz-snapshotter

Images using estargz can be used on old clients and registries that
have no support for the zstd compression algorithm.

Signed-off-by: Giuseppe Scrivano <gscrivan@redhat.com>
2021-08-25 16:16:20 +02:00
Giuseppe Scrivano 8694b29402
chunked: remove unused args
Signed-off-by: Giuseppe Scrivano <gscrivan@redhat.com>
2021-08-18 09:25:50 +02:00
Giuseppe Scrivano 76e458bfbe
chunked: fix fd leak on error
Signed-off-by: Giuseppe Scrivano <gscrivan@redhat.com>
2021-08-18 08:17:40 +02:00
Giuseppe Scrivano 0f9ccfe64a
chunked: remove unused argument missingDirsMode
Signed-off-by: Giuseppe Scrivano <gscrivan@redhat.com>
2021-08-18 08:17:39 +02:00
Giuseppe Scrivano c85d07f33b
chunked: add new pull option use_hard_links
if the option use_hard_links is set:

[storage.options]
pull_options = {use_hard_links = "true"}

then attempt to deduplicate files using hard links first.

Signed-off-by: Giuseppe Scrivano <gscrivan@redhat.com>
2021-08-18 08:17:39 +02:00
Giuseppe Scrivano a68c6e1cbf
chunked: allow to disable partial images feature
enable partial pulls only when it is explicitely configured in the
storage.conf file:

[storage.options]

pull_options = {enable_partial_images = "true"}

This is to prevent the experimental feature to leak into CRI-O.

The default value will change in future once the feature is stable.

Signed-off-by: Giuseppe Scrivano <gscrivan@redhat.com>
2021-08-17 09:32:36 +02:00
Miloslav Trmač 92b63ead41 Split pkg/chunked.ZstdCompressor into a separate subpackage
containers/image/pkg/compression depends on that function, so it's
highly undesirable for it to drag in all of containers/storage.

So, move it into a separate subpackage, along with its exclusive
dependency tree.

Code that is called both from the new pkg/chunked/compressor
and the original pkg/chunked has been moved into pkg/chunked/internal ,
so that we don't expose any new public API. That move was made
purely mechanically without any concern for conceptual consistency,
to minimize the size of the dependency (and not to spend time on
that until the concept is proven to be useful).

Signed-off-by: Miloslav Trmač <mitr@redhat.com>
2021-07-23 21:43:52 +02:00
Giuseppe Scrivano bfa0c220a5
chunked: fix the path used for layers dedup
`source` is the path to the layer that already contains the file that
is looked up.

Signed-off-by: Giuseppe Scrivano <gscrivan@redhat.com>
2021-07-01 00:02:06 +02:00
Giuseppe Scrivano 5494513f2e
chunked: fix build on other platforms
fix package build on !linux platforms

Signed-off-by: Giuseppe Scrivano <gscrivan@redhat.com>
2021-05-25 14:42:28 +02:00