Skip to content

Make daemon proxy settings configurable through daemon.json#42647

Closed
aiordache wants to merge 1 commit intomoby:masterfrom
aiordache:proxy_daemon_config
Closed

Make daemon proxy settings configurable through daemon.json#42647
aiordache wants to merge 1 commit intomoby:masterfrom
aiordache:proxy_daemon_config

Conversation

@aiordache
Copy link
Copy Markdown

@aiordache aiordache commented Jul 16, 2021

fixes #24758

Added proxy properties to daemon configuration (config file and dockerd flags).

- How to verify it

$ cat daemon.json 
{
    "http-proxy": "http://proxytest.example.com:80",
    "https-proxy": "https://proxytest.example.com:443"
}

$ dockerd --config-file daemon.json
$ docker pull busybox
Using default tag: latest
Error response from daemon: Get "https://registry-1.docker.io/v2/": proxyconnect tcp: dial tcp: lookup proxytest.example.com on 127.0.0.11:53: no such host


# docker build .     
Sending build context to Docker daemon  89.28MB
Step 1/3 : FROM golang:1.16-alpine AS base
Get "https://registry-1.docker.io/v2/": proxyconnect tcp: dial tcp: lookup proxytest.example.com on 127.0.0.11:53: no such host

Comment thread daemon/info.go Outdated
Comment on lines 67 to 69
Copy link
Copy Markdown
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Comment thread daemon/info.go Outdated
Copy link
Copy Markdown
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Ah, right. Guess this is the "magic" bit

Copy link
Copy Markdown
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Looking at this again, I think we should do this explicitly. Currently, setting the option relies on a side-effect of getEnvOrConfig() (and thus a side effect of daemon.SystemInfo(). I think it will be clearer to perform this step in the code that starts the daemon (after we did the initial validation of the daemon's configuration).

@aiordache aiordache force-pushed the proxy_daemon_config branch from e12b75b to 05e3527 Compare July 16, 2021 17:15
@tianon
Copy link
Copy Markdown
Member

tianon commented Jul 16, 2021

Honestly having a really hard time understanding the justification here -- why not use the frankly pretty well standardized environment variables instead?

Copy link
Copy Markdown
Contributor

@fredericdalleau fredericdalleau left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

LGTM

Copy link
Copy Markdown
Member

@thaJeztah thaJeztah left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Thanks! Sorry for the late reply on this one. I started a review, and had a branch with changes, but didn't post it, and had to rebase my branch to still work against master. Let me know if you want to take my branch or if I should push it as a separate PR (I left some commits un-squashed to explain the steps, and should probably squash those); https://github.com/moby/moby/compare/master...thaJeztah:proxy_daemon_config_carry?expand=1

Comment thread daemon/info.go
Comment on lines +67 to +68
HTTPProxy: maskCredentials(getEnvOrConfig(daemon.configStore.HTTPProxy, "HTTP_PROXY", "http_proxy")),
HTTPSProxy: maskCredentials(getEnvOrConfig(daemon.configStore.HTTPSProxy, "HTTPS_PROXY", "https_proxy")),
Copy link
Copy Markdown
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

We should make sure that these values are sanitised in other places as well;

  • the daemon prints an error message when it finds conflicting options (options passed both on the command-line and in the daemon.json), which contains the values for both.
  • when reloading the daemon configuration (kill -s HUP ..), the daemon's active configuration is printed.

Unfortunately it's a bit more involved to do so;

  • the maskCredentials() utility is not exported, so can't be used in some of those locations
  • in the SIGHUP / reload case, we marshal the whole config as JSON; sanitising the value will alter the actual config, so we need to either do a deep copy of the config, or we can extract the proxy-configuration fields to an embedded struct, and override.

Comment thread daemon/info.go
Comment on lines +312 to +316
func getEnvOrConfig(config string, env ...string) string {
val := getEnvAny(env...)
if val != "" {
return val
}
Copy link
Copy Markdown
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

The order in which we consider these options looks to be incorrect. I think the order of precedence is; (daemon.json | daemon flags) > env-vars. In other words; if a proxy is configured either as a command-line flag (--https-proxy) or through the daemon.json, it should override any env-var that's set.

Comment thread daemon/info.go Outdated
Copy link
Copy Markdown
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Looking at this again, I think we should do this explicitly. Currently, setting the option relies on a side-effect of getEnvOrConfig() (and thus a side effect of daemon.SystemInfo(). I think it will be clearer to perform this step in the code that starts the daemon (after we did the initial validation of the daemon's configuration).

@tianon
Copy link
Copy Markdown
Member

tianon commented Aug 31, 2021

Honestly having a really hard time understanding the justification here -- why not use the frankly pretty well standardized environment variables instead?

To follow up on this thought, the answer is Windows, where adding a variable to a service is anything but straightforward. 😬

@thaJeztah
Copy link
Copy Markdown
Member

Carrying these changes with my review suggestions in #42835

@thaJeztah thaJeztah closed this Sep 9, 2021
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Projects

None yet

Development

Successfully merging this pull request may close these issues.

Feature Request: Enable HTTP_PROXY Configuration as part of deamon json options

4 participants