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

Error when trying to list objects from a public S3 bucket via the listObjectsV2() function. #2912

Closed
KingMSM opened this issue Apr 24, 2024 · 2 comments · Fixed by #2914
Closed
Assignees
Labels
bug This issue is a bug. needs-review p2 This is a standard priority issue

Comments

@KingMSM
Copy link

KingMSM commented Apr 24, 2024

Describe the bug

So I have a public bucket which can directly be access by a link (can see the data if I copy paste that link on the browser).

However, when I try access the bucket via aws-sdk-php (v3.305.1) library it gives me the error:

"The authorization header is malformed; a non-empty Access Key (AKID) must be provided in the credential."

This is the code I have written to access the objects of my public bucket:

  $s3Client = new S3Client([
     "version" => "latest"
     "region" => "us-east-1"
     "credentials" => false // since its a public bucket
  ]);
  
  $data = $s3Client->listObjectsV2([
     "bucket" => "my bucket name"
  ]);

As per the AWS Documentation it says this is how to access via anonymous clients using the code above.

As a matter of fact this happens with any of the S3 functions (getObject, putObject, deleteObject, etc) that I use when I put [credentials => false]

Expected Behavior

Expected behavior is to list the objects of the S3 bucket.

Current Behavior

The following exception is thrown:

Aws\S3\Exception\S3Exception: Error executing "ListObjectsV2" on "public_bucket_url"; AWS HTTP error: Client error: GET public_bucket_url resulted in a 400 Bad Request response:

AuthorizationHeaderMalformedThe authorization header (truncated...)
AuthorizationHeaderMalformed (client): The authorization header is malformed; a non-empty Access Key (AKID) must be provided in the credential. -
AuthorizationHeaderMalformedThe authorization header is malformed; a non-empty Access Key (AKID) must be provided in the credential.F3MPEAGWS7NYARRD3J5SLAxac8koK4F5lhwBV9aj/aBLBGtDcH2wWfOfYyRoqG3EWFhfne9I0Spk2OBz2ruYqY/YzMU=

Caused by
GuzzleHttp\Exception\ClientException: Client error: GET public_bucket_url resulted in a 400 Bad Request response:

AuthorizationHeaderMalformedThe authorization header (truncated...)

/var/www/html/vendor/guzzlehttp/guzzle/src/Exception/RequestException.php:113
/var/www/html/vendor/guzzlehttp/guzzle/src/Middleware.php:69
/var/www/html/vendor/guzzlehttp/promises/src/Promise.php:204
/var/www/html/vendor/guzzlehttp/promises/src/Promise.php:153
/var/www/html/vendor/guzzlehttp/promises/src/TaskQueue.php:48
/var/www/html/vendor/guzzlehttp/guzzle/src/Handler/CurlMultiHandler.php:159
/var/www/html/vendor/guzzlehttp/guzzle/src/Handler/CurlMultiHandler.php:184
/var/www/html/vendor/guzzlehttp/promises/src/Promise.php:248
/var/www/html/vendor/guzzlehttp/promises/src/Promise.php:224
/var/www/html/vendor/guzzlehttp/promises/src/Promise.php:269
/var/www/html/vendor/guzzlehttp/promises/src/Promise.php:226
/var/www/html/vendor/guzzlehttp/promises/src/Promise.php:269
/var/www/html/vendor/guzzlehttp/promises/src/Promise.php:226
/var/www/html/vendor/guzzlehttp/promises/src/Promise.php:62
/var/www/html/vendor/aws/aws-sdk-php/src/AwsClientTrait.php:58
/var/www/html/vendor/aws/aws-sdk-php/src/AwsClientTrait.php:86

Reproduction Steps

  • Create an S3 client.
  • Try to list the objects of a public bucket with all public access via the listObjectV2 function.
  $s3Client = new S3Client([
     "version" => "latest"
     "region" => "us-east-1"
     "credentials" => false // since its a public bucket
  ]);
  
  $data = $s3Client->listObjectsV2([
     "bucket" => "my bucket name"
  ]);

Possible Solution

No response

Additional Information/Context

No response

SDK version used

v3.305.1

Environment details (Version of PHP (php -v)? OS name and version, etc.)

PHP 8.1, Windows 10, Docker

@KingMSM KingMSM added bug This issue is a bug. needs-triage This issue or PR still needs to be triaged. labels Apr 24, 2024
@yenfryherrerafeliz yenfryherrerafeliz self-assigned this Apr 25, 2024
@yenfryherrerafeliz yenfryherrerafeliz added needs-review p2 This is a standard priority issue and removed needs-triage This issue or PR still needs to be triaged. labels Apr 29, 2024
Copy link

github-actions bot commented May 3, 2024

This issue is now closed. Comments on closed issues are hard for our team to see.
If you need more assistance, please open a new issue that references this one.

@stobrien89
Copy link
Member

Hi @KingMSM ,

Sorry to hear about the issues. It turns out our endpoint resolution was overriding these requests and forcing them to use SIgV4. The fix will be available in today's release.

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. needs-review p2 This is a standard priority issue
Projects
None yet
Development

Successfully merging a pull request may close this issue.

3 participants