oras-project / oras-go

ORAS Go library
https://oras.land
Apache License 2.0
168 stars 90 forks source link

Anonymous blob mounting #756

Open ktarplee opened 2 months ago

ktarplee commented 2 months ago

For motivation and background see this

From the spec the from field is now optional when doing blob mounts.

The registry MAY treat the from parameter as optional, and it MAY cross-mount the blob if it can be found.

Wwwsylvia commented 2 months ago

Is this an issue of the distribution-spec? 🤔

ktarplee commented 1 month ago

@Wwwsylvia I'm not sure what you mean. It is not an issue with the distribution spec. The spec gives the client more flexibility in that they do not have to provide the from field if they do not want to. Maybe oras-go is handling this already but I did not see it when looking at it earlier. It seems like even in the case where the source repo is unknown, we would want to always try a POST to /v2/<name>/blobs/uploads/?mount=<digest> to try and benefit from a mount.

Wwwsylvia commented 1 month ago

@ktarplee Thanks for the clarification, I see what you mean now. blobStore.Mount() accepts an empty value of from, https://github.com/oras-project/oras-go/blob/9b6f32158776a699b23edb3db86d053623619b60/registry/remote/repository.go#L770-L773

and oras.Copy only checks if the sourceRepositories slice is empty or not but does not validate each sourceRepository. https://github.com/oras-project/oras-go/blob/9b6f32158776a699b23edb3db86d053623619b60/copy.go#L287-L296

So oras-go technically supports this scenario. Users can do anonymous mounting through something like below:

anonymousMounting := func(ctx context.Context, desc ocispec.Descriptor) ([]string, error) {
      return []string{""}, nil
}
opts := oras.CopyOptions{
      MountFrom = anonymousMounting
}
desc, err := oras.Copy(ctx, src, tagName, dst, tagName, opts)

If needed, we can make if more user friendly though.