Movatterモバイル変換


[0]ホーム

URL:


Skip to content

Navigation Menu

Sign in
Appearance settings

Search code, repositories, users, issues, pull requests...

Provide feedback

We read every piece of feedback, and take your input very seriously.

Saved searches

Use saved searches to filter your results more quickly

Sign up
Appearance settings

fix proxied requests forwarding to Moto#11653

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 ourterms of service andprivacy statement. We’ll occasionally send you account related emails.

Already on GitHub?Sign in to your account

Merged
bentsku merged 3 commits intomasterfromfix-moto-call-with-proxy
Oct 9, 2024

Conversation

@bentsku
Copy link
Contributor

@bentskubentsku commentedOct 7, 2024
edited
Loading

Motivation

As reported by#11652, we have an issue forwarding requests tomoto when those have a full URI in the HTTP request, as explained in#8962.
(Example HTTP request:POST http://sns.eu-central-1.amazonaws.com/ HTTP/1.1 instead of the usualPOST / HTTP/1.1)

This PR uses the helper created with the above PR to get the request path to send towards the moto dispatcher, so that we only get thepath part of the request. It only changes the logic to get the actual endpoint to call, as we were already using that helper to forward the request to moto. The logic change is very minimal.

Looking at it, I believe this is an issue in how Werkzeug handles those requests, putting the fullRAW_URI in thepath and not doing sanitization beforehand, as we've seen withhttps://www.ietf.org/rfc/rfc2616.txt that web servers should handle those.
Also, the question comes as to what changed in3.7.2, as this used to work with versions before, tested by the user down to3.4.

Changes

  • update the logic to properly sanitize the path used to get the proper endpoint for moto, to be sure it is only a path and not a full URI
  • add a regression test for it (I also confirmed the user sample now works with the fix)

fixes#11652

whummer, alexrashed, and Blind-Striker reacted with rocket emoji
@bentskubentsku added aws:snsAmazon Simple Notification Service area: asf semver: patchNon-breaking changes which can be included in patch releases labelsOct 7, 2024
@bentskubentsku self-assigned thisOct 7, 2024
@bentskubentsku marked this pull request as draftOctober 8, 2024 00:22
@github-actions
Copy link

github-actionsbot commentedOct 8, 2024
edited
Loading

LocalStack Community integration with Pro

    2 files  ±0      2 suites  ±0   1h 38m 50s ⏱️ - 4m 19s
3 488 tests +1  3 075 ✅ +1  413 💤 ±0  0 ❌ ±0 
3 490 runs  +1  3 075 ✅ +1  415 💤 ±0  0 ❌ ±0 

Results for commit21ed1a8. ± Comparison against base commit87104a6.

♻️ This comment has been updated with latest results.

@bentskubentsku marked this pull request as ready for reviewOctober 8, 2024 08:59
Copy link
Member

@alexrashedalexrashed left a comment

Choose a reason for hiding this comment

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

Wow! Great catch! This really is an interesting case! Thanks a lot for jumping on this and digging this deep!
I think we could move forward with this fix, but I think the problem here could actually be caused byrolo (sincerolo creates the request).
I think it would be worth it to try to:

  • See if this issue can really be reproduced with werkzeug and raise an issue in their repo is this really is the case.Their own code suggest that you are right and the path variable really shouldn't contain anything before the root path slash.
  • If it is not reproducible in plain werkzeug, I think this would actually be a subtle issue inrolo, and we should fix it there. /cc@thrau

What do you think?

bentsku reacted with thumbs up emoji
raw_path=get_full_raw_path(request)
# this is where we skip the HTTP roundtrip between the moto server and the boto client
dispatch=get_dispatcher(service.service_name,request.path)
dispatch=get_dispatcher(service.service_name,raw_path.split("?")[0])
Copy link
Member

Choose a reason for hiding this comment

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

nit: Would be great to add a comment line here explaining what's happening here and why.

Copy link
ContributorAuthor

Choose a reason for hiding this comment

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

Yep, agreed. The thing is, the "best" would be to callget_raw_path only to get the path to match the request, but it is called internally inget_full_raw_path and we'd be doing twice. I'll add a comment!

@bentsku
Copy link
ContributorAuthor

bentsku commentedOct 9, 2024
edited
Loading

@alexrashed sure! I'll try recreating against Werkzeug, I believe that during my first investigation I had already found that Werkzeug had the issue itself.

In Rolo, it creates the request by directly instantiatingwerkzeug.wrappers.request.Request on the passedenviron, so I don't think rolo is directly to blame here. (Inrolo.gateway.wsgi.WsgiGateway.__call__).
We could fix the issue inrolo, but for now I think we're just having the same behavior than Werkzeug by default.

I'll set up a reproducer for Werkzeug, but I think we should go forward with this fix for now! I'll add the comment

edit: working on the reproducer, I can't reproduce with either base Werkzeug or even base hello world rolo, printingrequest.path gives the right value when usingwerkzeug.run_simple. Will continue looking 🔍 might be related to WSGI and the web server in itself, most probably in our twisted bridge or twisted itself.

Blind-Striker reacted with heart emoji

@bentskubentskuforce-pushed thefix-moto-call-with-proxy branch froma9482e0 to21ed1a8CompareOctober 9, 2024 11:59
@bentsku
Copy link
ContributorAuthor

bentsku commentedOct 9, 2024
edited
Loading

@alexrashed the issue seems to be in Twisted, when getting the WSGIenviron when usingrolo, this is thePATH_INFO:'PATH_INFO': '/ttp://sns.eu-central-1.amazonaws.com/', which is why it's wrong down the line. I'll try investigating and fixing it, but I guess in the meantime, we should try to fix the issue itself to unblock users?

Small reproducer:

if__name__=='__main__':fromtwisted.webimportserver,resourcefromtwisted.internetimportreactorclassSimple(resource.Resource):isLeaf=Truedefrender_POST(self,request):print(f"{request.path=}")return"<html>Hello, world!</html>"site=server.Site(Simple())reactor.listenTCP(4566,site)

Using the reproducer given inhttps://github.com/Blind-Striker/localstack-sns-issue-sandbox, this prints:
request.path=b'http://sns.eu-central-1.amazonaws.com/', and I can see the environ is wrong.

Copy link
Member

@alexrashedalexrashed left a comment

Choose a reason for hiding this comment

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

Sure! We can definitely move forward with this fix to unblock users, and then carefully look at the issue in rolo and twisted! Thanks a lot for digging into this and addressing the comment! 🏅 💯

bentsku and Blind-Striker reacted with heart emoji
@bentskubentsku merged commit3ff3e2a intomasterOct 9, 2024
@bentskubentsku deleted the fix-moto-call-with-proxy branchOctober 9, 2024 14:27
@bentsku
Copy link
ContributorAuthor

@alexrashed here's the PR in Rolo:localstack/rolo#23
I could track this down to a bug in Twisted, as I wrote the test for rolo I know have a clear reproducer, so I'll open a bug report there when I have the time. We can then revert the change inmoto.py once we update the dependencies to use rolo, as we have a regression test for it.

alexrashed reacted with rocket emoji

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

Reviewers

@alexrashedalexrashedalexrashed approved these changes

@thrauthrauAwaiting requested review from thrau

Assignees

@bentskubentsku

Labels

area: asfaws:snsAmazon Simple Notification Servicesemver: patchNon-breaking changes which can be included in patch releases

Projects

None yet

Milestone

No milestone

Development

Successfully merging this pull request may close these issues.

bug: LocalStack.NET all SNS operations fails on LocalStack 3.7.2 and 3.8.0

3 participants

@bentsku@alexrashed

[8]ページ先頭

©2009-2025 Movatter.jp