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

Add support for external blobs #22

Merged
merged 2 commits into from
Sep 30, 2024

Conversation

ariel-miculas
Copy link
Collaborator

This feature is especially useful when we want to share blobs across OCI repositories. See the --dest-shared-blob-dir option in skopeo [1] as well as the LXC OCI template [2] (specifically OCI_USE_CACHE).

closes #21

[1] https://github.com/containers/skopeo/blob/main/docs/skopeo-copy.1.md
[2] https://github.com/lxc/lxc/blob/main/templates/lxc-oci.in

Copy link
Collaborator

@cgwalters cgwalters left a comment

Choose a reason for hiding this comment

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

Nice and simple, I only have minor nits.

PR title/commit message I think should be updated - this isn't about symlinks anymore.

Something like:

Add support for external blobs

?

src/lib.rs Outdated
/// This is useful when `blobs/sha256` might contain symlinks pointing outside the oci
/// directory, e.g. when sharing blobs across OCI repositories. The LXC OCI template uses this
/// feature.
pub fn open_with_external_blobs(dir: &Dir, blobs_dir: Dir) -> Result<Self> {
Copy link
Collaborator

Choose a reason for hiding this comment

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

I'm ok with this as is to be clear but it definitely feels inconsistent to have one take a ref and the other an owned value.

With just a small refactoring we could have both take owned values instead right?

Copy link
Collaborator

Choose a reason for hiding this comment

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

Or we take refs and do the try_clone() for both, if I had to make a call I'd probably say let's do that, but not strongly held.

Copy link
Collaborator Author

Choose a reason for hiding this comment

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

I actually prefer to take owned values for both. It would remove the try_clone, but what I really would like to avoid is sharing the underlying file handle, where you could seek through a reference, read through the other and observe the side effect of the seek. I know I've linked the example for files, but I assume there would be similar semantics for directories. I would like to entirely avoid having to deal with such behavior.

Copy link
Collaborator Author

Choose a reason for hiding this comment

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

I guess one concern with this approach is that it's a breaking change.

Copy link
Collaborator

Choose a reason for hiding this comment

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

I guess one concern with this approach is that it's a breaking change.

Yes. Now let's try to roll up a few other cleanups at least to make the semver bump worth it.

@ariel-miculas
Copy link
Collaborator Author

ariel-miculas commented Sep 26, 2024

Nice and simple, I only have minor nits.

PR title/commit message I think should be updated - this isn't about symlinks anymore.

Something like:

Add support for external blobs

?

Oh, I see, it's because you can pass whatever blobs directory you want, it doesn't have to go through a symlink. Took me a while to understand.

This feature is especially useful when we want to share blobs across OCI
repositories. See the `--dest-shared-blob-dir` option in skopeo [1] as
well as the LXC OCI template [2] (specifically OCI_USE_CACHE).

Usually this is done via symlinking oci/blobs or oci/blobs/sha256, but
ocidir-rs doesn't follow symlinks which lead outside the oci directory
(this is by design). This commit doesn't change the capability model, it
only addresses the blob sharing use case by adding a new
open_with_external_blobs function which takes the blobs directory as a
separate cap_std::Dir. The library won't allow any accesses outside the
blobs directory, but instead of reading the blobs directory from the OCI
directory, it will directly read the user supplied blobs directory.

closes containers#21

[1] https://github.com/containers/skopeo/blob/main/docs/skopeo-copy.1.md
[2] https://github.com/lxc/lxc/blob/main/templates/lxc-oci.in

Signed-off-by: Ariel Miculas-Trif <amiculas@cisco.com>
They now both take owned values of type cap_std::Dir for both parameters
instead of references to cap_std::Dir. The reason for owned values
instead of references is avoiding the undesired effects of sharing the
same underlying file handle [1].

[1] https://doc.rust-lang.org/nightly/std/fs/struct.File.html#method.try_clone

Signed-off-by: Ariel Miculas-Trif <amiculas@cisco.com>
@ariel-miculas ariel-miculas force-pushed the support-symlinks-for-blob branch from 44088b6 to 0a88546 Compare September 26, 2024 18:36
@ariel-miculas
Copy link
Collaborator Author

@cgwalters any objections to the latest changes? If not, I'll go ahead and merge this.

@cgwalters cgwalters merged commit 97ffb16 into containers:main Sep 30, 2024
3 checks passed
@ariel-miculas ariel-miculas changed the title Add support for symlinks in blobs/sha256 path Add support for external blobs Oct 14, 2024
ariel-miculas added a commit to ariel-miculas/puzzlefs that referenced this pull request Oct 14, 2024
…I repos

Use open_with_external_blobs which adds support for external blobs,
added in ocidir-rs [1].
We'll use the latest version of ocidir-rs from github and we'll switch
to version 0.4.0 when it gets released.

Closes project-machine#131

[1] containers/ocidir-rs#22

Signed-off-by: Ariel Miculas-Trif <amiculas@cisco.com>
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.

Support symlinks for the blobs/sha256 directory
2 participants