Thanks to visit codestin.com
Credit goes to github.com

Skip to content

add rules for ASF S3 virtual host urls #6846

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

Merged
merged 2 commits into from
Sep 20, 2022
Merged

add rules for ASF S3 virtual host urls #6846

merged 2 commits into from
Sep 20, 2022

Conversation

steffyP
Copy link
Member

@steffyP steffyP commented Sep 9, 2022

Buckets can be addressed either in path-style s3.<region>.localhost.localstack.cloud:4566/mybucket or virtual host-style mybucket.<region>.localhost.localstack.cloud:4566.

Path style (without region) is covered by moto.

  • Added routes for vhost-style
  • Added more specific routes for buckets that contain dot(s) in the name -> this is a special case as it changes the domain
    • put requests for such buckets will currently not work
  • Added route to match path-style urls that contain a region
    • currently only strips the region, and re-sends the request

Note: AWS works a bit differently (also compared to the old provider): if bucket is created with a location constraint and the path-style contains another region, it would respond with 301 (for any region other than us-east-1), or 307 (for us-east-1). see test test_access_bucket_different_region

@steffyP steffyP temporarily deployed to localstack-ext-tests September 9, 2022 15:14 Inactive
@coveralls
Copy link

coveralls commented Sep 9, 2022

Coverage Status

Coverage decreased (-0.08%) to 80.508% when pulling 7c7cb91 on s3_virtual_host into 91b3227 on master.

@github-actions
Copy link

github-actions bot commented Sep 9, 2022

LocalStack integration with Pro

       3 files  ±0         3 suites  ±0   1h 12m 52s ⏱️ +50s
1 292 tests +5  1 181 ✔️ +3  111 💤 +2  0 ±0 
1 788 runs  +9  1 533 ✔️ +7  255 💤 +2  0 ±0 

Results for commit 7c7cb91. ± Comparison against base commit 91b3227.

♻️ This comment has been updated with latest results.

@steffyP steffyP temporarily deployed to localstack-ext-tests September 9, 2022 17:03 Inactive
@steffyP steffyP temporarily deployed to localstack-ext-tests September 12, 2022 17:41 Inactive
@steffyP steffyP temporarily deployed to localstack-ext-tests September 13, 2022 07:05 Inactive
@steffyP steffyP temporarily deployed to localstack-ext-tests September 16, 2022 10:19 Inactive
@steffyP steffyP temporarily deployed to localstack-ext-tests September 19, 2022 08:27 Inactive
@steffyP steffyP marked this pull request as ready for review September 19, 2022 10:38
@steffyP steffyP requested a review from thrau as a code owner September 19, 2022 10:38
Copy link
Member

@thrau thrau left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

looks good overall! just a couple of comments/questions before i approve the PR.

original_host = copied_headers["Host"]
copied_headers["Host"] = host
params = {"data": request.data, "headers": copied_headers}
response = requests.request(method=request.method, url=rewritten_url, **params)
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

just a question: as i understand we are forwarding the request to moto here, right? is moto doing a lot for us, or could we also implement the serving logic ourselves by accessing the moto backend directly?

Copy link
Member Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

it's doing a lot. this can actually be any api call from s3, as everything in s3 works just with query-parameters and headers.

Comment on lines 212 to 221
copied_headers = copy.deepcopy(request.headers)
# TODO is_internal_call_context
original_host = copied_headers["Host"]
copied_headers["Host"] = host
params = {"data": request.data, "headers": copied_headers}
response = requests.request(method=request.method, url=rewritten_url, **params)

response.request.headers["Host"] = original_host
response.request.url = request.url
ls_response = convert_response(response)
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

have you considered using the localstack.http.proxy module? it has a bunch of utilities that could simplify some of the code here. alternatively you could also use the HttpClient from localstack.http.client. in any case i would avoid importing convert_response from the apigateway provider.

Copy link
Member Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

will check, thanks :)

Comment on lines 271 to 275
code, headers, body = fn(self, bucket_name, *args, **kwargs)
bucket = self.backend.get_bucket(bucket_name)
headers["x-amz-bucket-region"] = bucket.region_name
headers["content-type"] = "application/xml"
return code, headers, body
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

maybe this is out of scope, but would it be better to remove this patch all together, and wrap the head_bucket operation? or is that not an option because the moto response is a problem for our parser?

Copy link
Member Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Talked to @bentsku about it: we probably change it in a future PR.

@steffyP steffyP temporarily deployed to localstack-ext-tests September 20, 2022 14:44 Inactive
@steffyP steffyP requested a review from thrau September 20, 2022 14:46
Copy link
Member

@thrau thrau left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

thanks for clarifying and implementing the suggestions :-)

@thrau thrau merged commit 64c4d0a into master Sep 20, 2022
@thrau thrau deleted the s3_virtual_host branch September 20, 2022 16:49
bentsku pushed a commit that referenced this pull request Sep 20, 2022
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

Successfully merging this pull request may close these issues.

3 participants