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

Specific endpoint (S3 OVH) make the boto3 client use the wrong endpoint_url #3258

Closed
mh4ckt3mh4ckt1c4s opened this issue May 5, 2022 · 5 comments
Assignees
Labels
bug This issue is a confirmed bug. response-requested Waiting on additional information or feedback. s3 third-party

Comments

@mh4ckt3mh4ckt1c4s
Copy link

Describe the bug

When using boto3.client to create a new s3 client, the endpoint_url specified is sometimes not used properly and partially replaced with an amazonaws URL. Any request then fails as the endpoint is not valid.

Expected Behavior

The URL specified in endpoint_url is successfully used as the endpoint URL at all times.

Current Behavior

The URL was modified by an URL ending with amazonaws.com, which is not the domain targeted. Here is the two commands used and the associated logs.

>>> cl = boto3.client(endpoint_url="https://s3.gra.cloud.ovh.net", aws_access_key_id="XXXX", aws_secret_access_key="XXXX", service_
name="s3")                                                                                                                                                                                 
>>> cl.list_buckets()                                                                                                                                                                      
Traceback (most recent call last):                                                                                                                                                         
  File "/tmp/venv/lib/python3.10/site-packages/urllib3/connection.py", line 174, in _new_conn                                                                                              
    conn = connection.create_connection(                                                                                                                                                   
  File "/tmp/venv/lib/python3.10/site-packages/urllib3/util/connection.py", line 72, in create_connection                                                                                  
    for res in socket.getaddrinfo(host, port, family, socket.SOCK_STREAM):                                                                                                                 
  File "/usr/lib/python3.10/socket.py", line 955, in getaddrinfo                                                                                                                           
    for res in _socket.getaddrinfo(host, port, family, type, proto, flags):                                                                                                                
socket.gaierror: [Errno -2] Name or service not known                                                                                                                                      
                                                                                                                                                                                           
During handling of the above exception, another exception occurred:                                                                                                                        
                                                                                                                                                                                           
Traceback (most recent call last):                                                                                                                                                         
  File "/tmp/venv/lib/python3.10/site-packages/botocore/httpsession.py", line 439, in send                                                                                                 
    urllib_response = conn.urlopen(                                                                                                                                                        
  File "/tmp/venv/lib/python3.10/site-packages/urllib3/connectionpool.py", line 785, in urlopen                                                                                            
    retries = retries.increment(                                                                                                                                                           
  File "/tmp/venv/lib/python3.10/site-packages/urllib3/util/retry.py", line 525, in increment                                                                                              
    raise six.reraise(type(error), error, _stacktrace)                                                                                                                                     
  File "/tmp/venv/lib/python3.10/site-packages/urllib3/packages/six.py", line 770, in reraise                                                                                              
    raise value                                                                                                                                                                            
  File "/tmp/venv/lib/python3.10/site-packages/urllib3/connectionpool.py", line 703, in urlopen                                                                                            
    httplib_response = self._make_request(                                                                                                                                                 
  File "/tmp/venv/lib/python3.10/site-packages/urllib3/connectionpool.py", line 386, in _make_request                                                                                      
    self._validate_conn(conn)                                                                                                                                                              
  File "/tmp/venv/lib/python3.10/site-packages/urllib3/connectionpool.py", line 1040, in _validate_conn                                                                                    
    conn.connect()                                                                                                                                                                         
  File "/tmp/venv/lib/python3.10/site-packages/urllib3/connection.py", line 358, in connect                                                                                                
    self.sock = conn = self._new_conn()                                                                                                                                                    
  File "/tmp/venv/lib/python3.10/site-packages/urllib3/connection.py", line 186, in _new_conn                                                                                              
    raise NewConnectionError(                                                                                                                                                              
urllib3.exceptions.NewConnectionError: <botocore.awsrequest.AWSHTTPSConnection object at 0x7fb479db1b40>: Failed to establish a new connection: [Errno -2] Name or service not known

During handling of the above exception, another exception occurred:

Traceback (most recent call last):
  File "<stdin>", line 1, in <module>
  File "/tmp/venv/lib/python3.10/site-packages/botocore/client.py", line 415, in _api_call
    return self._make_api_call(operation_name, kwargs)
  File "/tmp/venv/lib/python3.10/site-packages/botocore/client.py", line 731, in _make_api_call
    http, parsed_response = self._make_request(
  File "/tmp/venv/lib/python3.10/site-packages/botocore/client.py", line 751, in _make_request
    return self._endpoint.make_request(operation_model, request_dict)
  File "/tmp/venv/lib/python3.10/site-packages/botocore/endpoint.py", line 107, in make_request
    return self._send_request(request_dict, operation_model)
  File "/tmp/venv/lib/python3.10/site-packages/botocore/endpoint.py", line 183, in _send_request
    while self._needs_retry(attempts, operation_model, request_dict,
  File "/tmp/venv/lib/python3.10/site-packages/botocore/endpoint.py", line 305, in _needs_retry
    responses = self._event_emitter.emit(
  File "/tmp/venv/lib/python3.10/site-packages/botocore/hooks.py", line 358, in emit
    return self._emitter.emit(aliased_event_name, **kwargs)
  File "/tmp/venv/lib/python3.10/site-packages/botocore/hooks.py", line 229, in emit
    return self._emit(event_name, kwargs)
  File "/tmp/venv/lib/python3.10/site-packages/botocore/hooks.py", line 212, in _emit
    response = handler(**kwargs)
  File "/tmp/venv/lib/python3.10/site-packages/botocore/retryhandler.py", line 194, in __call__
    if self._checker(**checker_kwargs):
  File "/tmp/venv/lib/python3.10/site-packages/botocore/retryhandler.py", line 267, in __call__
    should_retry = self._should_retry(attempt_number, response,
  File "/tmp/venv/lib/python3.10/site-packages/botocore/retryhandler.py", line 294, in _should_retry
    return self._checker(attempt_number, response, caught_exception)
  File "/tmp/venv/lib/python3.10/site-packages/botocore/retryhandler.py", line 333, in __call__
    checker_response = checker(attempt_number, response,
  File "/tmp/venv/lib/python3.10/site-packages/botocore/retryhandler.py", line 233, in __call__
    return self._check_caught_exception(
  File "/tmp/venv/lib/python3.10/site-packages/botocore/retryhandler.py", line 376, in _check_caught_exception
    raise caught_exception
  File "/tmp/venv/lib/python3.10/site-packages/botocore/endpoint.py", line 249, in _do_get_response
    http_response = self._send(request)
  File "/tmp/venv/lib/python3.10/site-packages/botocore/endpoint.py", line 321, in _send
    return self.http_session.send(request)
  File "/tmp/venv/lib/python3.10/site-packages/botocore/httpsession.py", line 468, in send
    raise EndpointConnectionError(endpoint_url=request.url, error=e)
botocore.exceptions.EndpointConnectionError: Could not connect to the endpoint URL: "https://s3.GRA.amazonaws.com/"

Reproduction Steps

Just use these following lines :

>>> import boto3
>>> cl = boto3.client(endpoint_url="https://s3.gra.cloud.ovh.net", aws_access_key_id="XXXX", aws_secret_access_key="XXXX", service_
name="s3")                                                                                                                                                                                 
>>> cl.list_buckets() 

And you will see the error with the wrong endpoint URL.

Possible Solution

I think this have something to do with the "s3" part in the URL. Retrying with exactly the same commands but replacing "s3" by "s2" in the URl does not make boto3 use the wrong URL. I rummaged into this repo and the botocore one but without being able to find the code that is actually causing the issue.

Additional Information/Context

We came up with this bug when trying to use the s3 OVH API (https://www.ovhcloud.com/en/) for object storage within a CTFd instance (https://github.com/CTFd/CTFd)

SDK version used

boto3 1.22.7 with s3 v4

Environment details (OS name and version, etc.)

Archlinux with 5.17.2 kernel, but reproduced also in various other environments.

@mh4ckt3mh4ckt1c4s mh4ckt3mh4ckt1c4s added bug This issue is a confirmed bug. needs-triage This issue or PR still needs to be triaged. labels May 5, 2022
@mh4ckt3mh4ckt1c4s mh4ckt3mh4ckt1c4s changed the title Specific endpoint (S3 OVH) Specific endpoint (S3 OVH) make the boto3 client use the wrong url_endpoint May 5, 2022
@mh4ckt3mh4ckt1c4s mh4ckt3mh4ckt1c4s changed the title Specific endpoint (S3 OVH) make the boto3 client use the wrong url_endpoint Specific endpoint (S3 OVH) make the boto3 client use the wrong endpoint_url May 5, 2022
@tim-finnigan tim-finnigan self-assigned this May 6, 2022
@tim-finnigan
Copy link
Contributor

Hi @mh4ckt3mh4ckt1c4s thanks for reaching out. Are you sure that you have the correct endpoint configured? Based on this OVH documentation it looks like you might need https://storage.gra.cloud.ovh.net

@tim-finnigan tim-finnigan added s3 third-party response-requested Waiting on additional information or feedback. and removed needs-triage This issue or PR still needs to be triaged. labels May 6, 2022
@mh4ckt3mh4ckt1c4s
Copy link
Author

Hello @tim-finnigan, thanks for your answer. We tried both endpoints actually, with the same problem. The two endpoints end up at the same location, with storage being the legacy name maintained for legacy reasons I think. Here is up-to-date OVH documentation giving the name of the endpoint : https://www.ovhcloud.com/en/public-cloud/object-storage/#how-to

@tim-finnigan
Copy link
Contributor

Have you tried asking in the OVH forums? I would check that you have the correct region configured, and also rule out that any firewall settings aren't preventing the connection.

@mh4ckt3mh4ckt1c4s
Copy link
Author

Well, you were right, it was the missing region_name parameter that did the trick. The documentation I used wasn't making use of it but after more research on the topic I found that using it can indeed fix problems like this. This issue is now fixed.

I must say that the Could not connect to the endpoint URL: "https://s3.GRA.amazonaws.com/" error here was really troubling and made me think that there was an issue as the URL given in the error was not the one provided. It might be worth fixing if possible.

Anyway, thanks a lot for your help.

@github-actions
Copy link

github-actions bot commented May 6, 2022

⚠️COMMENT VISIBILITY WARNING⚠️

Comments on closed issues are hard for our team to see.
If you need more assistance, please either tag a team member or open a new issue that references this one.
If you wish to keep having a conversation with other community members under this issue feel free to do so.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
bug This issue is a confirmed bug. response-requested Waiting on additional information or feedback. s3 third-party
Projects
None yet
Development

No branches or pull requests

2 participants