Skip to content
This repository has been archived by the owner on Nov 5, 2019. It is now read-only.

Proxies should never be used when querying GCE metadata server #114

Closed
thobrla opened this issue Jan 13, 2015 · 1 comment · Fixed by #293
Closed

Proxies should never be used when querying GCE metadata server #114

thobrla opened this issue Jan 13, 2015 · 1 comment · Fixed by #293

Comments

@thobrla
Copy link
Contributor

thobrla commented Jan 13, 2015

Similar changes to https://codereview.appspot.com/187380044/ should be made.

@dhermes
Copy link
Contributor

dhermes commented Mar 25, 2015

I filed googleapis/google-cloud-python#757 to make sure we are also doing the right thing.

AFAICT we get around autodetected proxies (and urllib magic overhead) by directly using the httplib library:

from six.moves.http_client import HTTPConnection
import socket

host = '169.254.169.254'
uri_path = '/computeMetadata/v1/project/project-id'
headers = {'Metadata-Flavor': 'Google'}
connection = HTTPConnection(host, timeout=0.1)

RESPONSE_BODY = None
try:
    connection.request('GET', uri_path, headers=headers)
    response = connection.getresponse()
    if response.status == 200:
        RESPONSE_BODY =  response.read()
except socket.error:  # socket.timeout or socket.error(64, 'Host is down')
    pass
finally:
    connection.close()

dhermes added a commit to dhermes/oauth2client that referenced this issue Aug 28, 2015
This avoids the potential issue of urllib detecting a proxy
and changing the actual request underneath our code. The
basic httplib library does not have any proxy detection, so
this is not even possible there.

Fixes googleapis#114.
Sign up for free to subscribe to this conversation on GitHub. Already have an account? Sign in.
Labels
None yet
Projects
None yet
Development

Successfully merging a pull request may close this issue.

2 participants