Skip to content

support reading basic_auth_password_file for HTTP basic auth#4077

Merged
brian-brazil merged 1 commit intoprometheus:masterfrom
adamdecaf:basic-auth-password-file
Apr 25, 2018
Merged

support reading basic_auth_password_file for HTTP basic auth#4077
brian-brazil merged 1 commit intoprometheus:masterfrom
adamdecaf:basic-auth-password-file

Conversation

@adamdecaf
Copy link
Contributor

This requires the BasicAuthPasswordFile added to common. See https://github.com/prometheus/common/pull/129/files#diff-a2356a3b837239d300d6a0326a452aafR70

Issue: #4076

@adamdecaf adamdecaf force-pushed the basic-auth-password-file branch from eec69a2 to 358ffe5 Compare April 10, 2018 21:51
Copy link
Contributor

Choose a reason for hiding this comment

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

There should be no code changes required, Prometheus shouldn't be duplicating this code.

Copy link
Contributor Author

Choose a reason for hiding this comment

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

@brian-brazil I've updated prometheus/common#129 in prometheus from master, but am not seeing successful auth'd requests. I think this block of code is duplicated in prometheus.

Copy link
Contributor

Choose a reason for hiding this comment

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

To be clear, I'm saying to stop Prometheus duplicating this code. It's was meant to be switched to the code from common.

Copy link
Contributor Author

Choose a reason for hiding this comment

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

Ok. I'm testing that change now locally.

@adamdecaf
Copy link
Contributor Author

adamdecaf commented Apr 11, 2018

@brian-brazil I'm having trouble implementing prometheus/common#129 into prometheus. I think the reimplementation of basicAuthRoundTripper breaks the ability to compose timeouts with the Authorization header.

Inside util/httpclient/client.go I have:

Details
// NewRoundTripperFromConfig returns a new HTTP RoundTripper configured for the
// given config.HTTPClientConfig. The name is used as go-conntrack metric label.
func NewRoundTripperFromConfig(cfg config_util.HTTPClientConfig, name string) (http.RoundTripper, error) {
	client, err := config_util.NewHTTPClientFromConfig(&cfg)
	if err != nil {
		return nil, err
	}

	// The only timeout we care about is the configured scrape timeout.
	// It is applied on request. So we leave out any timings here.
	if client.Transport == nil {
		client.Transport = &http.Transport{}
	}
	// Apply http.Transport specific settings
	rt, ok := client.Transport.(*http.Transport)
	if ok {
		rt.Proxy = http.ProxyURL(cfg.ProxyURL.URL)
		rt.MaxIdleConns = 20000
		rt.MaxIdleConnsPerHost = 1000 // see https://github.com/golang/go/issues/13801
		rt.DisableKeepAlives = false
		rt.DisableCompression = true
		// 5 minutes is typically above the maximum sane scrape interval. So we can
		// use keepalive for all configurations.
		rt.IdleConnTimeout = 5 * time.Minute
		rt.DialContext = conntrack.NewDialContextFunc(
			conntrack.DialWithTracing(),
			conntrack.DialWithName(name),
		)
		client.Transport = rt
	}

	return client.Transport, nil
}

Prometheus isn't making successful authed requests though.

@adamdecaf
Copy link
Contributor Author

Hang on. It's a problem with my credentials.

@adamdecaf adamdecaf force-pushed the basic-auth-password-file branch 2 times, most recently from f4230a4 to 232ac92 Compare April 17, 2018 14:00
@adamdecaf
Copy link
Contributor Author

adamdecaf commented Apr 17, 2018

After copying httputil over to the common repo I manually vendored it back into prometheus and then updated the imports/calls.

I'm going to test this out manually to verify the marathon case works.

Edit: It's working.

@adamdecaf adamdecaf force-pushed the basic-auth-password-file branch 2 times, most recently from 980aed9 to eb28aa8 Compare April 23, 2018 14:36
@adamdecaf
Copy link
Contributor Author

adamdecaf commented Apr 23, 2018

@brian-brazil Thanks for the prometheus/common merge. I cleaned up this branch and revendored that change here. I'm going to test it locally again just to double check, but this should be g2g.

Edit: It's working for me.

Copy link
Contributor

Choose a reason for hiding this comment

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

End sentences with a full stop.

Copy link
Contributor

Choose a reason for hiding this comment

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

This is not the only basic_auth in this file.

@adamdecaf adamdecaf force-pushed the basic-auth-password-file branch from eb28aa8 to dbbfa8a Compare April 25, 2018 14:33
@adamdecaf
Copy link
Contributor Author

@brian-brazil Updated.

@adamdecaf
Copy link
Contributor Author

adamdecaf commented Apr 25, 2018

That test failed before on this branch too, but it's passing for me locally. All tests pass locally for me.

$ go test -race github.com/prometheus/prometheus/discovery/kubernetes -count 1
ok  	github.com/prometheus/prometheus/discovery/kubernetes	1.474s

Issue: prometheus#4076

Signed-off-by: Adam Shannon <adamkshannon@gmail.com>
@adamdecaf adamdecaf force-pushed the basic-auth-password-file branch from dbbfa8a to 1cfa098 Compare April 25, 2018 15:27
@brian-brazil
Copy link
Contributor

That test is known to be flaky.

@brian-brazil brian-brazil merged commit 809881d into prometheus:master Apr 25, 2018
@brian-brazil
Copy link
Contributor

Thanks!

@adamdecaf adamdecaf deleted the basic-auth-password-file branch April 25, 2018 17:21
@juliusv
Copy link
Member

juliusv commented May 17, 2018

This broke basic auth configs without a username due to the new code now requiring them, see #4173.

gouthamve pushed a commit to gouthamve/prometheus that referenced this pull request Aug 1, 2018
@alexellis
Copy link

Hi folks, what is the static on this PR? Our users could really benefit from this security fix. I can't see it documented in the published site yet? https://prometheus.io/docs/alerting/configuration/#http_config

Thanks,

Alex cc @LucasRoesler

@simonpasquier
Copy link
Member

@alexellis the option is already available in AlertManager v0.15.3 but it is true that it isn't documented. As it was implemented in github.com/prometheus/commong, it got added to AlertManager in stealth mode ;-)

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.

5 participants