Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Pre-signed URL using Aws\Signature\SignatureV4 and temp Cognito credentials fails with 403 #2247

Open
CoDanny opened this issue May 16, 2021 · 4 comments
Assignees
Labels
bug This issue is a bug. p2 This is a standard priority issue

Comments

@CoDanny
Copy link

CoDanny commented May 16, 2021

Confirm by changing [ ] to [x] below to ensure that it's a bug:

Describe the bug
When using the class Aws\Signature\SignatureV4 to pre-sign an IoT Core websocket connection or GET shadow request, the request fails with 403 (The request signature we calculated does not match the signature you provided. Check your AWS Secret Access Key and signing method. Consult the service documentation for details.).

This only happens when using Cognito Identity temporary credentials. Permanent IAM credentials work.

This is due to the following lines

if ($token = $credentials->getSecurityToken()) {
$parsedRequest['headers']['X-Amz-Security-Token'] = [$token];
}
which are trying to add the security token header to the pre-signed request. The server seems to want this header added at the end of the pre-sign process. It shouldn't be part of the signature.

Version of AWS SDK for PHP?
Example: v3.178.11

  • get SDK version by printing the output of Aws\Sdk::VERSION in your code
  • if the SDK was installed via composer you can see the version installed with composer show -i

Version of PHP (php -v)?
php 5.6

To Reproduce (observed behavior)
Obtain STS Credentials from a Cognito Identity and use them to generate a websocket connection URL for IoT Core. I have also tried by making a https GET shadow request. Then use that url in javascript with mqtt.js to connect to IoT Core.

Expected behavior
The connection succeeds

@CoDanny CoDanny added bug This issue is a bug. needs-triage This issue or PR still needs to be triaged. labels May 16, 2021
@CoDanny CoDanny changed the title Pre-sign URL using Aws\Signature\SignatureV4 and temp Cognito credentials fails with 403 Pre-signed URL using Aws\Signature\SignatureV4 and temp Cognito credentials fails with 403 May 16, 2021
@ajredniwja ajredniwja self-assigned this Jul 8, 2021
@ajredniwja
Copy link
Member

Hi @CoDanny, sorry for delayed response, is this still a persisting issue? I can see here that the security-token header is marked optional so Im not sure if thats what is causing this. I'll discuss it with the team for some more insight.

@CoDanny
Copy link
Author

CoDanny commented Apr 12, 2022

@ajredniwja looking in the code for the SignatureV4 class in the latest released version, it appears that the problem is still there. I ended up re-implementing the class in my code to fix this issue.

@stobrien89
Copy link
Member

Hi @CoDanny,

Apologies for the delayed response here. In order to determine whether or not this is a bug, I'd need to see how you're generating the presigned url.

Presigned urls are only officially supported by a few services, so in this case it might be better than you've reimplemented the class— it's possible you're trying to do something that the SDK doesn't officially support.

@stobrien89 stobrien89 added response-requested Waiting on additional info and feedback. Will move to "closing-soon" in 7 days. and removed needs-triage This issue or PR still needs to be triaged. labels Mar 22, 2023
@CoDanny
Copy link
Author

CoDanny commented Mar 22, 2023

Here's my code snippet:

$credentials = new Credentials($idCredentials->accessKey, $idCredentials->secretKey, $idCredentials->sessionToken, $idCredentials->expiration);
$request = new Request("GET", "wss://". $iotConfig->iotEndpoint ."/mqtt");
$signer = new SignatureV4ForIotCore('iotdevicegateway', $this->config->aws->region);
$signed = $signer->presign($request, $credentials, "+5 seconds");

I then return the signed url

'connection_url' => (string) $signed->getUri()

SignatureV4ForIotCore is a class that extends from SignatureV4 with my fixes.

@github-actions github-actions bot removed the response-requested Waiting on additional info and feedback. Will move to "closing-soon" in 7 days. label Mar 23, 2023
@yenfryherrerafeliz yenfryherrerafeliz added the p2 This is a standard priority issue label Mar 30, 2023
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
bug This issue is a bug. p2 This is a standard priority issue
Projects
None yet
Development

No branches or pull requests

4 participants