Repository navigation
Description
Multipart uploads to S3 do not have working checksum-based synchronization or validations. This can be implemented in two different ways:
- Set additional headers of the known checksums of the file (as a bonus, you can set multiple different checksums on a single file
- If the chunk size is consistent, the local ETag can be calculated for comparison. The chunk size can also be stored as a header, to ensure later calculations can be repeated, This is possible as documented here: http://www.perlmonks.org/?node_id=1140988
What is your rclone version (eg output from
rclone -V)
rclone v1.29Which OS you are using and how many bits (eg Windows 7, 64 bit)
Gentoo Linux, 64-bitWhich cloud storage system are you using? (eg Google Drive)
S3 (Ceph Hammer)The command you were trying to run (eg
rclone copy /tmp remote:tmp)
rclone sync . $REMOTE_NAME:$BUCKET_NAME/ --checksumA log from the command with the
-vflag (eg output fromrclone -v copy /tmp remote:tmp)rclone sync . $REMOTE_NAME:$BUCKET_NAME/ --checksum --dump-headers --dump-bodies 2016/06/14 17:09:27 >>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>> 2016/06/14 17:09:27 HTTP REQUEST 2016/06/14 17:09:27 HEAD /$BUCKET_NAME HTTP/1.1 Host: objects-us-west-1.dream.io User-Agent: rclone/v1.29 Authorization: AWS XXXXXX:Ke4mVHLXl4WUSPoyfVYZ6LoPFiM= Date: Wed, 15 Jun 2016 00:09:27 UTC
2016/06/14 17:09:27 >>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>
2016/06/14 17:09:27 <<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<
2016/06/14 17:09:27 HTTP RESPONSE
2016/06/14 17:09:27 HTTP/1.1 200 OK
Date: Wed, 15 Jun 2016 00:09:27 GMT
X-Amz-Request-Id: tx000000000000001bbb918-0057609cb7-d8d7311-default
X-Rgw-Bytes-Used: 44040192
X-Rgw-Object-Count: 3
Content-Length: 0
2016/06/14 17:09:27 <<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<
2016/06/14 17:09:27 S3 bucket robjoh84-congress-test2: Building file list
2016/06/14 17:09:27 >>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>
2016/06/14 17:09:27 HTTP REQUEST
2016/06/14 17:09:27 GET /$BUCKET_NAME?delimiter=&max-keys=1024&prefix= HTTP/1.1
Host: objects-us-west-1.dream.io
User-Agent: rclone/v1.29
Authorization: AWS XXXXXXXX:lEMCCAZstZ5rJbzqUt25R59v5j8=
Date: Wed, 15 Jun 2016 00:09:27 UTC
Accept-Encoding: gzip
2016/06/14 17:09:27 >>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>
2016/06/14 17:09:27 <<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<
2016/06/14 17:09:27 HTTP RESPONSE
2016/06/14 17:09:27 HTTP/1.1 200 OK
Content-Length: 525
Content-Type: application/xml
Date: Wed, 15 Jun 2016 00:09:27 GMT
X-Amz-Request-Id: tx000000000000001bbb91b-0057609cb7-d8d7311-default
2016/06/14 17:09:27 <<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<
2016/06/14 17:09:27 S3 bucket $BUCKET_NAME: Waiting for checks to finish
2016/06/14 17:09:27 Waiting for deletions to finish
2016/06/14 17:09:27 S3 bucket $BUCKET_NAME: Waiting for transfers to finish
2016/06/14 17:09:27 S3 bucket $BUCKET_NAME: Waiting for deletes to finish (during+after)
Transferred: 0 Bytes ( 0.00 kByte/s)
Errors: 0
Checks: 1
Transferred: 0
Elapsed time: 400ms
Activity
ncw commentedon Jun 15, 2016
I prefer option 1 as there is already a precedent for that - that is how b2 does it. That would also make
rclone md5sumwork and enable checksum based syncing for large files. Option 2 only lets you calcuate the etag when you download the file which is useful, but not as useful for rclone.Is there a de-facto standard for the name of the metadata - I try to keep rclone compatible with other tools if possible?
This could also be implemented for swift (&hubic) - I wonder if there is any standard metadata keys for that also?
ncw commentedon Jun 15, 2016
I asked on StackOverflow a question about a standard metadata key for storing MD5SUMs.
robbat2 commentedon Jun 16, 2016
The closest I've seen to a standard name in S3 tools was
x-amz-meta-$HASHNAME. I did want to mention thatthere is another strong advantage to the ETag method, notably parallel checksumming of large files (assuming you have enough disk IO to feed multiple threads of checksumming).
Maybe support both in headers...
jamshid commentedon Jan 9, 2017
I don't understand this. Using the S3 ETag seems like the better option since it does not require adding a custom header. The S3 ETag is returned in listings, so you don't even have to HEAD the object to validate its checksum against the local file. You certainly don't need to download the file, which would defeat the purpose of .
You don't need to store the chunk size in a separate header since the number of parts is included in the ETag. The format is "HEX MD5 OF EACH PART'S MD5 - NUMBER OF PARTS". The chunk size is simply the
file size / number of parts. with the remainder being the last part.ncw commentedon Jan 9, 2017
@jamshid wrote
Having an actual MD5 of big files would enable cloud to cloud copies from drive to s3 with checking for example, and it would enable
rclone md5sumto work, neither of which would work with Option 1.chris-redekop commentedon Oct 25, 2017
I drafted an implementation of Option 1 for S3. During an update, it detects large files and attaches the MD5 hash as metadata; during a check, it falls back to checking the metadata when the ETag is not an MD5 hash.
I have a question about this implementation and S3-backed crypt remotes. When
S3#Updateasks a crypt proxy for its hash, on line chris-redekop@515def7#diff-7db3cb93944d57b2ffc803281c906018R1009 , crypt returns "" (https://github.com/ncw/rclone/blob/master/crypt/crypt.go#L615 ). This r esults in an empty hash being saved to the metadata, instead of the hash of the encrypted file.To address this, can crypt remotes implement this Hash function by encrypting the proxied file and then calculating its MD5 hash? Should they? I think this would fix MD5 hashes for large encrypted files on S3, but I'm concerned about unintended consequences.
chris-redekop commentedon Nov 26, 2017
I took a closer look support for
ObjectInfo#Hashincrypt::ObjectInfo. I think this would be a great feature, and I think it's doable; but it would need some rework in the hash handshake between file systems. In particular, I think the handshake needs to brokerIn the meantime, I added ETag support to the S3 file system. The change is up in #1863.
ncw commentedon Nov 28, 2017
Sorry @chris-redekop I missed your comment from 25th October.
That is pretty much exactly how the b2 large file hash works. However it has the downside you've pointed out below which are in #1767
They could, but it is likely to mean the file is encrypted twice and possibly transferred twice so not ideal. See #1767 for more discussion!
I'm not sure how you would solve encrypting and transferring the data twice?
To solve the crypt hash problem, I was thinking of making a v2 crypt format which stores a blob of metadata in front of each file. This would be hashes in all supported formats, and also the full name of the file. This would mean that it was relatively cheap to look up the hash of an encrypted file.
chris-redekop commentedon Nov 29, 2017
Thanks for the context. #1767 does go over this issue in detail! I'd like to talk through this "calculate the sum in advance" option a bit more, as it addresses my use case better than #1863: "as a backup operator, I want to (crypt) check the large files that rclone copies to S3".
I do see the need for double encryption--once to calculate the sum in advance and once to transfer the file encrypted. (I don't see a need for a double transfer?) The double encryption seems like a fair tradeoff to me, for four reasons:
My "S3 backup operator with large files" use case needs two encryptions either way:
When I "calculate the sum in advance", I never have to crypt check my backup files. (S3 assured during upload that they match.) This means I avoid re-checking a remote FS to check newly backed-up files, which means I also avoid rechecking the previously backed-up files that I have already checked. In this sense, "calculating the sum in advance" actually reduces the overall number of re-encryptions.
Other than the S3 ETag--which we know doesn't address all use cases--uploading the MD5 sum in advance is the only way to verify large files on S3. There is no other way to confirm that the bytes on S3's side were, e.g., not corrupted during transmission. Note that uploading the MD5 sum later, as arbitrary metadata that S3 does not confirm, does not address this issue. We need S3 to recognize and confirm the sum on its side; and uploading the MD5 sum in advance is currently the only way to achieve this. (If S3 ever adds the ability to do this check afterward, all the better.)
This is Amazon's recommended approach for ensuring data integrity. It works transparently for multi-part upload, and Amazon's CLI does this by default.
I like this idea as an optimization. I also think it would be fun to write an S3 crawler to upgrade v1 files to v2! 🕸️
Functionally, though, it does not address 3 above. I think we need at least one anchor sum that is verified by S3 and and serves to "certify" the other sums in the v2 blob. Otherwise, we can't be sure that the uploaded sums actually match the contents of the uploaded file. For this reason, I still support calculating the sum in advance.
The unfortunate thing here--touched upon on #1767 --is that the APIs want the sum before the upload instead of after. I don't see this as a reason to not implement the "calculate the sum in advance" functionality; if the APIs improve later, rclone can improve its "calculate the sum in advance" impl right along with them. 😄
What do you think? I prefer this solution as an alternative to #1863, and would be happy to switch over to this work.
ncw commentedon Nov 30, 2017
I agree by and large with your points above. I'll just call out some things
Remember rclone supports remote -> remote transfers so it will involve a double transfer from the source.
I've looked at the docs and Content-MD5 doesn't seem to be supported for multipart uploads. It is supported for each chunk and the AWS Go SDK does that for me already.
Yes that is mostly why I haven't done it....
I think that it won't work with multipart files unfortunately :-( Here are the docs for initiate, upload a part and finalise - I'd appreciate a double check on that.
Rclone goes to some effort to check hash integrity. After uploading something, rclone will immediately check the hash is correct (ie check the Etag returned by S3 matches that caculated locally) and delete the file if it isn't which has the same eventual result as sending it in the Content-MD5 header I think.
That scheme would work well with #1863 and I think it covers your requirements of having an object whose hash has been checked at the point of upload.
I think we would have to hide it behind a feature flag --s3-etag or something like that so we don't break backwards compatibility with other workflows.
Although we could always use this mechanism for uploads - it is just downloads that are potentially problematic.
In fact looking at the s3manager code it has all the info there (namely MD5SUMs) of all the parts so it would be really easy for it to check the etag returned there...
4 remaining items
chris-redekop commentedon Dec 3, 2017
Ah, good idea re: submitting a PR to aws-go-sdk. I'll take a closer look and see how that might work.
Re: trackng moves, yes, I see what you mean. By making hashes available sooner, crypt remotes look more like unencrypted remotes.
ncw commentedon Dec 4, 2017
I did a little test with rclone uploading an 11M file.
s3-no-nulls.log
If you look at that log you can see
X-Amz-Content-Sha256so each chunk is protectedSo I think s3manager and S3 are ensuring the integrity of large file uploads quite well.
chris-redekop commentedon Dec 6, 2017
Yes, I see what you mean! Thanks for finding this.
So Content-MD5 aside, the SDK is always SHA-256 hashing its chunked payload. This addresses a big part of (the motivation behind) my use case; all that remains is, "as a backup operator, I want to (crypt) check the large files that rclone copied to S3 some time in the past"
I do want to address this use case, but now that (I realize that) my rcloned files have been verified 😅 I'm not in as big of a hurry. Given the new SHA-256 information, are you still interested in adding either MD5 or ETag support to S3 large files? In the meantime, I'm going to keep studying the ETag before I propose one or the other.
chris-redekop commentedon Dec 8, 2017
Given what I found below, @ncw, I think calculating and specifying the MD5 ahead of the download is the best approach. (I think the ETag is too fragile.) What do you think?
ncw commentedon Dec 12, 2017
I think that is probably the best approach and matches the approach taken by b2. I agree with you that the ETag is probably too fragile. I think the major pointer is that direction is that it isn't documented by AWS, so they can change it whenever they like...
I didn't know about Etag of large object copies. Note that rclone does a server side copy when updating the modtime of a file so it is more common that you might think.
chris-redekop commentedon Dec 13, 2017
Sounds good. I'll close #1863, then, and prep my original branch for a PR.
ncw commentedon Dec 14, 2017
That would be great :-)
I note in your branch you use
metaMD5Hash = "Md5hash"- I'd like to follow some standard here if there is one! Any thoughts?chris-redekop commentedon Dec 18, 2017
Leaving a note here: in it's CLI/S3 FAQ, AWS lists Signature Version 4's
x-amz-content-sha256as a preferred alternative toContent-MD5when uploading files to S3.s3: set/get the hash for multipart files - #523
ncw commentedon Sep 3, 2023
We now
I think this is sufficient to close this issue.
s3: set/get the hash for multipart files - rclone#523