Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Expect UncompressedDigest to be set for partial pulls, enforce DiffID match #2613

Merged
merged 15 commits into from
Jan 21, 2025

Conversation

mtrmac
Copy link
Collaborator

@mtrmac mtrmac commented Oct 30, 2024

Requires containers/storage#2155

  • If a layer has a TOC, require that it must have a DiffID commitment in the config’s RootFS.DiffIDs, or refuse to pull it partially.
  • Layers without a TOC continue to be allowed to use the partial pull code path, and we don't even require config's RootFS.DiffIDs to be present.
  • If a layer has a TOC digest (i.e. could possibly be pulled partially), and c/storage has computed the uncompressed digest, require that the config's RootFS.DiffIDs exists and matches. This fixes the “view ambiguity” of partially-pulled layers.
  • For all layers, if RootFS.DiffIDs exists and we know the layer’s uncompressed digest, also require the RootFS.DiffID value to match. This might be a compatibility break, but Docker requires these values anyway.
  • We happen to allow setting DiffIDs to empty values, if the layer does not have a TOC digest (so there is no risk of “view ambiguity”).

See individual commit messages for details.

mtrmac added a commit to mtrmac/libpod that referenced this pull request Oct 30, 2024
mtrmac added a commit to mtrmac/libpod that referenced this pull request Oct 30, 2024
mtrmac added a commit to mtrmac/libpod that referenced this pull request Oct 30, 2024
storage/storage_dest.go Outdated Show resolved Hide resolved
mtrmac added a commit to mtrmac/libpod that referenced this pull request Nov 18, 2024
mtrmac added a commit to mtrmac/libpod that referenced this pull request Nov 18, 2024
mtrmac added a commit to mtrmac/libpod that referenced this pull request Nov 18, 2024
@mtrmac mtrmac force-pushed the wip-authentic branch 3 times, most recently from e46c8d0 to eb0db7b Compare November 22, 2024 20:15
mtrmac added a commit to mtrmac/libpod that referenced this pull request Nov 25, 2024
> go mod edit -replace github.com/containers/image/v5=github.com/mtrmac/image/v5@wip-authentic

Signed-off-by: Miloslav Trmač <[email protected]>
@mtrmac mtrmac force-pushed the wip-authentic branch 4 times, most recently from 95cdcf3 to 57b0637 Compare November 26, 2024 20:38
mtrmac added a commit to mtrmac/libpod that referenced this pull request Nov 26, 2024
> go mod edit -replace github.com/containers/image/v5=github.com/mtrmac/image/v5@wip-authentic

Signed-off-by: Miloslav Trmač <[email protected]>
@mtrmac mtrmac force-pushed the wip-authentic branch 3 times, most recently from 137b760 to 4fb4df8 Compare November 28, 2024 20:42
mtrmac added a commit to mtrmac/libpod that referenced this pull request Nov 28, 2024
> go mod edit -replace github.com/containers/image/v5=github.com/mtrmac/image/v5@wip-authentic

Signed-off-by: Miloslav Trmač <[email protected]>
mtrmac added a commit to mtrmac/libpod that referenced this pull request Nov 29, 2024
> go mod edit -replace github.com/containers/image/v5=github.com/mtrmac/image/v5@wip-authentic

Signed-off-by: Miloslav Trmač <[email protected]>
@mtrmac
Copy link
Collaborator Author

mtrmac commented Nov 29, 2024

@giuseppe RFC. I still need to address / review some corner cases, but I think the broad outline is settled now, and Podman tests are passing.

@mtrmac mtrmac force-pushed the wip-authentic branch 2 times, most recently from d7fdde4 to c1036a6 Compare December 9, 2024 22:26
@mtrmac
Copy link
Collaborator Author

mtrmac commented Dec 10, 2024

@giuseppe PTAL for an early review. This is mostly untested, but it should be feature-complete and comprehensive.

Contrary to the original plan for containers/storage#2180 , this minimizes the impact on pull_options.convert_images: schema1 and non-TOC layers are always allowed to use the partial pull code path. Only TOC-containing layers may skip it, if the config does not contain DiffID values.

@mheon
Copy link
Member

mheon commented Jan 21, 2025

LGTM, though given my unfamiliarity with the codebase a review from someone else would be much more valuable.

@TomSweeneyRedHat
Copy link
Member

@nalind or @rhatdan or @giuseppe could one of you give this an eyeball please?

Copy link
Member

@giuseppe giuseppe left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

LGTM

mtrmac added a commit to mtrmac/libpod that referenced this pull request Jan 21, 2025
> go mod edit -replace github.com/containers/image/v5=github.com/mtrmac/image/v5@wip-authentic

