Repository navigation
fix: verify pulled blobs and manifests against their digest - #266
Rohilalala wants to merge 1 commit into
Conversation
| for chunk in r.iter_content(chunk_size=8192): | ||
| if chunk: | ||
| f.write(chunk) | ||
| # Write beside the target and move it into place only once it |
There was a problem hiding this comment.
Please make this into an isolated function we can call, in utils or alongside digest helpers would be preferable.
There was a problem hiding this comment.
Moved it into oras/utils/fileio.py next to get_file_hash. write_verified_file(filename, chunks, digest) does the streamed write and check, and check_digest(content, digest) covers manifests, so layout.py calls that too instead of a method on the provider.
Two small changes came with the move. The staging file is now .<uuid>.partial in the same directory, because a fixed <name>.partial could overwrite a real file with that name and failed for names close to the 255-byte limit. And get_manifest now checks the digest after parsing the JSON, so a digest-pinned pull that gets an HTML page back still shows the #223 message.
| __license__ = "Apache-2.0" | ||
|
|
||
| __version__ = "0.2.44" | ||
| __version__ = "0.2.45" |
There was a problem hiding this comment.
Double check the version here - I think we haven't released 0.2.44 yet.
download_blob now hashes the blob while streaming it into a temporary file beside the target, and moves it into place only when the content matches the requested digest, so a mismatched or interrupted download never leaves a file under the blob's name. get_manifest checks the manifest when it is requested by digest, and the OCI layout pull checks the manifest against the Docker-Content-Digest header it records, the requested digest, and each index child against its descriptor. Both checks live in oras.utils (check_digest, write_verified_file) next to get_file_hash. Closes oras-project#247 Signed-off-by: Aditya <205600203+Rohilalala@users.noreply.github.com>
c8cf8dc to
2e465a2
Compare
Content fetched from a registry was never checked against the digest it was requested by:
download_blobsaved whatever bytes came back,get_manifestreturned any manifest for arepo@sha256:…reference, and the OCI layout pull stored the manifest under itsDocker-Content-Digestheader without checking the header against the body (the distribution spec says a client that uses that header must verify it).Now:
download_blobhashes the blob while streaming it into a temporary file besideoutfileand moves it into place only when it matches, so a mismatched or interrupted download never leaves a file under the blob's name. A mismatch raisesValueError. The logic isoras.utils.write_verified_file, withoras.utils.check_digestfor manifests.get_manifestchecks a manifest requested by digest.A digest algorithm
hashlibdoesn't support now raises instead of downloading unchecked. Tag pulls throughget_manifest(which don't use the header) are unchanged.Closes #247 (picks it up after #245 was closed).