Skip to content

Objects with "=" in name cause 403 error on some providers. #1224

Closed

Description

@gboggs

What platform/OS are you using?

x86_64 Linux SLES12.3 Linux/4.4.114-94.11-default

Which version of the SDK?

aws-sdk-cpp/1.7.29

What compiler are you using? what version?

gcc version 4.8.5 (SUSE Linux)

What are your CMake arguments?

-DBUILD_ONLY="core;s3" -DCMAKE_BUILD_TYPE=RelWithDebInfo

Can you provide a TRACE level log? (sanitize any sensitive information)

Yes, if needed.

We have an application that needs to work with various S3 providers and are encountering a problem with the C++ SDK when trying to GET objects that have "=" in their names (and other special chars as well, but "=" is the one we're worried about). Apparently, some applications like Spark generate objects with such names so simply renaming the objects is not a good solution for us.

The problem is that GetObject() will fail with a 403/SignatureDoesNotMatch on some S3 providers but work on others when trying to retrieve these objects. For a simple test case, create a bucket named "foo" and upload an object named "foo=foo", then try to GET it with GetObjectRequest().

This will work just fine on real Amazon S3 and Minio, but will fail with a 403/SignatureDoesNotMatch error on Ceph, Google and Dell ECS.

s3cmd will retrieve the objects on all of these platforms. Looking at TCP dump output, it appears that the SDK does not escape the "=" in the path whereas s3cmd does.

SDK: GET /foo=foo HTTP/1.1
s3cmd: GET /foo%3Dfoo HTTP/1.1

So, what goes over the wire is not escaped, yet the string used for the signature is. The Canonical Request String is:
[DEBUG] 2019-08-23 21:41:28 AWSAuthV4Signer [139824467363648] Canonical Request String: GET
/foo%3Dfoo

But, what gets to Curl is this:
[TRACE] 2019-08-23 21:41:28 CurlHttpClient [139824467363648] Making request to https://xxxx-foo-1.ceph-s3.xxxxxxxxx.com/foo=foo

This apparently bothers some S3 implementations and not others. I've tried various things to get around this including pre-escaping the object key before passing it to the GetObjectRequest and changing the urlEscapePath parameter to true where S3Client::S3Client() calls the AWSAuthV4Signer constructor. These things end up with the "=" being double escaped (i.e. %253D when we only wanted %3D) and it still fails.

I've found one thing that DOES work. I'm not suggesting that this is the fix, but it does seem to give the desired behavior, at least for this test case. In URI::GetURIString(), m_path is escaped using URLEncodePathRFC3986() which explicitly checks for and does not percent encode the "=". If this call is replaced with a similar one that does escape the "=" (and only done here. URLEncodePathRFC3986() is called in a few places), the resulting URL becomes this:

[TRACE] 2019-08-23 22:29:33 CurlHttpClient [139976436225856] Making request to https://xxxx-foo-1.ceph-s3.xxxxxxxxx.com/foo%3Dfoo

With the same Canonical request string:
[DEBUG] 2019-08-23 22:29:33 AWSAuthV4Signer [139976436225856] Canonical Request String: GET
/foo%3Dfoo

This works OK on all of the providers mentioned above. I'm hoping I've missed something obvious and there's a better solution.

Activity

  1. KaibaLopez commented on Aug 26, 2019

    @KaibaLopez
    Contributor

    Hi @gboggs, if I understand the issue here correctly, the problem is with special character compatibility between service providers.
    In our documentation on object key naming conventions we mention that while we do support "=" it may require special handling. I think this is such a case, specially considering it's on relation with 3rd party compatibility.
    That being said, I'm glad you found a workaround for your case, and please let me know if I misunderstood something here.

  2. added
    third-party
    on Aug 26, 2019
  3. gboggs commented on Aug 26, 2019

    @gboggs
    Author

    Yes, but the only special handling I've found that works is patching the SDK as described above. That's not very pleasant and I'm unsure what the side effects will be, even though this patch appears to work on real Amazon S3 and Minio in addition to the ones that were failing. Was there a specific reason for using URLEncodePathRFC3986() to escape m_path in URI::GetURIString() as opposed to some other function that would escape the special chars? I don't want to use the patch and find I've broken something else.

  4. KaibaLopez commented on Aug 26, 2019

    @KaibaLopez
    Contributor

    To be clear, this is not a bug so much as an implementation problem. The sdk is behaving as expected, so we would not be making a change.
    But, there is no reason why you couldn't minimize the scope of the change for your own case, you could, for example, create a custom client class, using the HttpClient parent class where you could have it behave pretty much the same way but handle the encoding in a way that fits your needs without modifying the core functions to avoid side effects. Or you could overload the method with an extra value to signify the special encoding, and call that instead.
    This is all customization though, not changes we'd make with the sdk.

    As far as why we are not escaping all special characters, I'm afraid the most I can tell is what's written in the comments :

    // The path section of the URL allow reserved characters to appear unescaped
    // RFC 3986 §2.2 Reserved characters
    // NOTE: this implementation does not accurately implement the RFC on purpose to accommodate for
    // discrepancies in the implementations of URL encoding between AWS services for legacy reasons.
    
  5. added
    guidance
    closing-soon
    on Aug 26, 2019
  6. pitrou commented on Nov 14, 2022

    @pitrou

    I know this has been closed in a long time, but for the record, the boto3 library seems to handle this situation fine.

    I'm also unsure how to subclass the core client classes to override this without reimplementing a lot of logic.
    Typically, one has to reimplement CurlHttpClient::MakeRequest simply to change the URI::GetURIString call (*) to something else (and, of course, do this for other HTTP client implementations as well). This is very fragile maintenance-wise, especially if wanting to remain compatible with multiple versions of the SDK at once.

    (*)

    Aws::String url = uri.GetURIString();

  7. SergeyRyabinin commented on Nov 14, 2022

    @SergeyRyabinin
    Contributor

    Hi @pitrou ,
    You are right it is a long issue, but we had one contribution since then to support this thing recently:

    if (s_compliantRfc3986Encoding)

    There is a global variable now that could be set to switch how segments in the query path are encoded.

    Best regards

  8. pitrou commented on Nov 15, 2022

    @pitrou

    @SergeyRyabinin This seems to have fixed the issue for us. Thank you very much!

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Metadata

Metadata

Assignees

No one assigned

    Labels

    closing-soonguidancethird-party

    Type

    No type

    Projects

    No projects

      Milestone

      No milestone

      Relationships

      None yet

      Development

      No branches or pull requests

      Issue actions