Commit Graph

26 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č e66b4773a9 Beautify storageImageSource.LayerInfosForCopy
Exit early on error.

Should not change behavior.

Signed-off-by: Miloslav Trmač <mitr@redhat.com>
2024-02-15 19:33:09 +01:00
Miloslav Trmač 7188fd4dd6 Update out-of-date comments
Should not change behavior.

Signed-off-by: Miloslav Trmač <mitr@redhat.com>
2024-02-15 19:33:00 +01:00
Miloslav Trmač a3222f6b68 Support pulling and pushing fully-consumed partial layers
... and identify them using UncompressedDigest, not TOCDigest

On pushes, also use the trusted UncompressedDigest if available
instead of preferring the untrusted value when a TOC digest
is present.

Signed-off-by: Miloslav Trmač <mitr@redhat.com>
2024-02-13 20:19:43 +01:00
Miloslav Trmač 100081eb00 Fix the documentation related to getBlobMutex*
Signed-off-by: Miloslav Trmač <mitr@redhat.com>
2024-02-09 18:03:33 +01:00
Miloslav Trmač 6c9a2e25ce Move getBlobMutexProtected after storageImageSource
... so that the fields of storageImageSource read in
approximately natural order.

Only moves unchanged code, should not change behavior.

Signed-off-by: Miloslav Trmač <mitr@redhat.com>
2024-02-09 18:03:27 +01:00
Miloslav Trmač e34346bd58 Document expectedLayerDiffIDFlag
Signed-off-by: Miloslav Trmač <mitr@redhat.com>
2024-02-09 18:03:14 +01:00
Miloslav Trmač 4cc225e197 Define storageImageMetadata for the JSON in Image.Metadata
This way we:
- have a single type, guaranteeing the source and destination don't
  get out of sync
- separate the JSON-encoded data, without having to worry about
  Marshal/Unmarshal affecting unrelated fields of the source/destination.

Should not change behavior.

Signed-off-by: Miloslav Trmač <mitr@redhat.com>
2024-02-08 02:10:39 +01:00
Yaroslav Halchenko 498178b59a [DATALAD RUNCMD] run codespell throughout but ignore fail
=== Do not change lines below ===
{
 "chain": [],
 "cmd": "codespell -w || :",
 "exit": 0,
 "extra_inputs": [],
 "inputs": [],
 "outputs": [],
 "pwd": "."
}
^^^ Do not change lines above ^^^

Signed-off-by: Yaroslav Halchenko <debian@onerussian.com>
2023-12-08 16:20:31 -05:00
Giuseppe Scrivano b15a850b60
storage: store the diffID and use for validation
when copying a partial image, store the expected diffID so that it can
be later used to validate the obtained layer stream.

Signed-off-by: Giuseppe Scrivano <gscrivan@redhat.com>
2023-12-06 09:35:45 +01:00
Giuseppe Scrivano 10ee1549bf
storage: accept layers without UncompressedDigest
Signed-off-by: Giuseppe Scrivano <gscrivan@redhat.com>
2023-12-05 22:08:26 +01:00
Mike Norgate 62835fec67
fix removal of temp file in GetBlob on Windows
Signed-off-by: Mike Norgate <mike.norgate@mythical.games>
2023-09-05 10:38:30 +01:00
Daniel J Walsh f485997b9a
Make temporary names container/image specific
If you hit Ctr-C while pulling an image files and directories get
left in /var/tmp. By adding "containers_images" prefix, we can use
systemd tmpfiles handling to remove them on reboot safely.

Help to make https://github.com/containers/podman/pull/19201 safer.

Signed-off-by: Daniel J Walsh <dwalsh@redhat.com>
2023-07-17 10:24:13 -04:00
Miloslav Trmač 73dc7901b6 Add FIXMEs about handling of zstd:chunked blob annotations on blob changes
It's completely undefined whether the OCI blob annotations apply to
the object as a concept, regardless of representation, or to the specific
binary representation. So it's unclear whether we should preserve or drop them
when compressing/decompressing/substituting blobs.