Signed-off-by: Miloslav Trmač <[email protected]>
@TomSweeneyRedHat
Copy link
Member

LGTM

@TomSweeneyRedHat
Copy link
Member

Great work @mtrmac !
/lgtm

mtrmac added 15 commits January 21, 2025 22:11
reused.Digest is not always blobDigest, it might be
uncompressedDigest; but we must have a blobDiffIDs entry
for reused.Digest.

Signed-off-by: Miloslav Trmač <[email protected]>
... because we will start enforcing that the DiffID values match.

Signed-off-by: Miloslav Trmač <[email protected]>
We will use the trustedLayerIdentityData for other purposes in the caller as well.

Should not change behavior.

Signed-off-by: Miloslav Trmač <[email protected]>
Keep the commit queuing logic together, this is more of an
implementation detail of commitLayer.

Only moves unchanged code, should not change behavior.

Signed-off-by: Miloslav Trmač <[email protected]>
It's fairly isolated from the rest of the function,
and if split, it can have unit tests. Those tests are valuable
to ensure that layer IDs continue to behave the expected way
and maximize layer reuse (although we are not making an API commitment
to layer ID values).

Should not change behavior.

Signed-off-by: Miloslav Trmač <[email protected]>
Should not change behavior.

Signed-off-by: Miloslav Trmač <[email protected]>
... to simplify some of the repetitive logging code.

Should not change behavior.

Signed-off-by: Miloslav Trmač <[email protected]>
untrustedLayerDiffID currently specializes the "not available yet"
case; also specialize the "image does not provide this at all"
case, which we will need to handle.

Should not change behavior.

Signed-off-by: Miloslav Trmač <[email protected]>
Two different locations in the function need the data, and the
caller must have it available; so always passing it in simplifies
the implementation and removes an impossible error path.

This might hypothetically make layer reuse a bit worse, if we
happened to learn something for trustedLayerIdentityData from
processing other layers of the same image, but reusing the same
layer twice within an image should be rare.

Signed-off-by: Miloslav Trmač <[email protected]>
…ema1 images

Should not change behavior; we call GetTOCDigest in copy.imageCopier.copyLayer
before reaching PutBlobPartial, so the new error path should not be reachable.

Signed-off-by: Miloslav Trmač <[email protected]>
…ID values

If a layer has a TOC, require that it must have a DiffID commitment, or refuse
to pull it partially.

Layers without a TOC continue to be allowed to use the partial pull code path,
and we don't even require config's RootFS.DiffID to be present.

Signed-off-by: Miloslav Trmač <[email protected]>
Remove some completely redundant comments to shorten the code,
clarify where appropriate.

Should not change behavior.

Signed-off-by: Miloslav Trmač <[email protected]>
- If a layer has a TOC digest (i.e. could possibly be pulled partially),
  and c/storage has computed the uncompressed digest, require that
  the config's RootFS.DiffIDs exists and matches. This fixes the
  "view ambiguity" of partially-pulled layers.
- For _all_ layers, if RootFS.DiffIDs exists and we know the layer's
  uncompressed digest, also require the RootFS.DiffIDs value to match.
  This might be a compatibility break, but Docker requires these
  values anyway.
- We happen to allow setting DiffIDs to empty values, if the layer does
  not have a TOC digest (so there is no risk of "view ambiguity").

Signed-off-by: Miloslav Trmač <[email protected]>
@mtrmac mtrmac merged commit 77582bb into containers:main Jan 21, 2025
10 checks passed
@mtrmac mtrmac deleted the wip-authentic branch January 21, 2025 21:47
mtrmac added a commit to mtrmac/libpod that referenced this pull request Jan 21, 2025
This resolves the "signing ambiguity" by requiring that images
must have a DiffID entry, and it must match, in partial pulls.

Signed-off-by: Miloslav Trmač <[email protected]>
mtrmac added a commit to mtrmac/libpod that referenced this pull request Jan 22, 2025
This resolves the "signing ambiguity" by requiring that images
must have a DiffID entry, and it must match, in partial pulls.

Signed-off-by: Miloslav Trmač <[email protected]>
mtrmac added a commit to mtrmac/libpod that referenced this pull request Jan 22, 2025
This resolves the "signing ambiguity" by requiring that images
must have a DiffID entry, and it must match, in partial pulls.

Signed-off-by: Miloslav Trmač <[email protected]>
mtrmac added a commit to mtrmac/libpod that referenced this pull request Jan 22, 2025
This resolves the "signing ambiguity" by requiring that images
must have a DiffID entry, and it must match, in partial pulls.

Signed-off-by: Miloslav Trmač <[email protected]>
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

Successfully merging this pull request may close these issues.

4 participants