Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Only one auth mechanism allowed; only the X-Amz-Algorithm query parameter..?

I am trying to send a PUT request to an amazonS3 presigned URL. My request seems to be called twice even if I only have one PUT request. The first request returns 200 OK, the second one returns 400 Bad Request.

Here is my code:

var req = {
    method: 'PUT',
    url: presignedUrl,
    headers: {
        'Content-Type': 'text/csv'
    },
    data: <some file in base64 format>
};

$http(req).success(function(result) {
    console.log('SUCCESS!');
}).error(function(error) {
    console.log('FAILED!', error);
});

The 400 Bad Request error in more detail:

<?xml version="1.0" encoding="UTF-8"?>
<Error>
   <Code>InvalidArgument</Code>
   <Message>Only one auth mechanism allowed; only the X-Amz-Algorithm query parameter, Signature query string parameter or the Authorization header should be specified</Message>
   <ArgumentName>Authorization</ArgumentName>
   <ArgumentValue>Bearer someToken</ArgumentValue>
   <RequestId>someRequestId</RequestId>
   <HostId>someHostId</HostId>
</Error>

What I don't understand is, why is it returning 400? and What's the workaround?

like image 925
chinco de mayo Avatar asked Jul 20 '15 10:07

chinco de mayo


4 Answers

Your client is probably sending an initial request that uses an Authorization header, which is being responded with a 302. The response includes a Location header which has a Signature parameter. The problem is that the headers from the initial request are being copied into the subsequent redirect request, such that it contains both Authorization and Signature. If you remove the Authorization from the subsequent request you should be good.

This happened to me, but in a Java / HttpClient environment. I can provide details of the solution in Java, but unfortunately not for AngularJS.

like image 182
mlohbihler Avatar answered Nov 14 '22 10:11

mlohbihler


For the Googlers, if you're sending a signed (signature v4) S3 request via Cloudfront and "Restrict Bucket Access" is set to "Yes" in your Cloudfront Origin settings, Cloudfront will add the Authorization header to your request and you'll get this error. Since you've already signed your request, though, you should be able to turn this setting off and not sacrifice any security.

like image 23
yagni Avatar answered Nov 14 '22 09:11

yagni


I know this may be too late to answer, but like @mlohbihler said, the cause of this error for me was the Authorization header being sent by the http interceptor I had setup in Angular. Essentially, I had not properly filtered out the AWS S3 domain so as to avoid it automatically getting the JWT authorization header.

like image 4
ako977 Avatar answered Nov 14 '22 10:11

ako977


Also, the 400 "invalid argument" may surface as a result of wrong config/credentials for your S3::Presigner that is presigning the url to begin with. Once you get past the 400, you may encounter a 501 "not implemented" response like I did. Was able to solve it by specifying a Content-Length header (specified here as a required header). Hopefully that helps @arjuncc, it solved my postman issue when testing s3 image uploads with a presigned url.

like image 2
frostini Avatar answered Nov 14 '22 10:11

frostini