Skip to content

Fix Signature Does Not Match when mounting Amazon S3 external storage - #8195

Closed
ctjctj wants to merge 3 commits into
owncloud:masterfrom
ctjctj:fix_amazons3
Closed

ctjctj wants to merge 3 commits into
owncloud:masterfrom
ctjctj:fix_amazons3

Conversation

@ctjctj

@ctjctj ctjctj commented Apr 14, 2014

Copy link
Copy Markdown
Contributor

For some reason the aws-sdk-php package does not calculate the
signature correctly when accessing an object in a bucket with a name of ..

When we are at the top of a S3 bucket there is a need(?) to have a directory
name. Per standard Unix the name picked was '.' (dot or period). This
choice exercises the aws-sdk bug.

This fix is to add a field to the method to store the name to use instead of
'.' which at this point is hard coded to ''. We also add a private
function cleanKey() which will test for the '.' name and replace it with
the variable. Finally all calls to manipulate objects where the path is
not obviously not '.' are processed through cleanKey().

An example where we don't process through clean key would be

    'Key' => $path.'/',

For some reason the aws-sdk-php package does not caclulate the
signiture correctly when accessing an object in a bucket with a name of
'.'.

When we are at the top of a S3 bucket there is a need(?) to have a directory
name.  Per standard Unix the name picked was '.' (dot or period).  This
choice exercises the aws-sdk bug.

This fix is to add a field to the method to store the name to use instead of
'.' which at this point is hard coded to '<root>'.  We also add a private
function 'cleanKey()' which will test for the '.' name and replace it with
the variable.  Finally all calls to manipulate objects where the path is
not obviously not '.' are processed through cleanKey().

An example where we don't process through clean key would be
	'Key' => $path.'/',
@ghost

ghost commented Apr 14, 2014

Copy link
Copy Markdown

Thanks a lot for your contribution! Contributions to the core repo require a signed contributors agreement http://owncloud.org/about/contributor-agreement/ Alternatively you can add a comment here where you state that this contribution is MIT licensed. Some more details about out pull request workflow can be found here: http://owncloud.org/code-reviews-on-github/

@ctjctj

ctjctj commented Apr 14, 2014

Copy link
Copy Markdown
Contributor Author

This fix is contributed to owncloud under the MIT license agreement.

Comment thread apps/files_external/lib/amazons3.php Outdated

Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

@ctjctj ctjctj closed this Apr 15, 2014
@jbtbnl jbtbnl reopened this Apr 15, 2014
@ghost

ghost commented Apr 15, 2014

Copy link
Copy Markdown

Thanks a lot for your contribution! Contributions to the core repo require a signed contributors agreement http://owncloud.org/about/contributor-agreement/ Alternatively you can add a comment here where you state that this contribution is MIT licensed. Some more details about out pull request workflow can be found here: http://owncloud.org/code-reviews-on-github/

@VicDeo

VicDeo commented Apr 15, 2014

Copy link
Copy Markdown
Contributor

@owncloud-bot this is ok to test

@scrutinizer-notifier

Copy link
Copy Markdown

The inspection completed: 39 new issues, 37 updated code elements

@MorrisJobke

Copy link
Copy Markdown
Contributor

@PVince81 Do you know somebody who can test with Amazon S3? cc @DeepDiver1975

@GloryFish

Copy link
Copy Markdown

I encountered the signature match error described here when setting up a new install of ownCloud 6.0.2 stable. I applied the changes in this pull request and got a green S3 connection. I'm seeing correct results when browsing my files now.

@MorrisJobke

Copy link
Copy Markdown
Contributor

@GloryFish Thanks for testing.

@karlitschek Can we see this as a 👍 ?

@vgezer vgezer changed the title Fix Signiture Does Not Match when mounting Amazon S3 external storage Fix Signature Does Not Match when mounting Amazon S3 external storage Apr 16, 2014
@DeepDiver1975

Copy link
Copy Markdown
Contributor

@owncloud-bot retest this please

@ghost

ghost commented Apr 23, 2014

Copy link
Copy Markdown

@ctjctj

ctjctj commented Apr 25, 2014

Copy link
Copy Markdown
Contributor Author

#8325 is likely the same underlying error in the SDK. AWS-SDK-PHP is looking at the issue and I expect they will fix it. In the mean time the files_external/amazons3.php has a method that can be used for cleaning any request. I think we can change umlauts (and other such characters) to a UTF-8 encoding which is likely to fix the issue.

The problem with this fix is that if you upload an object with umlauts via the S3 interface (or other tool) and then access it via owncloud it is unlikely you will be able to make a round trip. I'll also check to see if umlauts are allowed in AWS S3 Object names.

@PVince81

Copy link
Copy Markdown
Contributor

@ser72 can you help testing this ? Thanks.

@ser72

ser72 commented Apr 28, 2014

Copy link
Copy Markdown

@PVince81 Sure -- what are the reproduction steps? What am I looking for? :)

@PVince81

Copy link
Copy Markdown
Contributor

@ctjctj can you provide some steps to reproduce the issue for @ser72 ?
Did you just create a bucket called "." ?

@ctjctj

ctjctj commented Apr 28, 2014

Copy link
Copy Markdown
Contributor Author

