Skip to content

Prevent http.DefaultServeMux exposure on CMSA#1197

Merged
laoj2 merged 1 commit into
GoogleCloudPlatform:masterfrom
laoj2:httpmux
May 20, 2026
Merged

Prevent http.DefaultServeMux exposure on CMSA#1197
laoj2 merged 1 commit into
GoogleCloudPlatform:masterfrom
laoj2:httpmux

Conversation

@laoj2
Copy link
Copy Markdown
Member

@laoj2 laoj2 commented May 20, 2026

When the Prometheus /metrics endpoint is enabled, the HTTP server was initialized via http.ListenAndServe(addr, nil), defaulting to the global http.DefaultServeMux

Transitive third-party dependencies (like k8s libraries) register global debug and profiling handlers (/debug/pprof/*), these endpoints were unintentionally exposed publicly on the metrics port.

So, we're isolating the /metrics endpoint by initializing a dedicated ServeMux.

Tested on a live cluster with --metrics-address=0.0.0.0:8080 flag configured on the CMSA deployment:

Metrics scraping still works:

curl -i http://localhost:8080/metrics
HTTP/1.1 200 OK

Profiling endpoints are no longer exposed as a side effect:

curl -i http://localhost:8080/debug/pprof/
HTTP/1.1 404 Not Found 

When the Prometheus /metrics endpoint is enabled, the HTTP server was
initialized via `http.ListenAndServe(addr, nil)`, defaulting to the
global `http.DefaultServeMux`

Transitive third-party dependencies (like k8s libraries) register global debug and profiling handlers (/debug/pprof/*), these diagnostic and performance endpoints were unintentionally exposed publicly on the metrics port.

So, we're isolating the /metrics endpoint by initializing a dedicated
ServeMux.

Tested on a live cluster with --metrics-address=0.0.0.0:8080 flag
configured qqon the CMSA deployment:

Metrics scraping still works:
curl -i http://localhost:8080/metrics

Profiling endpoints are no longer exposed as a side effect:

curl -i http://localhost:8080/debug/pprof/
@laoj2 laoj2 requested a review from rsgowman May 20, 2026 18:05
Copy link
Copy Markdown
Contributor

@rsgowman rsgowman left a comment

Choose a reason for hiding this comment

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

lgtm.

@laoj2 laoj2 merged commit a2a3a79 into GoogleCloudPlatform:master May 20, 2026
18 checks passed
@laoj2 laoj2 deleted the httpmux branch May 21, 2026 13:25
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.

2 participants