Skip to content

config: reload cert files from disk automatically - #173

Merged
brian-brazil merged 4 commits into
prometheus:masterfrom
simonpasquier:fix-4155
Mar 12, 2019
Merged

config: reload cert files from disk automatically#173
brian-brazil merged 4 commits into
prometheus:masterfrom
simonpasquier:fix-4155

Conversation

@simonpasquier

@simonpasquier simonpasquier commented Feb 28, 2019

Copy link
Copy Markdown
Member

@brian-brazil

Copy link
Copy Markdown
Contributor

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

@brancz

brancz commented Feb 28, 2019

Copy link
Copy Markdown
Member

@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
Copy Markdown
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
Copy Markdown
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
Copy Markdown
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

Comment thread config/http_config.go

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

Copy link
Copy Markdown
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
Copy Markdown
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
Copy Markdown
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
Copy Markdown
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
Copy Markdown
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
Copy Markdown
Member Author

Choose a reason for hiding this comment

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

Comment thread config/http_config.go
@beorn7

beorn7 commented Mar 5, 2019

Copy link
Copy Markdown
Contributor

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>
Comment thread config/http_config.go
}

func (rt *bearerAuthRoundTripper) CloseIdleConnections() {
if ci, ok := rt.rt.(closeIdler); ok {

Copy link
Copy Markdown
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

@simonpasquier simonpasquier Mar 7, 2019

Copy link
Copy Markdown
Member Author

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
Copy Markdown
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
Copy Markdown
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
Copy Markdown
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

brancz commented Mar 7, 2019

Copy link
Copy Markdown
Member

lgtm 👍

@roidelapluie

Copy link
Copy Markdown
Member

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

Comment thread config/http_config.go Outdated
}

func (t *tlsRoundTripper) CloseIdleConnections() {
t.mtx.Lock()

Copy link
Copy Markdown
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
Copy Markdown
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