cli icon indicating copy to clipboard operation
cli copied to clipboard

Configuring proxies in config.json randomizes environment-variable order

Open thaJeztah opened this issue 7 years ago • 0 comments

Noticed this when working on https://github.com/docker/cli/pull/1573

I have a fix (and some refactoring for this); still cleaning it up a bit, but will open a PR after that

When specifying environment variables, the order in which the variables are set is preserved;

docker run --rm --env no_proxy=one --env NO_PROXY=two --env HTTPS_PROXY=three busybox env
PATH=/usr/local/sbin:/usr/local/bin:/usr/sbin:/usr/bin:/sbin:/bin
HOSTNAME=8f03e5a9a4d1
no_proxy=one
NO_PROXY=two
HTTPS_PROXY=three
HOME=/root

docker run --rm --env no_proxy=one --env NO_PROXY=two --env HTTPS_PROXY=three busybox env
PATH=/usr/local/sbin:/usr/local/bin:/usr/sbin:/usr/bin:/sbin:/bin
HOSTNAME=8f03e5a9a4d1
no_proxy=one
NO_PROXY=two
HTTPS_PROXY=three
HOME=/root

However, when configuring proxies in the config.json configuration file, those proxy-settings are merged with environment-variables set on the command-line, causing their order to be randomized;

echo '{ "proxies": {"default": { "httpProxy": "four" }}}' > config.json

docker --config=./ run --rm --env no_proxy=one --env NO_PROXY=two --env HTTPS_PROXY=three busybox env
PATH=/usr/local/sbin:/usr/local/bin:/usr/sbin:/usr/bin:/sbin:/bin
HOSTNAME=f9b54b5489fa
no_proxy=one
NO_PROXY=two
HTTPS_PROXY=three
HTTP_PROXY=four
http_proxy=four
HOME=/root


docker --config=./ run --rm --env no_proxy=one --env NO_PROXY=two --env HTTPS_PROXY=three busybox env
PATH=/usr/local/sbin:/usr/local/bin:/usr/sbin:/usr/bin:/sbin:/bin
HOSTNAME=8e7b6b848827
HTTPS_PROXY=three
HTTP_PROXY=four
http_proxy=four
no_proxy=one
NO_PROXY=two
HOME=/root

The problem is caused by ParseProxyConfig converting the environment variables to a map, and Golang (by design) randomizes the order of maps when iterating over them.

thaJeztah avatar Dec 13 '18 21:12 thaJeztah