Skip to content

Configuring proxies in config.json randomizes environment-variable order #1574

@thaJeztah

Description

@thaJeztah

Noticed this when working on #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.

Metadata

Metadata

Assignees

Type

No type
No fields configured for issues without a type.

Projects

No projects

Milestone

No milestone

Relationships

None yet

Development

No branches or pull requests

Issue actions