lyft / metadataproxy

A proxy for AWS's metadata service that gives out scoped IAM credentials from STS
Other
458 stars 69 forks source link

Auto-set the docker client version #26

Closed sharganMedallia closed 7 years ago

sharganMedallia commented 8 years ago

As currently written, using an older docker version on the server side of the socket raise an exception:

Traceback (most recent call last):
  File "/usr/lib/python2.7/site-packages/gunicorn/workers/async.py", line 52, in handle
    self.handle_request(listener_name, req, client, addr)
  File "/usr/lib/python2.7/site-packages/gunicorn/workers/ggevent.py", line 159, in handle_request
    super(GeventWorker, self).handle_request(*args)
  File "/usr/lib/python2.7/site-packages/gunicorn/workers/async.py", line 105, in handle_request
    respiter = self.wsgi(environ, resp.start_response)
  File "/usr/lib/python2.7/site-packages/flask/app.py", line 1836, in __call__
    return self.wsgi_app(environ, start_response)
  File "/usr/lib/python2.7/site-packages/flask/app.py", line 1820, in wsgi_app
    response = self.make_response(self.handle_exception(e))
  File "/usr/lib/python2.7/site-packages/flask/app.py", line 1403, in handle_exception
    reraise(exc_type, exc_value, tb)
  File "/usr/lib/python2.7/site-packages/flask/app.py", line 1817, in wsgi_app
    response = self.full_dispatch_request()
  File "/usr/lib/python2.7/site-packages/flask/app.py", line 1477, in full_dispatch_request
    rv = self.handle_user_exception(e)
  File "/usr/lib/python2.7/site-packages/flask/app.py", line 1381, in handle_user_exception
    reraise(exc_type, exc_value, tb)
  File "/usr/lib/python2.7/site-packages/flask/app.py", line 1475, in full_dispatch_request
    rv = self.dispatch_request()
  File "/usr/lib/python2.7/site-packages/flask/app.py", line 1461, in dispatch_request
    return self.view_functions[rule.endpoint](**req.view_args)
  File "/usr/lib/python2.7/site-packages/metadataproxy/routes/proxy.py", line 44, in iam_role_name
    role_name_from_ip = roles.get_role_name_from_ip(request.remote_addr)
  File "/usr/lib/python2.7/site-packages/metadataproxy/roles.py", line 57, in timed
    result = method(*args, **kw)
  File "/usr/lib/python2.7/site-packages/metadataproxy/roles.py", line 160, in get_role_name_from_ip
    container = find_container(ip)
  File "/usr/lib/python2.7/site-packages/metadataproxy/roles.py", line 57, in timed
    result = method(*args, **kw)
  File "/usr/lib/python2.7/site-packages/metadataproxy/roles.py", line 114, in find_container
    _ids = [c['Id'] for c in client.containers()]
  File "/usr/lib/python2.7/site-packages/docker/api/container.py", line 70, in containers
    res = self._result(self._get(u, params=params), True)
  File "/usr/lib/python2.7/site-packages/docker/client.py", line 178, in _result
    self._raise_for_status(response)
  File "/usr/lib/python2.7/site-packages/docker/client.py", line 174, in _raise_for_status
    raise errors.APIError(e, response, explanation=explanation)
APIError: 400 Client Error: Bad Request ("client is newer than server (client API version: 1.22, server API version: 1.21)")

This easily fixed by allowing docker.Client to autodetect its version (while still permitting runtime override via the DOCKER_VERSION environment variable). Requests that require an unsupported version are still gated by docker-py's docker.utils.minimum_version decorator.

ryan-lane commented 8 years ago

This is great! Thanks for the PR. Before we can accept this, we need you to sign our CLA:

https://oss.lyft.com/cla

Let me know when you've signed and I can merge this in.

ryan-lane commented 8 years ago

@sharganMedallia did you get a chance to look at the CLA?

sharganMedallia commented 8 years ago

Sorry for the delayed response. I'm working with my company's legal team now to ensure that everything's in order and it's taking a little longer than I'd hoped. Will keep you posted!

ryan-lane commented 8 years ago

Awesome. Thanks for the update. No rush :)

ryan-lane commented 7 years ago

Any update @sharganMedallia?

ryan-lane commented 7 years ago

For now we're going to close this PR out, @sharganMedallia, but we can open it back up at any point if you sign the CLA.