@PVince81 @ser72 To replicate the issue:

  • do a clean install of owncloud 6.0.2 or from the development branch.
  • Configure to allow the use of external storage.
  • Create an AWS S3 ID with the correct permissions and get the key and secret.
  • Create a new bucket. (I've not tested the code to create a bucket, this step might not be needed)
  • Verify the bucket, key and secret via some other method such as s3cmd.
  • Go the the admin page and attempt to add an amazons3 external storage with the bucket, key and secret just tested.

The indicator will go to red circle. At this point you can look at the logs and see the signature error.

Apply the PR. Restart the service. Go to admin page and the S3 storage should show green.

Complete testing by creating directories and files at the top level and lower levels.

@ctjctj

ctjctj commented Apr 28, 2014

Copy link
Copy Markdown
Contributor Author

I see from my commit comment and the comments here that there is a bit of confusion regarding the bug. This bug exists when an OBJECT with a name of . is created within a bucket. I've not tested to see if there are limits on the bucket name. Given that somebody choosing to name their bucket . would be strange and ugly my fix for that error would be "Don't do that."

@ser72

ser72 commented Apr 28, 2014

Copy link
Copy Markdown

I've done S3 storage on 6.0.2 and haven't seen the above issue. I've always gotten the green light and not a red light as you mention.? So I don't think I will be able to reproduce this issue.

@ctjctj

ctjctj commented Apr 28, 2014

Copy link
Copy Markdown
Contributor Author

@ser72 Can you try again? If you do not see the error then there is an underlying
difference in our systems. I have verified that the putObject fails
outside of owncloud so if it works for you then it is a OS issue that is
causing aws-sdk-php to fail. My test system is Ubuntu 14.04 with only
enough extras for owncloud to run.
On Apr 28, 2014 9:28 AM, "Steve Robinson" [email protected] wrote:

I've done S3 storage on 6.0.2 and haven't seen the above issue. I've
always gotten the green light and not a red light as you mention.? So I
don't think I will be able to reproduce this issue.

—
Reply to this email directly or view it on GitHubhttps://github.com//pull/8195#issuecomment-41557611
.

Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I'm not familiar with S3, so asking: is this string <root> a convention of the S3 API to tell that you want the root or is it just a name you're using as workaround because . doesn't always work ?

Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

@ctjctj please clarify

Copy link
Copy Markdown
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Vincent, at issue is a bug in the aws-sdk for s3 that does not handle
files with a name of '.' correctly. It also looks like they do not handle
characters that have things like umlaut's in them. This variable "$root"
is used to hold the name of the root directory. I.e. if the code
references the "." directory then we will change it to "".

The side affect of this fix is that it is no longer possible to have a file
name of "".

On Fri, Jun 20, 2014 at 3:55 AM, Vincent Petry [email protected]
wrote:

In apps/files_external/lib/amazons3.php:

@@ -53,6 +53,7 @@ class AmazonS3 extends \OC\Files\Storage\Common {
* @var int
*/
private $timeout = 15;

  • private $root = '';

@ctjctj https://github.com/ctjctj please clarify

—
Reply to this email directly or view it on GitHub
https://github.com/owncloud/core/pull/8195/files#r14009923.

@PVince81

Copy link
Copy Markdown
Contributor

@cdamken can you test this ? With a bit of luck it might also solve the issues you mentioned to me recently.

@butonic

butonic commented Jun 30, 2014

Copy link
Copy Markdown
Contributor

I tried this but still got:

{"reqId":"53b194e69bad5","app":"files_external","message":"Aws\\S3\\Exception\\NotImplementedException: A header you provided implies functionality that is not implemented","level":4,"time":"2014-06-30T16:48:38+00:00","method":"POST","url":"\/core\/index.php\/apps\/files_external\/ajax\/addMountPoint.php"}

I changed '<root>' to '/' in lib/amazons3.php:L53 and can now mount the storage and up / download files. The preview icon seems to be broken though ... will investigate further tomorrow.

@butonic

butonic commented Jul 1, 2014

Copy link
Copy Markdown
Contributor

@ctjctj I changed '<root>' to '/' and that seems to be working fine. Up and downloads work nicely with a bucket in Ireland. No Signature or NotImplemented errors. Can you try with '/' as root? after that it's a 👍 from me.

@butonic

butonic commented Jul 4, 2014

Copy link
Copy Markdown
Contributor

@cdamken

cdamken commented Jul 7, 2014

Copy link
Copy Markdown
Contributor

Well......

one image says more than words:

amazon

WORKS!!!!!!!

@PVince81 @butonic

@cdamken

cdamken commented Jul 7, 2014

Copy link
Copy Markdown
Contributor

@butonic works both ways: <root> or /

@MorrisJobke

Copy link
Copy Markdown
Contributor

@butonic Can you take care of the merge and backport?

@butonic

butonic commented Jul 8, 2014

Copy link
Copy Markdown
Contributor

@cdamken yeah, but with <root> you cant store a file named <root> in the root folder ;)

@DeepDiver1975

Copy link
Copy Markdown
Contributor

superseded by #9509

@lock lock Bot locked as resolved and limited conversation to collaborators Aug 20, 2019
Sign up for free to subscribe to this conversation on GitHub. Already have an account? Sign in.

Projects

None yet

Development

Successfully merging this pull request may close these issues.