Skip to content

Add support to use Proxy From Environment#462

Merged
roidelapluie merged 1 commit intoprometheus:mainfrom
roidelapluie:proxyfromenv
Mar 8, 2023
Merged

Add support to use Proxy From Environment#462
roidelapluie merged 1 commit intoprometheus:mainfrom
roidelapluie:proxyfromenv

Conversation

@roidelapluie
Copy link
Member

This commit adds a new field ProxyFromEnvironment to the HTTPClientConfig and OAuth2 structs to enable Prometheus to use the default proxy from the environment variable (as specified in net/http ProxyFromEnvironment.) This is opt-out by default, so does not change anything for existing users.

This change is necessary because Prometheus previously had insufficient behavior to avoid proxying EC2 metadata requests when proxy_url is set in ec2_sd_configs.

See prometheus/prometheus#11991

@roidelapluie roidelapluie force-pushed the proxyfromenv branch 4 times, most recently from 6fc6baf to 26800d4 Compare March 6, 2023 20:09
// UnmarshalYAML implements the yaml.Unmarshaler interface.
func (c *ProxyConfig) Validate() error {
if len(c.ProxyConnectHeader) > 0 && (!c.ProxyFromEnvironment && (c.ProxyURL.URL == nil || c.ProxyURL.String() == "")) {
return fmt.Errorf("if proxy_connect_header is configured proxy_url or proxy_from_environment must also be configured")
Copy link
Contributor

Choose a reason for hiding this comment

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

small readability nit (applies to other messages too)

Suggested change
return fmt.Errorf("if proxy_connect_header is configured proxy_url or proxy_from_environment must also be configured")
return fmt.Errorf("if proxy_connect_header is configured, proxy_url or proxy_from_environment must also be configured")

This commit adds a new field `ProxyFromEnvironment` to the
`HTTPClientConfig` and `OAuth2` structs to enable Prometheus to use the
default proxy from the environment variable (as specified in net/http
ProxyFromEnvironment.) This is opt-out by default, so does not change
anything for existing users.

This change is necessary because Prometheus previously had insufficient
behavior to avoid proxying EC2 metadata requests when `proxy_url` is
set in `ec2_sd_configs`.

This commit also adds the ability to support `no_proxy`.

See prometheus/prometheus#11991

Signed-off-by: Julien Pivotto <roidelapluie@o11y.eu>
Copy link
Member

@SuperQ SuperQ left a comment

Choose a reason for hiding this comment

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

LGTM

@roidelapluie roidelapluie merged commit 66b493f into prometheus:main Mar 8, 2023
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

3 participants