In particular, we currently don't truly correctly handle the zstd:chunked
annotations on:
- decompression (should be dropped)
- recompression (should be dropped)
- substitution (should be replaced by data about the other blob, if any; we don't record that)

Right now, we drop all annotations on decompression and recompression (which
happens to work fine), and preserve annotations on substitution (which is technically
invalid).

Luckily, the zstd:chunked use is opportunistic, and if the annotations are invalid
or not applicable, the manifest checksum fails, and we fall through to an ordinary pull;
so, that is not quite a deal breaker.

So, for now, just add FIXMEs recording the pain points.

To fix this truly correctly, we would need:
- a new metadataCleaner field in pkg/compression/internal.Algorithm
- a new pkg/compression.CleanMetadata
- turning public manifest.Manifest into internal/manifest.Manifest where we can add methods
- adding internal/manifest.Manifest.LayerInfosWithCompression that turns MIME types into compression.Algorithm values
- (using that in copy.copyLayer instead of the current hard-coded switch)
- then either defining a new alternative to UpdatedImage that can handle these annotations naturally,
  or all the marked users that need to clean the annotations themselves calling LayerInfosWithCompression
  and CleanMetadata on the affected blobs.
- recording the zstd annotations in the blob info cache
- reading those annotations when substituting blobs based on the cache

We should do all that long-term, but that's quite a lot of work to fix a metadata inconsistency
which we can currently silently, with moderate cost, hide from the user.

Signed-off-by: Miloslav Trmač <mitr@redhat.com>
2023-04-03 14:00:44 +02:00
Miloslav Trmač bca868f393 Fix various unused parameters
Usually by removing them, sometimes by actually using an already-available value.

golangci-lint linter: unparam

Signed-off-by: Miloslav Trmač <mitr@redhat.com>
2023-02-14 19:46:41 +01:00
Miloslav Trmač 90b0606973 Start a local variable name with lower case
golangci-lint linter: gocritic

Signed-off-by: Miloslav Trmač <mitr@redhat.com>
2023-02-06 21:23:34 +01:00
Colin Walters 0dd2a85d6a storage: Immediately unlink tmpfile
All we need in this case is an anonymous temporary file, so
unlink the file immediately after creating it.  This avoids
leaking space if the caller forgets to call `Close()` (and the
process exits).

This would have mitigated https://github.com/containers/skopeo/pull/1837
which was a missing `Close()` in the skopeo proxy code.

(It'd be better to use Linux `O_TMPFILE`, but this path is
 portable and avoids a new dependency)

Signed-off-by: Colin Walters <walters@verbum.org>
2023-01-03 14:54:46 -05:00
Alexander Larsson d56226cf70 storage source: Don't store small blobs on disk in GetBlob()
To avoid locking the store for a large time we currently make a copy
of the blob into TemporaryDirectoryForBigFiles (i.e. /var/tmp) when
getting a stream to the blob. During a simple "podman run" this
happens 6 time.

However, all those calls are for the config blob, which we don't stream
anyway, so the temporary copy is unnecessary. This commit moves the
check for a the config blob outside of `getBlobAndLayerID()` allowing
us to return early in the config blob case and avoid the temporary file.

Signed-off-by: Alexander Larsson <alexl@redhat.com>
2022-12-15 09:30:50 +01:00
Miloslav Trmač febb29171f Use io.SeekStart instead of a hard-coded 0
The hard-coded 0 is defined in the API, so this works fine;
this is just a readability improvement.

Should not change behavior.

Signed-off-by: Miloslav Trmač <mitr@redhat.com>
2022-12-08 22:28:26 +01:00
Sascha Grunert 849dd70143 Switch to golang native error wrapping
`github.com/pkg/errors` is deprecated since quite some time so we now
use the native error wrapping for more idiomatic golang.

Signed-off-by: Sascha Grunert <sgrunert@redhat.com>
2022-07-13 16:50:50 +02:00
Miloslav Trmač ad2c293d75 Introduce ImageSource.GetSignaturesWithFormat
Signed-off-by: Miloslav Trmač <mitr@redhat.com>
2022-07-07 13:44:22 +02:00
Miloslav Trmač ba768be6ee Fix error handling
err is necessarily nil at that location, so this was returning
no error indication.

Signed-off-by: Miloslav Trmač <mitr@redhat.com>
2022-07-07 13:30:40 +02:00
Miloslav Trmač 1b6a4bf0d0 Rename local variables in storageImageSource.GetSignatures
We want the "signatures" package name to be visible.

Signed-off-by: Miloslav Trmač <mitr@redhat.com>
2022-07-07 13:30:33 +02:00
Miloslav Trmač cbd13d3dcc Add internal/imagesource/impl.Properties, use it to reduce boilerplate
This matches internal/imagedestination/impl.Properties; it's not
quite worth it for the single value, but the consistency is
attractive.

Should not change behavior.

Signed-off-by: Miloslav Trmač <mitr@redhat.com>
2022-07-05 17:02:24 +02:00
Miloslav Trmač 592371c8be Implement private.ImageSource in non-forwarding transports
This sets up the precedent that all transports should primarily implement
the private interface; that will allow us to make future changes to the
private interface easier, because we can just change the public interface
wrappers in a single place instead of modifying transports - especially
as more stubs are added soonish.

Should not change behavior.

Signed-off-by: Miloslav Trmač <mitr@redhat.com>
2022-07-05 17:02:23 +02:00
Miloslav Trmač c4b384b06d Move storageImageSource into a separate storage/storage_src.go
storage_image.go is becoming too large, and we'd like to
have easy access to both internal/imagesource/impl and
internal/imagedestination/impl, which is easier with separate files.

Only moves unchanged code, should not change behavior.

Signed-off-by: Miloslav Trmač <mitr@redhat.com>
2022-07-05 17:02:23 +02:00