Skip to content
This repository has been archived by the owner on Oct 31, 2019. It is now read-only.

Recode storage authentication requests to use English locale #55

Open
jwijffels opened this issue Apr 25, 2017 · 12 comments
Open

Recode storage authentication requests to use English locale #55

jwijffels opened this issue Apr 25, 2017 · 12 comments
Labels
Milestone

Comments

@jwijffels
Copy link

jwijffels commented Apr 25, 2017

I'm trying to use Azure Blob storage as follows but I'm getting an authentication error.:

Server failed to authenticate the request. 
Make sure the value of Authorization header is formed correctly including the signature

What am I doing wrong here?

sc <- createAzureContext(tenantID = "{TID}", clientID = "{CID}", authKey= "{KEY}")
sKey <- azureSAGetKey(sc, resourceGroup = "bnosac-training", storageAccount = "bnosacdata4training")
Fetching Storage Key..
azureListStorageContainers(sc, storageAccount = "bnosacdata4training", storageKey = sKey)
No encoding supplied: defaulting to UTF-8.
No encoding supplied: defaulting to UTF-8.
Error: azureListStorageContainers()
AuthenticationFailed
Server failed to authenticate the request. Make sure the value of Authorization header is formed correctly including the signature.
RequestId:89983872-0001-00a6-1ccb-bdbf26000000
Time:2017-04-25T13:51:32.9974238Z
Return code: 403
@jwijffels
Copy link
Author

jwijffels commented Apr 25, 2017

After a bit of debugging and getting the content of XML of the GET call, it says The Date header in the request is incorrect.

<!DOCTYPE html PUBLIC "-//W3C//DTD HTML 4.0 Transitional//EN" "http://www.w3.org/TR/REC-html40/loose.dtd">
<?xml version="1.0" encoding="utf-8"?><html><body><error><code>AuthenticationFailed</code><message>Server failed to authenticate the request. Make sure the value of Authorization header is formed correctly including the signature.
RequestId:b8c84964-0001-00c2-6fcd-bd0f86000000
Time:2017-04-25T14:09:27.9794599Z</message><authenticationerrordetail>The Date header in the request is incorrect.</authenticationerrordetail></error></body></html>

The header looks like this in R

Authorization 
"LEFT OUT FOR CONFIDENTIALITY" 
                                                              Content-Length 
                                                                         "0" 
                                                                x-ms-version 
                                                                "2015-04-05" 
                                                                   x-ms-date 
                                              "di, 25 apr 2017 14:09:59 GMT"

My locale settings (which are used in the call) are:

Sys.getlocale("LC_TIME")
[1] "Dutch_Netherlands.1252"

@Alanwe
Copy link
Member

Alanwe commented Apr 25, 2017

Hi,

We did have a few similar issues earlier in the year. Have you recently update the package?

Many thanks
Alan

@jwijffels
Copy link
Author

jwijffels commented Apr 25, 2017

I installed today with devtools::install_github("Microsoft/AzureSMR").
What is the solution to this error?

@Alanwe
Copy link
Member

Alanwe commented Apr 25, 2017

Originally there was no need to get the Key as it would get the key during the function automatically.
e.g-

sc <- createAzureContext(tenantID = "{TID}", clientID = "{CID}", authKey= "{KEY}")
azureListStorageContainers(sc, storageAccount = "bnosacdata4training")

There was some work to change this so a key could be provided. That way the user wouldn't need admin access. (which you need to get the key).

Do any of the other blob functions work or is this just azureListStorageContainers()?

@jwijffels
Copy link
Author

jwijffels commented Apr 25, 2017

The proposed solution does not work. This is what I get.

> azureListStorageContainers(sc, storageAccount = "bnosacdata4training")
Error in azureListStorageContainers(sc, storageAccount = "bnosacdata4training") : 
  Error: No resourceGroup provided: Use resourceGroup argument or set in AzureContext
> azureListStorageContainers(sc, resourceGroup = "bnosac-training", storageAccount = "bnosacdata4training")
Fetching Storage Key..
No encoding supplied: defaulting to UTF-8.
No encoding supplied: defaulting to UTF-8.
Error: azureListStorageContainers()
AuthenticationFailed
Server failed to authenticate the request. Make sure the value of Authorization header is formed correctly including the signature.
RequestId:173a23ff-0001-00ec-21de-bd8f41000000
Time:2017-04-25T16:14:03.2643166Z
Return code: 403

@andrie
Copy link
Contributor

andrie commented Apr 25, 2017

That looks like a locale problem. The Azure storage REST API constructs "canonical headers" as follows (reference):

x-ms-date:Sat, 21 Feb 2015 00:48:38 GMT\nx-ms-version:2014-02-14\n

So, if you're using a different locale, this is a bug in the package - we should transcode the locale.

As a workaround, can you try using an English locale?

On my test machine I get:

> Sys.getlocale()
[1] "LC_COLLATE=English_United Kingdom.1252;LC_CTYPE=English_United Kingdom.1252;LC_MONETARY=English_United Kingdom.1252;LC_NUMERIC=C;LC_TIME=English_United Kingdom.1252"

