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

Stop relying on SERVER_SOFTWARE being set #1704

Merged
merged 5 commits into from Oct 18, 2019
Merged
Changes from 3 commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Jump to
Jump to file
Failed to load files.
Diff view
Diff view
19 changes: 9 additions & 10 deletions src/urllib3/contrib/_appengine_environ.py
Expand Up @@ -6,27 +6,26 @@


def is_appengine():
return is_local_appengine() or is_prod_appengine() or is_prod_appengine_mvms()
return "APPENGINE_RUNTIME" in os.environ


def is_appengine_sandbox():
return is_appengine() and not is_prod_appengine_mvms()
"""Deprecated. Use is_appengine instead."""
Copy link
Member

Choose a reason for hiding this comment

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

This changes the foundational behavior of this method. It should detect if the app is running under the legacy 2.7 runtime in App Engine standard. Making it detect any app engine runtime is likely to cause user code to fail.

Copy link
Contributor Author

Choose a reason for hiding this comment

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

I guess I don't really know what the "foundational behavior" of this method is supposed to be. I couldn't find any documentation for this function, so I only had the old code to go on which I interpreted as "all appengine runtimes except managed VMs are sandboxed."

Given that managed VMs are decommissioned, it seemed that now the situation is that "all appengine runtimes are sandboxed." Am I missing something?

Copy link
Member

Choose a reason for hiding this comment

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

So "sandboxed" here is a bit weird. You'll have to kinda go back to when this was written - which was before gVisor.

When urllib3 first added rudimentary support for App Engine, there was App Engine (with no qualifier) in a heavily (ptrace) sandboxed environment and there was App Engine managed VMs which had a much less severe KVM sandbox. Urllib3 can run as usual in the KVM sandbox, but can't run as usual in the ptrace sandbox. So this function is used to determine "can I really use sockets and ssl the in a normal way?" which breaks down to this table these days:

Standard legacy 2.7: no
Standard 3.x: yes
Flexible 2.x or 3.x: yes

So this function should return True only in the legacy 2.7 runtime or when using the legacy 2.7 runtime with devappserver. User code uses this function to determine whether or not to use the AppEngineManager (and therefore urlfetch) instead of the normal PoolManager (and therefore sockets).

Copy link
Contributor Author

Choose a reason for hiding this comment

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

That makes sense. I've changed the function to return True for the python27 runtime and added some documentation to explain the behavior.

return is_appengine()


def is_local_appengine():
return (
"APPENGINE_RUNTIME" in os.environ
and "Development/" in os.environ["SERVER_SOFTWARE"]
return is_appengine() and os.environ.get("SERVER_SOFTWARE", "").startswith(
"Development/"
)


def is_prod_appengine():
return (
"APPENGINE_RUNTIME" in os.environ
and "Google App Engine/" in os.environ["SERVER_SOFTWARE"]
and not is_prod_appengine_mvms()
return is_appengine() and os.environ.get("SERVER_SOFTWARE", "").startswith(
"Google App Engine/"
)


def is_prod_appengine_mvms():
theacodes marked this conversation as resolved.
Show resolved Hide resolved
return os.environ.get("GAE_VM", False) == "true"
"""Deprecated."""
return False