lyft / metadataproxy

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

Add `split_envvar()` method to return key/val or key/None #90

Closed JamesAwesome closed 5 years ago

JamesAwesome commented 5 years ago

In roles.py there are several places where a string representing an envvar (formatted as key=val) is split like so:

key, val = e.split('=', 1)

It's possible however that these strings can also be formatted as simply key due to a nil environment variable being set on the docker container.

eg: if you launch a container like so: docker run -e 'FOO' -it ubuntu when you inspect the container, it's JSON output will look like so:

            "Env": [
                "FOO",
                "PATH=/usr/local/sbin:/usr/local/bin:/usr/sbin:/usr/bin:/sbin:/bin"
            ],

The current method of splitting by directly calling .split will cause a stack trace in this event, even if the key which is nil is not something we are looking for.

To prevent that I've simply added a method that will ensure two items are always returned when splitting an envvar string. If an ennvar is nil, the value returned for val will be None.

ryan-lane commented 5 years ago

Thanks for the PR and great catch!

ryan-lane commented 5 years ago

Releasing this into 1.9.0.

JamesAwesome commented 5 years ago

🙇 Thank you!

ryan-lane commented 5 years ago

Released!