Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

config: reload cert files from disk automatically #173

Merged
merged 4 commits into from
Mar 12, 2019

Conversation

simonpasquier
Copy link
Member

@simonpasquier simonpasquier commented Feb 28, 2019

@brian-brazil
Copy link
Contributor

This would only apply on reload, it shouldn't require that to be in line with how the other auth files work.

@brancz
Copy link
Member

brancz commented Feb 28, 2019

@brian-brazil Are you saying the other file references need to be handled as well, or in the same way? As far as I can tell the only other one in the http config is the bearerTokenFile, which is already handled by re-reading on every scrape. Not objecting, just trying to understand what you meant.

@brian-brazil
Copy link
Contributor

The other ones are already handled this way.

@simonpasquier simonpasquier changed the title config: add CheckFiles() method to TLSConfig config: reload cert files from disk automatically Mar 4, 2019
Signed-off-by: Simon Pasquier <spasquie@redhat.com>
@simonpasquier simonpasquier force-pushed the fix-4155 branch 3 times, most recently from 844be5f to d8d76bd Compare March 4, 2019 13:58
Signed-off-by: Simon Pasquier <spasquie@redhat.com>
@simonpasquier
Copy link
Member Author

@brian-brazil @brancz can you have a look again? FWIW I've tested it locally.
This PR is using tls.Config.GetClientCertificate which is only available since Go 1.8. I've assumed that the change doesn't have to be made for earlier versions of Go so I've added // +build go1.8 directives. If this is wrong, I could amend the PR to remove this "limitation".

@brian-brazil
Copy link
Contributor

I've assumed that the change doesn't have to be made for earlier versions of Go so I've added // +build go1.8 directives. If this is wrong, I could amend the PR to remove this "limitation".

This won't be used by client_golang, so that seems a safe assumption. FYI @beorn7


if cfg.BasicAuth != nil {
rt = NewBasicAuthRoundTripper(cfg.BasicAuth.Username, cfg.BasicAuth.Password, cfg.BasicAuth.PasswordFile, rt)
if len(cfg.TLSConfig.CAFile) == 0 {
Copy link
Contributor

Choose a reason for hiding this comment

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

I'm not getting what you're trying to do here.

Copy link
Member Author

Choose a reason for hiding this comment

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

If no CA file is provided, we don't need a round tripper that reloads the CA. So we return a "normal" round-tripper.

Copy link
Contributor

Choose a reason for hiding this comment

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

What if the root changes?

Copy link
Member Author

Choose a reason for hiding this comment

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

Which root?

Copy link
Contributor

Choose a reason for hiding this comment

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

I meant the CA (as that's usually the root), but that would miss the client ssl auth changing.

Copy link
Member Author

Choose a reason for hiding this comment

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

config/http_config.go Show resolved Hide resolved
@beorn7
Copy link
Member

beorn7 commented Mar 5, 2019

This won't be used by client_golang, so that seems a safe assumption.

And even if we did at some point in the future, I see little problems raising the min requirement for client_golang to 1.8. Those are ancient versions, and while I think we should support them as long as it doesn't cause any overhead, we should not commit to more than that.

Signed-off-by: Simon Pasquier <spasquie@redhat.com>
@@ -195,6 +199,12 @@ func (rt *bearerAuthRoundTripper) RoundTrip(req *http.Request) (*http.Response,
return rt.rt.RoundTrip(req)
}

func (rt *bearerAuthRoundTripper) CloseIdleConnections() {
if ci, ok := rt.rt.(closeIdler); ok {
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 cleaner in Go 1.12 as it exposes this directly, without having to reach into the transport

Copy link
Member Author

@simonpasquier simonpasquier Mar 7, 2019

Choose a reason for hiding this comment

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

You refer to client.CloseIdleConnections()? I don't know how we can avoid going through the nested round-trippers until we call http.Transport.CloseIdleConnections().

https://golang.org/src/net/http/client.go?s=27593:27632#L841

Copy link
Member

Choose a reason for hiding this comment

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

Have we even switched over to go 1.12 everywhere? I feel like it might be a little early to use that. I think I'd prefer this approach at this point.

Copy link
Contributor

Choose a reason for hiding this comment

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

Can we add a TODO at least to clean this up?

Copy link
Member Author

Choose a reason for hiding this comment

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

I'm still not clear about what the TODO should be about... AFAICT consumers of the library using Go 1.12 will be able to do this and it will just work:

client, err := config.NewClient(...)
...
client.CloseIdleConnections()

But again I don't see how we could avoid having CloseIdleConnections() for all the custom round-trippers if we want client.CloseIdleConnections() to be effective.

@brancz
Copy link
Member

brancz commented Mar 7, 2019

lgtm 👍

@roidelapluie
Copy link
Member

@simonpasquier this is so awesome. I will be able to drop my https://github.com/roidelapluie/sslproxy :)

}

func (t *tlsRoundTripper) CloseIdleConnections() {
t.mtx.Lock()
Copy link
Contributor

Choose a reason for hiding this comment

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

Wouldn't this be a read lock?

Copy link
Member Author

Choose a reason for hiding this comment

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

Correct.

Signed-off-by: Simon Pasquier <spasquie@redhat.com>
@brian-brazil brian-brazil merged commit e6686eb into prometheus:master Mar 12, 2019
@simonpasquier simonpasquier deleted the fix-4155 branch March 12, 2019 11:44
simonpasquier added a commit to simonpasquier/prometheus that referenced this pull request Apr 10, 2019
This change bumps github.com/prometheus/common to include
prometheus/common#173

Signed-off-by: Simon Pasquier <spasquie@redhat.com>
brian-brazil pushed a commit to prometheus/prometheus that referenced this pull request Apr 10, 2019
* Reload certificates from disk automatically

This change bumps github.com/prometheus/common to include
prometheus/common#173

Signed-off-by: Simon Pasquier <spasquie@redhat.com>

* scrape: close idle connections on reload/stop

Signed-off-by: Simon Pasquier <spasquie@redhat.com>

* use v0.3.0 tag

Signed-off-by: Simon Pasquier <spasquie@redhat.com>
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