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

Add authenticated debug server #187

Merged
merged 6 commits into from
Oct 23, 2017
Merged

Add authenticated debug server #187

merged 6 commits into from
Oct 23, 2017

Conversation

zwass
Copy link
Contributor

@zwass zwass commented Oct 19, 2017

  • Add the runtime/pprof tools as an HTTP server
  • Toggle server state by sending SIGUSR1 (default off)
  • Port randomly chosen from available ports on startup (for reliability)
  • Auth token generated on startup (for security)
  • Address with auth written to $launcher_root/debug_addr, and logs

@zwass zwass requested review from marpaia and groob October 19, 2017 21:04
@@ -92,6 +93,11 @@ func main() {
logFatal(logger, "err", errors.Wrap(err, "detecting platform"))
}

debugTokenPath := filepath.Join(rootDirectory, "debug_token")
if err := debug.StartDebugServer("localhost:5097", debugTokenPath, logger); err != nil {
Copy link
Contributor

Choose a reason for hiding this comment

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

the port should not be hardcoded. We're going to end up failing on a bunch of machines just because. It should be a random available port IMO.

@@ -92,6 +93,11 @@ func main() {
logFatal(logger, "err", errors.Wrap(err, "detecting platform"))
}

debugTokenPath := filepath.Join(rootDirectory, "debug_token")
Copy link
Contributor

Choose a reason for hiding this comment

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

I think the debug server should be hidden by a flag. Perhaps it's own flag, or perhaps just --debug.

Copy link
Contributor Author

Choose a reason for hiding this comment

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

I'd like to reason about the possibility of leaving it on by default... We are not binding to any public address, and not exposing any particularly sensitive information. It's not as useful if someone encounters an issue and then cannot turn on the server for a running process.

@zwass
Copy link
Contributor Author

zwass commented Oct 23, 2017

The compromise we came up with was to leave the debug server off by default, but toggle its state by sending SIGUSR1. The server will start with a random available port (for reliability), and a new randomly generated auth token (for security).

Gopkg.toml Outdated

[[constraint]]
branch = "master"
name = "github.com/e-dard/netbug"
Copy link
Contributor

Choose a reason for hiding this comment

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

thoughts on moving the html template into this repo before merging?

debug/debug.go Outdated
}

// The below handler code is adapted from MIT licensed github.com/e-dard/netbug
func handler(token string, logger log.Logger) http.Handler {
Copy link
Contributor

Choose a reason for hiding this comment

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

You can have http.HandlerFunc as the return arg. That returns a handler but you don't have to cast the function in the return.

debug/debug.go Outdated
if r.FormValue("token") == token {
h.ServeHTTP(w, r)
} else {
w.WriteHeader(http.StatusUnauthorized)
Copy link
Contributor

Choose a reason for hiding this comment

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

Use http.Error

debug/debug.go Outdated
serv := http.Server{
Handler: r,
}
listener, err := net.Listen("tcp", "localhost:0")
Copy link
Contributor

Choose a reason for hiding this comment

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

Can you add a comment explaining :0 ?

debug/debug.go Outdated
}
}()

addr := fmt.Sprintf("http://%s/debug/?token=%s", listener.Addr().String(), token.String())
Copy link
Contributor

Choose a reason for hiding this comment

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

What do you think about adding url.Parse on the addr for additional validation?

Copy link
Contributor

@groob groob left a comment

Choose a reason for hiding this comment

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

Nice!

Copy link
Contributor

@marpaia marpaia left a comment

Choose a reason for hiding this comment

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

🚢

@zwass zwass merged commit 0c38b43 into kolide:master Oct 23, 2017
@zwass zwass deleted the debug_server branch October 23, 2017 23:16
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