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

Allow consul debug on non-ACL consul servers #15155

Merged

Conversation

kisunji
Copy link
Contributor

@kisunji kisunji commented Oct 25, 2022

Description

#10273 had an unintended side-effect of crashing consul debug CLI command if ACLs were disabled and debug_enabled was false.

The correct behavior would be to disable the HTTP endpoints for profiling information but still allowing other debug profile targets like logs and metrics to run without issues.

Testing & Reproduction steps

  • Modified tests to assert for previous behavior

PR Checklist

  • updated test coverage
  • external facing docs updated
  • not a security concern

@github-actions github-actions bot added theme/api Relating to the HTTP API interface theme/cli Flags and documentation for the CLI interface labels Oct 25, 2022
Comment on lines +243 to +250
// If enableDebug or ACL enabled, register wrapped pprof handlers
if enableDebug || !s.checkACLDisabled() {
handlePProf("/debug/pprof/", pprof.Index)
handlePProf("/debug/pprof/cmdline", pprof.Cmdline)
handlePProf("/debug/pprof/profile", pprof.Profile)
handlePProf("/debug/pprof/symbol", pprof.Symbol)
handlePProf("/debug/pprof/trace", pprof.Trace)
}
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 thought it would make more sense for the handler registration to be guarded by the if condition here rather than allowing the endpoints to be exposed but returning a 401 every time.

Would this cause any side effects?

Copy link
Member

Choose a reason for hiding this comment

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

The only one I can think of is that it will alter the HTTP status code send back when enable debug is false and acls are not on. I think it will be a 404 instead of a 403/401. I think that should be fine though.

@@ -209,13 +209,6 @@ func (s *HTTPHandlers) handler(enableDebug bool) http.Handler {
var token string
s.parseToken(req, &token)

// If enableDebug is not set, and ACLs are disabled, write
// an unauthorized response
if !enableDebug && s.checkACLDisabled() {
Copy link
Contributor Author

Choose a reason for hiding this comment

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

Instead of checking these conditions per request, I've moved the check below to conditionally register pprof handlers instead.

if c.captureTarget(targetProfiles) {
dir, err := makeIntervalDir(c.output, c.timeNow())
Copy link
Contributor Author

Choose a reason for hiding this comment

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

avoids making empty directories if this branch is never entered

@@ -274,6 +273,22 @@ func (c *cmd) prepare() (version string, err error) {
c.capture = defaultTargets
}

// If EnableDebug is not true, skip collecting pprof
enableDebug, ok := self["DebugConfig"]["EnableDebug"].(bool)
Copy link
Contributor Author

Choose a reason for hiding this comment

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

@kisunji kisunji marked this pull request as ready for review October 26, 2022 17:58
agent/connect/ca/testing.go Outdated Show resolved Hide resolved
@kisunji kisunji added backport/1.12 Changes are backported to 1.12 backport/1.13 Changes are backported to 1.13 backport/1.14 Changes are backported to 1.14 labels Oct 26, 2022
Copy link
Member

@mkeeler mkeeler left a comment

Choose a reason for hiding this comment

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

I approved but I think the connect ca testing code could probably be rolled back. Its not a blocker though

Comment on lines +243 to +250
// If enableDebug or ACL enabled, register wrapped pprof handlers
if enableDebug || !s.checkACLDisabled() {
handlePProf("/debug/pprof/", pprof.Index)
handlePProf("/debug/pprof/cmdline", pprof.Cmdline)
handlePProf("/debug/pprof/profile", pprof.Profile)
handlePProf("/debug/pprof/symbol", pprof.Symbol)
handlePProf("/debug/pprof/trace", pprof.Trace)
}
Copy link
Member

Choose a reason for hiding this comment

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

The only one I can think of is that it will alter the HTTP status code send back when enable debug is false and acls are not on. I think it will be a 404 instead of a 403/401. I think that should be fine though.

@kisunji kisunji force-pushed the NET-1174-74937-consul-debug-cli-broken-on-non-acl-clusters branch from 7163f33 to 86972fa Compare October 26, 2022 19:30
Copy link
Collaborator

@dhiaayachi dhiaayachi left a comment

Choose a reason for hiding this comment

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

LGTM!

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
backport/1.12 Changes are backported to 1.12 backport/1.13 Changes are backported to 1.13 backport/1.14 Changes are backported to 1.14 pr/no-metrics-test theme/api Relating to the HTTP API interface theme/cli Flags and documentation for the CLI interface
Projects
None yet
Development

Successfully merging this pull request may close these issues.

None yet

3 participants