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

Support HTTPS certs, keys and CAs #261

Closed
wants to merge 1 commit into from
Closed

Conversation

sjug
Copy link

@sjug sjug commented Nov 14, 2017

As subject says, allows users to pass -cert -key and -CA so that pprof can be used against authenticated TLS endpoints.

Closes golang/go#20939 and #244

@vbatts
Copy link

vbatts commented Nov 14, 2017

seems fine to me

Copy link
Collaborator

@aalexand aalexand left a comment

Choose a reason for hiding this comment

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

Thanks for doing this! Can you please add tests that verify the new functionality end-to-end?

// HTTPS options
flagCertFile := flag.String("cert", "", "TLS client certificate file")
flagKeyFile := flag.String("key", "", "TLS private key file")
flagCAFile := flag.String("CA", "", "TLS CA certs file")
Copy link
Collaborator

Choose a reason for hiding this comment

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

It's a bit strange to have command line flag in capital letters. Is there a precedent for this?

Copy link
Author

@sjug sjug Nov 15, 2017

Choose a reason for hiding this comment

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

Agreed, my mistake.

tlsConfig.RootCAs = caCertPool
}

if url.Scheme == "https+insecure" {
Copy link
Collaborator

Choose a reason for hiding this comment

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

Should internal/symbolizer/symbolizer.go be updated as well?

Copy link
Author

@sjug sjug Nov 15, 2017

Choose a reason for hiding this comment

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

Do you mean the postURL() in symbolizer.go?

Copy link
Collaborator

Choose a reason for hiding this comment

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

Yes.

Copy link
Author

@sjug sjug Nov 15, 2017

Choose a reason for hiding this comment

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

The problem is the source struct which contains the flag values is in driver pkg. That's why Symbolizer() takes mode string rather than s *source. In order to keep it clean I would need to create a new package for the source struct, do you have any preference where it should go?

Copy link
Collaborator

@aalexand aalexand Nov 15, 2017

Choose a reason for hiding this comment

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

I don't think we should pass all of source struct to the symbolizer, it doesn't need most of that. Maybe something like this in internal/plugin/plugin.go:

type TLSParams struct {
  HTTPSCert, HTTPSKey, HTTPSCA string
}

and then pass it as to the symbolizer and to the fetcher as a new param.

Copy link
Author

Choose a reason for hiding this comment

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

Changed the implementation to use TLSParams, thoughts?

@aalexand
Copy link
Collaborator

@sjug Did you also see my

Can you please add tests that verify the new functionality end-to-end?

request? Just want to make sure it's not missed since it was a whole-PR comment rather than on a specific line and so looks subtle in the GH UI.

@sjug
Copy link
Author

sjug commented Nov 15, 2017

@aalexand Yep, didn't miss it. Will do.

@@ -34,6 +34,9 @@ type source struct {
Timeout int
Symbolize string
HTTPHostport string
HTTPSCert string
Copy link
Collaborator

Choose a reason for hiding this comment

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

Perhaps move these up to follow Sources field to emphasize that this is about setting up the TLS for fetching the profiles not for the HTTP server mode of pprof itself.

@@ -61,6 +64,10 @@ func parseFlags(o *plugin.Options) (*source, []string, error) {
flagContentions := flag.Bool("contentions", false, "Display number of delays at each region")
flagMeanDelay := flag.Bool("mean_delay", false, "Display mean delay at each region")
flagTools := flag.String("tools", os.Getenv("PPROF_TOOLS"), "Path for object tool pathnames")
// HTTPS options
flagCertFile := flag.String("cert", "", "TLS client certificate file")
Copy link
Collaborator

Choose a reason for hiding this comment

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

I like the brevity of the docs but we should here also clarify that this about the TLS params for profile and symbol fetch.

@@ -280,6 +290,9 @@ var usageMsgSrc = "\n\n" +
" Source options:\n" +
" -seconds Duration for time-based profile collection\n" +
" -timeout Timeout in seconds for profile collection\n" +
" -key Specify TLS private key\n" +
Copy link
Collaborator

Choose a reason for hiding this comment

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

Ditto (I like the brevity of the docs but we should here also clarify that this about the TLS params for profile and symbol fetch).

@@ -580,17 +581,35 @@ func adjustURL(source string, duration, timeout time.Duration) (string, time.Dur

// httpGet is a wrapper around http.Get; it is defined as a variable
// so it can be redefined during for testing.
var httpGet = func(source string, timeout time.Duration) (*http.Response, error) {
var httpGet = func(s *source, source string, timeout time.Duration) (*http.Response, error) {
Copy link
Collaborator

Choose a reason for hiding this comment

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

We shouldn't need to pass all of "s *source" here, we only need the TLS params?

Copy link
Author

Choose a reason for hiding this comment

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

Just seemed cleaner to not create anything extra, just reuse the existing struct. If we make the TLSParams in plugin.go that should work for Symbolizer() as well. Isn't having the same HTTPS* fields in the source struct redundant?

Copy link
Collaborator

@aalexand aalexand Nov 15, 2017

Choose a reason for hiding this comment

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

I would use TLSParams in the source structure as well to avoid the duplicated fields, but (as I said) would pass the source / URL string and the TLS params alone instead of passing the whole input structure. Passing only what's needed is better than being able to avoid another little struct imo.

tlsConfig.RootCAs = caCertPool
}

if url.Scheme == "https+insecure" {
Copy link
Collaborator

@aalexand aalexand Nov 15, 2017

Choose a reason for hiding this comment

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

I don't think we should pass all of source struct to the symbolizer, it doesn't need most of that. Maybe something like this in internal/plugin/plugin.go:

type TLSParams struct {
  HTTPSCert, HTTPSKey, HTTPSCA string
}

and then pass it as to the symbolizer and to the fetcher as a new param.

@sjug sjug force-pushed the pprof_https_auth branch 3 times, most recently from cecace9 to 302e336 Compare November 15, 2017 20:17
@aalexand
Copy link
Collaborator

The only thing that concerns me is that the TLS parameters are visible in the help and are exposed in the method signatures now regardless of whether the underlying symbolizer and fetcher need them. For example, at Google internally we use a custom fetch implementation which wouldn't need these options. I wonder if there is a better way to abstract these into the implementation of the fetcher and symbolizer. @rauls5382 do you have some ideas?

@sjug
Copy link
Author

sjug commented Nov 30, 2017

@aalexand Has a decision been made as to how this should be implemented so I can move forward with writing tests for this?

@aalexand
Copy link
Collaborator

Not yet. I was curious to hear @rauls5382's thoughts. Raul, any thoughts here?

@dgryski
Copy link
Contributor

dgryski commented Feb 15, 2018

Ping @rauls5382.

@nolanmar511
Copy link
Contributor

This functionality was added with #423, so I'm closing this PR.

Thanks for all the work here!

@nolanmar511 nolanmar511 closed this Jan 7, 2019
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
Projects
None yet
Development

Successfully merging this pull request may close these issues.

None yet

6 participants