Stream OCI blobs to a verified tempfile

What does this MR do and why?

Adds Client#blob, which streams a layer to a per-blob Tempfile while computing its sha256. It yields the file only when the digest and byte count match the manifest descriptor.

  • A body longer than the descriptor size is cut off as it arrives.
  • A digest that is not sha256 is refused.
  • One download deadline covers the blob and any redirect. A caller can pass the seconds a sync run has left as a budget, which shortens that deadline. A budget of zero or less is refused before any request.
  • A malformed Location raises Client::Error. Error messages name a URL without its query string or userinfo.
  • The redirect to a presigned URL is followed by hand, without the Authorization header.
  • A layer whose descriptor size is above 325 MiB (MAX_BLOB_SIZE) is refused before any request. That is about 4 times the largest published v3 archive, which is 81 MiB compressed.
  • The body of a non-200 answer is dropped under the same deadline, and the download fails past 64 KiB (ERROR_BODY_LIMIT).
  • The deadline is also checked before the 401 retry and before the redirect. A request opens its connection and reads within the shorter of 60 seconds and the time left, and never starts at or past the deadline.
  • The tempfile is removed when the block returns.

Safe alone: nothing calls blob yet.

Part 4 of 7. Previous: feature/pmdb-oci-3-client. Next: feature/pmdb-oci-5-timeline.

Related to #642401

How to set up and validate locally

bundle exec rspec ee/spec/lib/gitlab/package_metadata/oci/client_spec.rb

MR acceptance checklist

  • The specs that cover this slice pass at 85b61eae23: 621 examples in 13 spec files, 0 failures.
  • RuboCop reports no offenses on the changed files.

An AI coding assistant wrote this change. The assistant also ran RuboCop on the changed files and the specs above on a self-managed GitLab development instance on a test VM.

Edited by Andrew Dunn

Merge request reports

Loading
Loading