s3cmd icon indicating copy to clipboard operation
s3cmd copied to clipboard

SignatureDoesNotMatch on files with spaces while trying to sync

Open Mehlstaub opened this issue 9 years ago • 10 comments

I am trying to sync some files from a local ubuntu 16.04 machine to a s3 bucket. Whenever it tries to upload a file wich has spaces in the filename, the process breaks with 403 signaturedoesnotmatch.

Files without spaces in it work just fine.

s3cmd sync --no-check-md5 --delete-removed -r -v /opt/rvcms/data/wcm/ s3://content/ INFO: Compiling list of local files... INFO: Running stat() and reading/calculating MD5 values on 25241 files, this may take some time... INFO: [1000/25241] INFO: [2000/25241] INFO: [3000/25241] INFO: [4000/25241] INFO: [5000/25241] INFO: [6000/25241] INFO: [7000/25241] INFO: [8000/25241] INFO: [9000/25241] INFO: [10000/25241] INFO: [11000/25241] INFO: [12000/25241] INFO: [13000/25241] INFO: [14000/25241] INFO: [15000/25241] INFO: [16000/25241] INFO: [17000/25241] INFO: [18000/25241] INFO: [19000/25241] INFO: [20000/25241] INFO: [21000/25241] INFO: [22000/25241] INFO: [23000/25241] INFO: [24000/25241] INFO: [25000/25241] INFO: Retrieving list of remote files for s3://content/ ... INFO: Found 25241 local files, 1 remote files INFO: Verifying attributes... INFO: Summary: 25241 local files to upload, 0 files to remote copy, 1 remote files to delete delete: 's3://content/wcm/mediadata/0000.txt' upload: '/opt/rvcms/data/wcm/mediadata/0000.txt' -> 's3://content/mediadata/0000.txt' [1 of 25241] 5 of 5 100% in 0s 68.00 B/s done upload: '/opt/rvcms/data/wcm/mediadata/01 1_new.pdf' -> 's3://content/mediadata/01 1_new.pdf' [2 of 25241] 329315 of 329315 100% in 0s 2.91 MB/s done ERROR: S3 error: 403 (SignatureDoesNotMatch): The request signature we calculated does not match the signature you provided. Check your AWS Secret Access Key and signing method. For more information, see REST Authentication and SOAP Authentication for details.

Mehlstaub avatar Feb 01 '17 07:02 Mehlstaub

I have the same issue with spaces. I have determined that the issue started as of commit 267a312e0c85109cfa626a8d323ccdbfe3830db5.

root@3fe290adab8e:/s3cmd# git checkout 267a312e0c85109cfa626a8d323ccdbfe3830db5
Previous HEAD position was 2f994be... Remove legacy code. s3cmd is now only compatible py >2.6
HEAD is now at 267a312... Py3 support: Reworked request/signature regarding unicode/bytes mix.
root@3fe290adab8e:/s3cmd# s3cmd ls "s3://_bucket_-photos/Misc 2/photo.JPG"
ERROR: S3 error: 403 (SignatureDoesNotMatch): The request signature we calculated does not match the signature you provided. Check your key and signing method.

roll back one commit:

root@3fe290adab8e:/s3cmd# git checkout 2f994be2878c8b0aa1263cfd2830d390333d9925
Previous HEAD position was 267a312... Py3 support: Reworked request/signature regarding unicode/bytes mix.
HEAD is now at 2f994be... Remove legacy code. s3cmd is now only compatible py >2.6
root@3fe290adab8e:/s3cmd# s3cmd ls "s3://_bucket_-photos/Misc 2/photo.JPG"
2014-08-18 04:32    151991   s3://_bucket_-photos/Misc 2/photo.JPG

Probably irrelevant, but after seeing this issue, I generated a new access key and secret key as my old secret key had non-alphanumerics in it and I'd seen some comments about that not working in some circumstances.

The difference seems to be that the working request (2f994be2878c8b0aa1263cfd2830d390333d9925) submits the URI: /?prefix=Misc+2/photo.JPG&delimiter=/ and the non-working request (267a312e0c85109cfa626a8d323ccdbfe3830db5) submits the URI: /?prefix=Misc%202/photo.JPG&delimiter=/.

kawaja avatar Apr 23 '17 06:04 kawaja

I did change the "encoding" mode, but it is supposed to work this is style recent code so there could be a bug.

3 questions:

  • Are you targeting Amazon S3 or a compatible service?
  • Do you have the same issue with your newly issued key
  • Please run the non working s3cmd with the "-d" flag, you should see more debug info. With the signature does not match error, you should see a report from the server of what it was expecting and what it did receive. With that we should be able to identify the exact issue.

fviard avatar Apr 23 '17 12:04 fviard

  1. It's AWS S3 proper
  2. Yes I had the same issue with both sets of keys. I only included the info about keys because I wanted to rule out the potential issue of non-alphanumerics.
  3. I will, but it might take me a day or so as I'll need to set up a test bucket (rather not post debug traces of access to my production buckets).

kawaja avatar Apr 23 '17 13:04 kawaja

I am willing to bet this is the same issue as #846 opened on Mar 19 2017.

My last master before the encoding mode change is in Nov 28, 2016. Is there a way for a dumb admin like me to only remove the encoding mode patch for testing?

dsbcpas avatar Apr 27 '17 22:04 dsbcpas

@dsbcpas Could it be possible for you to try to reproduce the issue with the -d flag so we have some debug information? At the end of the debug, there should be all the info that is needed to figure out the root cause of this issue. There is the what was expected to be signed by Amazon compared to what we have sent. With that, it could be possible to understand and fix the bug. There shouldn't be too much sensitive informations here, but you can also send them to me by email if you prefer.

fviard avatar Apr 27 '17 23:04 fviard

@kawaja @dsbcpas thank you for your elements, in fact in think that I have spotted the issue, maybe the special characters (" " et ":") that are in the prefix.

fviard avatar Apr 28 '17 00:04 fviard

@kawaja @dsbcpas I have just pushed a change in MASTER that should fix your issues. Can you give it a try?

fviard avatar May 04 '17 00:05 fviard

Hi Fviard, 1st pass test results - Appears to have solved our "SignatureDoesNotMatch" problem!

Thank you. And thanks to @kawaja for spotting the special characters (including his spaces) in the debug output.

I will test it more extensively tonight with live data.

Though I am just a dumb sys admin, how might I "give back" and "pay forward" to the project?

dsbcpas avatar May 04 '17 13:05 dsbcpas

@kawaja Patch confirmed to work for my application use. Okay to close issue if it also resolved your problem. Again, thank you.

dsbcpas avatar May 05 '17 17:05 dsbcpas

Sorry for the delay, @fviard (had troubles with my test system). Current HEAD (596bbe83a7d31bb4a762f18bbee4f8561bae813e) works. Thanks!

kawaja avatar May 13 '17 03:05 kawaja