@andrie andrie changed the title Server failed to authenticate the request. Make sure the value of Authorization header is formed correctly including the signature. Recode storage authentication requests to use English locale Apr 25, 2017
@andrie andrie added the bug label Apr 25, 2017
@jwijffels
Copy link
Author

@andrie Thanks for the feedback.
Changing the locale did the trick. The following worked for me.

Sys.setlocale(category = "LC_TIME", locale = "English_United Kingdom.1252")
azureListStorageContainers(sc, resourceGroup = "bnosac-training", storageAccount = "bnosacdata4training")

@andrie
Copy link
Contributor

andrie commented Apr 26, 2017

@jwijffels Thanks for confirming. I have now marked this as a bug.

@andrie
Copy link
Contributor

andrie commented May 31, 2017

@jwijffels Can you please test again using the latest version (v0.2.4)?

I think this has now been fixed.

@andrie andrie self-assigned this May 31, 2017
@andrie andrie added this to the v0.2.4 milestone May 31, 2017
@jwijffels
Copy link
Author

jwijffels commented Jun 6, 2017

Looks fine for the error I reported about azureListStorageContainers
I'm trying out the next part - uploading blobs.

When I serialise as JSON and put the data as blob, this is working fine.

> l <- lm(Sepal.Width ~ Sepal.Length, data = iris)
> save(l, file = "test.RData")
> x <- jsonlite::serializeJSON(l)
> azurePutBlob(sc, storageAccount = "bnosacdata4training", container = "opendata", 
+              contents = x, blob = "HELLO")
blob HELLO saved: 17293 bytes written
[1] TRUE
> azureDeleteBlob(sc, storageAccount = "bnosacdata4training", container = "opendata", blob = "HELLO")
Blob delete request accepted
[1] TRUE

When I use the file argument, I get a similar authentication signature error. I don't know if this is the type of error, or if I'm using the function incorrectly.

> azurePutBlob(sc, storageAccount = "bnosacdata4training", container = "opendata", 
+              file = file.path(getwd(), "test.RData"), blob = "HELLO")
No encoding supplied: defaulting to UTF-8.
No encoding supplied: defaulting to UTF-8.
Error: azurePutBlob()
AuthenticationFailed
Server failed to authenticate the request. Make sure the value of Authorization header is formed correctly including the signature.
RequestId:c0cf2754-0001-0034-4bf7-de2890000000 Time:2017-06-06T19:03:58.1503340Z
The MAC signature found in the HTTP request '6u27LKSnNfLe5mSaQ2pKq0YaHOt7WcPAzVwk5bpW2IU=' is not the same as any computed
signature. Server used following string to sign: 'PUT

text/plain; charset=UTF-8

x-ms-blob-type:Blockblob x-ms-date:Tue, 06 Jun 2017 19:05:34 GMT x-ms-version:2015-04-05 /bnosacdata4training/opendata/HELLO'.
Return code: 403

This also does not work as I was expecting it to work

> x <- iris
> azurePutBlob(sc, storageAccount = "bnosacdata4training", container = "opendata", 
+              contents = x, blob = "HELLO")
No encoding supplied: defaulting to UTF-8.
No encoding supplied: defaulting to UTF-8.
Error: azurePutBlob()
AuthenticationFailed
Server failed to authenticate the request. Make sure the value of Authorization header is formed correctly including the signature.
RequestId:b7f3bf41-0001-00d4-3afa-dece18000000 Time:2017-06-06T19:27:09.4361225Z
The MAC signature found in the HTTP request 'JOFm8CP/U38FR1sY9wB8UzlIKK+HYrUS9SGqkaxNgk4=' is not the same as any computed
signature. Server used following string to sign: 'PUT

562

text/plain; charset=UTF-8; boundary=------------------------651f1103ec6bf4be

x-ms-blob-type:Blockblob x-ms-date:Tue, 06 Jun 2017 19:28:45 GMT x-ms-version:2015-04-05 /bnosacdata4training/opendata/HELLO'.
Return code: 403
In addition: Warning messages:
1: In charToRaw(object) :
  argument should be a character vector of length 1
all but the first element will be ignored
2: In charToRaw(enc2utf8(val)) :
  argument should be a character vector of length 1
all but the first element will be ignored
3: In charToRaw(enc2utf8(val)) :
  argument should be a character vector of length 1
all but the first element will be ignored
4: In charToRaw(enc2utf8(val)) :
  argument should be a character vector of length 1
all but the first element will be ignored
5: In charToRaw(enc2utf8(val)) :
  argument should be a character vector of length 1
all but the first element will be ignored
6: In charToRaw(enc2utf8(val)) :
  argument should be a character vector of length 1
all but the first element will be ignored

@maelle
Copy link

maelle commented Jan 27, 2018

I get the same error as in the previous comment.

@maelle
Copy link

maelle commented Jan 27, 2018

My workaround for an image file was simply to send it raw via the contents argument: magick::image_read(file) %>% magick::image_write()

Sign up for free to subscribe to this conversation on GitHub. Already have an account? Sign in.
Labels
Projects
None yet
Development

No branches or pull requests

4 participants