Repository navigation
sptp-exporter: don't serve pprof on the exporter port - #601
Support-itecz wants to merge 1 commit into
Conversation
sptp-exporter links net/http/pprof, which registers /debug/pprof/* on http.DefaultServeMux, and PrometheusExporter.Start served that mux on :<exporterport>. The profiler was reachable on every interface even with -pprof left empty. Serve /metrics from a dedicated mux, as ntp/responder/stats already does for ntpresponder.
|
Hi @Support-itecz! Thank you for your pull request and welcome to our community. Action RequiredIn order to merge any pull request (code, docs, etc.), we require contributors to sign our Contributor License Agreement, and we don't seem to have one on file for you. ProcessIn order for us to review and merge your suggested changes, please sign at https://code.facebook.com/cla. If you are contributing on behalf of someone else (eg your employer), the individual CLA may not be sufficient and your employer may need to sign the corporate CLA. Once the CLA is signed, our tooling will perform checks and validations. Afterwards, the pull request will be tagged with If you have received this in error or have any questions, please contact us at cla@meta.com. Thanks! |
|
Unless you sign CLA we can't review this |
Summary
sptp-exporterblank-importsnet/http/pprof, whoseinitregisters/debug/pprof/*onhttp.DefaultServeMux.PrometheusExporter.Startregistered/metricson that same default mux and served it withhttp.ListenAndServe(":<exporterport>", nil), so the exporter port (6942 by default, all interfaces) answered every pprof endpoint even with-pprofleft empty, which the flag help describes as disabled. Anyone who can reach that port can read/debug/pprof/cmdline, full goroutine dumps and heap profiles, and start CPU profiles or execution traces against the process without authentication. It is the same exposure as CVE-2019-11248 (kubelet serving pprof on its healthz port).Startnow builds its ownServeMuxholding only/metrics, the same fixntp/responder/statsalready carries forntpresponder. Profiling stays available through the explicit-pproflistener, which keeps using the default mux.ptpcheck's metrics server also uses the default mux, but that binary does not linknet/http/pprof, so it is not affected and is left alone.Test Plan
Added
TestPrometheusExporterDoesNotServePprof, modeled onTestMonitoringPortDoesNotServePprofinntp/responder/stats. It linksnet/http/pprofthe way the binary does, runsStartagainst a stub sptp counters endpoint on[::1], waits for the scraped gauge on/metrics, then expects 404 from/debug/pprof/,/debug/pprof/cmdlineand/debug/pprof/symbol.Without the
prom_exporter.gochange:With it (Linux, Go 1.26.10):
Against the built binary with default flags (
-pprofunset),-exporterport 48942and a stub sptp on[::1]:48269:With
-pprof 127.0.0.1:48060the profiler still answers on that address (200) and the exporter port still returns 404.go build ./...,golangci-lint run(v2.15.0) andgofmt -lare clean.