Skip to content

Fix pprof broad exposition#996

Merged
jotak merged 3 commits into
netobserv:mainfrom
jotak:pprof
Jun 25, 2026
Merged

Fix pprof broad exposition#996
jotak merged 3 commits into
netobserv:mainfrom
jotak:pprof

Conversation

@jotak

@jotak jotak commented Jun 23, 2026

Copy link
Copy Markdown
Member

Description

When pprof was enabled, it was exposed on ":(port)" which stands for all net interfaces.

Settings are changed so the user controls what address to use. For example, they can configure it with "127.0.0.1:6060" to restrict to the local loop (more secured), or keep ":6060" or "0.0.0.0:6060" for a broader exposition. Documented those security aspects.

Note that this setting is not exposed in netobserv API, but can still be configured using the environment variable.

Additionally, the pprof server now uses the common safeguards against resource exhaustion attacks

Breaking changes:

  • config for pprof changed from env "PROFILE_PORT" to "PPROF_ADDR", now including the listening address.

Dependencies

Checklist

  • Does the changes in PR need specific configuration or environment set up for testing?
    • if so please describe it in PR description.
  • I have added thorough unit tests for the change.
  • QE requirements (check 1 from the list):
    • Standard QE validation, with pre-merge tests unless stated otherwise.
    • Regression tests only (e.g. refactoring with no user-facing change).
    • No QE (e.g. trivial change with high reviewer's confidence, or per agreement with the QE team).

To run a perfscale test, comment with: /test ebpf-node-density-heavy-25nodes

Summary by CodeRabbit

  • Configuration Changes

    • Profiling configuration now uses PPROF_ADDR (string listen address) instead of PROFILE_PORT; profiling is disabled when PPROF_ADDR isn’t set.
  • Security Improvements

    • Hardened HTTP server defaults across services, including secure TLS baseline (TLS 1.3 minimum), safer request/body limits, and improved timeout handling.
  • Documentation

    • Updated configuration and profiling guides with PPROF_ADDR, including revised example settings and Kubernetes port-forward guidance.

When pprof was enabled, it was exposed on ":(port)" which stands for all
net interfaces.

Settings are changed so the user controls what address to use. For
example, they can configure it with "127.0.0.1:6060" to restrict to the
local loop (more secured), or keep ":6060" or "0.0.0.0:6060" for a
broader exposition. Documented those security aspects.

Note that this setting is not exposed in netobserv API, but can still be
configured using the environment variable.

Additionally, the pprof server now uses the common safeguards against
resource exhaustion attacks

*Breaking changes*:
- config for pprof changed from env "PROFILE_PORT" to "PPROF_ADDR", now
  including the listening address.
@coderabbitai

coderabbitai Bot commented Jun 23, 2026

Copy link
Copy Markdown

Review Change Stack

Warning

Review limit reached

@jotak, we couldn't start this review because you've reached your PR review rate limit.

More reviews will be available in 38 minutes and 50 seconds. Learn how PR review limits work.

Your organization has used up its prepaid credits, and credit purchases are no longer available. Enable the review add-on in the billing tab to keep reviews running — you're only billed for reviews past your plan's rate limits ($0.25/file).

⌛ How to resolve this issue?

After more reviews become available, a review can be triggered using the @coderabbitai review command as a PR comment. Alternatively, push new commits to this PR.

To avoid repeated limits, reduce automatic review volume by pausing incremental auto-reviews earlier, using label-based review opt-in, excluding WIP or generated PR titles, or requesting reviews manually when the PR is ready. If your team needs uninterrupted high-volume reviews, an organization admin can enable usage-based credits.

🚦 How do rate limits work?

CodeRabbit enforces per-developer PR review limits for each organization. Most developers receive the normal plan review availability.

For paid Pro and Pro+ PR reviews, CodeRabbit uses adaptive limits for sustained high-volume activity. When a developer's recent PR review activity reaches the 95th percentile or higher among CodeRabbit users, additional reviews become available more gradually as earlier reviews age out of the rolling window.

Please see our Fair Usage Limits Policy for further information.

ℹ️ Review info
⚙️ Run configuration

Configuration used: Path: .coderabbit.yaml

Review profile: CHILL

Plan: Pro

Run ID: 6d5267c5-a996-4dcd-aeeb-f93f78c884d4

📥 Commits

Reviewing files that changed from the base of the PR and between 5554b95 and f6e8ed1.

📒 Files selected for processing (1)
  • cmd/netobserv-ebpf-agent.go
📝 Walkthrough

Walkthrough

Introduces pkg/server/common.go with a shared Default(*http.Server) helper. The Prometheus server and agent pprof startup now use it. ProfilePort is replaced by PprofAddr, and the related docs are updated.

Changes

Shared HTTP server defaults and PPROF_ADDR migration

Layer / File(s) Summary
New server.Default helper
pkg/server/common.go
Adds Default(*http.Server) *http.Server that enforces body-size middleware (when a handler is set), zero-value timeout defaults, MaxHeaderBytes, TLS 1.3 minimum, and HTTP/2 disabling via TLSNextProto.
Config rename and server migrations
pkg/config/config.go, pkg/prometheus/prom_server.go, cmd/netobserv-ebpf-agent.go
Replaces ProfilePort int with PprofAddr string in Agent. Removes the local defaultServer from prom_server.go and calls server.Default instead. Agent entrypoint switches pprof conditional to PprofAddr != "" and constructs the pprof server via server.Default.
Docs
docs/config.md, docs/profiling.md
Documents PPROF_ADDR replacing PROFILE_PORT, adds address-binding security guidance, and updates the Kubernetes port-forward example.

Estimated code review effort

🎯 2 (Simple) | ⏱️ ~10 minutes

🚥 Pre-merge checks | ✅ 4 | ❌ 1

❌ Failed checks (1 warning)

Check name Status Explanation Resolution
Docstring Coverage ⚠️ Warning Docstring coverage is 0.00% which is insufficient. The required threshold is 80.00%. Write docstrings for the functions missing them to satisfy the coverage threshold.
✅ Passed checks (4 passed)
Check name Status Explanation
Title check ✅ Passed The title matches the main change: tightening and configuring pprof exposure.
Linked Issues check ✅ Passed Check skipped because no linked issues were found for this pull request.
Out of Scope Changes check ✅ Passed Check skipped because no linked issues were found for this pull request.
Description check ✅ Passed The PR description follows the template and includes purpose, breaking change, dependencies, and QE choice, with only minor checklist details left unfilled.

✏️ Tip: You can configure your own custom pre-merge checks in the settings.

✨ Finishing Touches
🧪 Generate unit tests (beta)
  • Create PR with unit tests

Warning

Review ran into problems

🔥 Problems

Linked repositories: Your configuration references 2 linked repositories, but your current plan allows 0. Analyzed ``, skipped netobserv/netobserv-operator, `netobserv/flowlogs-pipeline`.


Thanks for using CodeRabbit! It's free for OSS, and your support helps us grow. If you like it, consider giving us a shout-out.

❤️ Share

Comment @coderabbitai help to get the list of available commands.

@coderabbitai coderabbitai Bot left a comment

Copy link
Copy Markdown

Choose a reason for hiding this comment

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

Actionable comments posted: 6

🤖 Prompt for all review comments with AI agents
Verify each finding against current code. Fix only still-valid issues, skip the
rest with a brief reason, keep changes minimal, and validate.

Inline comments:
In `@cmd/netobserv-ebpf-agent.go`:
- Line 16: The import statement at line 16 of cmd/netobserv-ebpf-agent.go is
importing from the external flowlogs-pipeline repository, but the local
pkg/server package should be used instead for consistency with how it is
imported in pkg/prometheus/prom_server.go. Replace the external import path
"github.com/netobserv/flowlogs-pipeline/pkg/server" with the local package
import path to ensure the codebase uses the local source consistently and avoids
divergence.
- Around line 49-53: The PProf listener is bypassing the MaxBytesHandler
body-size guard because the http.Server passed to server.Default() at line 52
has a nil Handler field. When Handler is nil, the MaxBytesHandler wrapping in
pkg/server/common.go:15 is skipped, and the DefaultServeMux (registered by the
net/http/pprof blank import) is used unprotected by ListenAndServe(). Explicitly
set the Handler field on the http.Server passed to server.Default() to
http.DefaultServeMux so that the MaxBytesHandler protection is applied to the
PProf endpoints.

In `@docs/profiling.md`:
- Around line 22-24: The fenced code block containing the kubectl port-forward
command is missing a language declaration, which violates the MD040 markdown
linting rule. Add "bash" after the opening triple backticks (```) on line 22 to
specify that the code block contains bash code, changing it from triple
backticks with no language to triple backticks followed by "bash".

In `@pkg/prometheus/prom_server.go`:
- Line 53: The explicit MinVersion set to tls.VersionTLS12 at line 41 prevents
server.Default from enforcing TLS 1.3 when called at line 53, as server.Default
only applies TLS 1.3 when MinVersion is unset. Either remove the explicit TLS
1.2 configuration entirely to allow server.Default to apply TLS 1.3, or upgrade
the MinVersion to tls.VersionTLS13 to match the intended security baseline used
elsewhere in the codebase.

In `@pkg/server/common.go`:
- Line 1: The Go file in pkg/server/common.go is missing the required Apache v2
license header at the beginning. Add the standard Apache v2 license header
comment block before the `package server` declaration to comply with the coding
guidelines for Go files.
- Around line 13-46: The `Default` function in pkg/server/common.go lacks unit
test coverage. Create a test file (pkg/server/common_test.go) using Go's
standard testing package with test cases that verify the `Default` function
correctly sets all default timeout values, MaxHeaderBytes, TLSConfig settings,
and disables HTTP/2. Include a test case that verifies the handler is wrapped
with http.MaxBytesHandler when srv.Handler is not nil, and another that confirms
the warning is logged when srv.Handler is nil. Ensure all conditional branches
in the `Default` function are covered by your tests.
🪄 Autofix (Beta)

Fix all unresolved CodeRabbit comments on this PR:

  • Push a commit to this branch (recommended)
  • Create a new PR with the fixes

ℹ️ Review info
⚙️ Run configuration

Configuration used: Path: .coderabbit.yaml

Review profile: CHILL

Plan: Pro

Run ID: d23fcb02-97a6-4dea-baef-b6da48cbd7a7

📥 Commits

Reviewing files that changed from the base of the PR and between ce5ed02 and 9eeca9f.

📒 Files selected for processing (6)
  • cmd/netobserv-ebpf-agent.go
  • docs/config.md
  • docs/profiling.md
  • pkg/config/config.go
  • pkg/prometheus/prom_server.go
  • pkg/server/common.go

Comment thread cmd/netobserv-ebpf-agent.go Outdated
Comment thread cmd/netobserv-ebpf-agent.go
Comment thread docs/profiling.md
Comment on lines 22 to 24
```
oc -n netobserv-privileged port-forward <netobserv-ebpf-agent pod name> 6060
kubectl -n netobserv-privileged port-forward <netobserv-ebpf-agent pod name> 6060
```

Copy link
Copy Markdown

Choose a reason for hiding this comment

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

📐 Maintainability & Code Quality | 🟡 Minor | ⚡ Quick win

Add a language to the fenced command block.

Line 22 should declare a language (e.g., bash) to satisfy MD040.

Suggested fix
-    ```
+    ```bash
     kubectl -n netobserv-privileged port-forward <netobserv-ebpf-agent pod name> 6060
     ```
📝 Committable suggestion

‼️ IMPORTANT
Carefully review the code before committing. Ensure that it accurately replaces the highlighted code, contains no missing lines, and has no issues with indentation. Thoroughly test & benchmark the code to ensure it meets the requirements.

Suggested change
```
oc -n netobserv-privileged port-forward <netobserv-ebpf-agent pod name> 6060
kubectl -n netobserv-privileged port-forward <netobserv-ebpf-agent pod name> 6060
```
🧰 Tools
🪛 markdownlint-cli2 (0.22.1)

[warning] 22-22: Fenced code blocks should have a language specified

(MD040, fenced-code-language)

🤖 Prompt for AI Agents
Verify each finding against current code. Fix only still-valid issues, skip the
rest with a brief reason, keep changes minimal, and validate.

In `@docs/profiling.md` around lines 22 - 24, The fenced code block containing the
kubectl port-forward command is missing a language declaration, which violates
the MD040 markdown linting rule. Add "bash" after the opening triple backticks
(```) on line 22 to specify that the code block contains bash code, changing it
from triple backticks with no language to triple backticks followed by "bash".

Source: Linters/SAST tools

}
httpServer.Handler = mux
httpServer = defaultServer(httpServer)
httpServer = server.Default(httpServer)

Copy link
Copy Markdown

Choose a reason for hiding this comment

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

🔒 Security & Privacy | 🟠 Major

🧩 Analysis chain

🏁 Script executed:

#!/bin/bash
# Verify TLS minimum versions on migrated server code paths.
rg -n --type=go 'MinVersion:\s*tls\.VersionTLS1[23]|server\.Default\(' \
  pkg/prometheus/prom_server.go pkg/server/common.go cmd/netobserv-ebpf-agent.go

Repository: netobserv/netobserv-ebpf-agent

Length of output: 402


🏁 Script executed:

# First, locate and examine the server.Default implementation
ast-grep outline pkg/server/common.go --view expanded

Repository: netobserv/netobserv-ebpf-agent

Length of output: 287


🏁 Script executed:

# Read the server.Default function to understand its behavior
cat -n pkg/server/common.go

Repository: netobserv/netobserv-ebpf-agent

Length of output: 1628


🏁 Script executed:

sed -n '35,60p' pkg/prometheus/prom_server.go

Repository: netobserv/netobserv-ebpf-agent

Length of output: 939


🏁 Script executed:

# Check how server.Default is used elsewhere - cmd/netobserv-ebpf-agent.go from initial search
sed -n '50,60p' cmd/netobserv-ebpf-agent.go

Repository: netobserv/netobserv-ebpf-agent

Length of output: 609


Remove explicit TLS 1.2 override or upgrade to TLS 1.3.

Line 41 sets MinVersion: tls.VersionTLS12, preventing server.Default at line 53 from enforcing TLS 1.3 (it only applies when MinVersion == 0). This weakens the intended security baseline—other servers in the codebase use server.Default without explicit TLS config and correctly get TLS 1.3. Either upgrade to TLS 1.3 or remove the override entirely.

Suggested fix
-		TLSConfig: &tls.Config{
-			MinVersion: tls.VersionTLS12,
-		},
+		TLSConfig: &tls.Config{
+			MinVersion: tls.VersionTLS13,
+		},
🤖 Prompt for AI Agents
Verify each finding against current code. Fix only still-valid issues, skip the
rest with a brief reason, keep changes minimal, and validate.

In `@pkg/prometheus/prom_server.go` at line 53, The explicit MinVersion set to
tls.VersionTLS12 at line 41 prevents server.Default from enforcing TLS 1.3 when
called at line 53, as server.Default only applies TLS 1.3 when MinVersion is
unset. Either remove the explicit TLS 1.2 configuration entirely to allow
server.Default to apply TLS 1.3, or upgrade the MinVersion to tls.VersionTLS13
to match the intended security baseline used elsewhere in the codebase.

Comment thread pkg/server/common.go
@@ -0,0 +1,46 @@
package server

Copy link
Copy Markdown

Choose a reason for hiding this comment

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

📐 Maintainability & Code Quality | 🟠 Major | ⚡ Quick win

Add Apache v2 license header to this new Go file.

Line 1 starts directly with package, so the required header is missing.

As per coding guidelines, **/*.go: Go code must use Apache v2 license headers.

🤖 Prompt for AI Agents
Verify each finding against current code. Fix only still-valid issues, skip the
rest with a brief reason, keep changes minimal, and validate.

In `@pkg/server/common.go` at line 1, The Go file in pkg/server/common.go is
missing the required Apache v2 license header at the beginning. Add the standard
Apache v2 license header comment block before the `package server` declaration
to comply with the coding guidelines for Go files.

Source: Coding guidelines

Comment thread pkg/server/common.go
Comment on lines +13 to +46
func Default(srv *http.Server) *http.Server {
// defaults taken from https://bruinsslot.jp/post/go-secure-webserver/ can be overriden by caller
if srv.Handler != nil {
// No more than 2MB body
srv.Handler = http.MaxBytesHandler(srv.Handler, 2<<20)
} else {
slog.Warnf("Handler not yet set on server while securing defaults. Make sure a MaxByte middleware is used.")
}
if srv.ReadTimeout == 0 {
srv.ReadTimeout = 10 * time.Second
}
if srv.ReadHeaderTimeout == 0 {
srv.ReadHeaderTimeout = 5 * time.Second
}
if srv.WriteTimeout == 0 {
srv.WriteTimeout = 10 * time.Second
}
if srv.IdleTimeout == 0 {
srv.IdleTimeout = 120 * time.Second
}
if srv.MaxHeaderBytes == 0 {
srv.MaxHeaderBytes = 1 << 20 // 1MB
}
if srv.TLSConfig == nil {
srv.TLSConfig = &tls.Config{}
}
if srv.TLSConfig.MinVersion == 0 {
srv.TLSConfig.MinVersion = tls.VersionTLS13
}
// Disable http/2
srv.TLSNextProto = make(map[string]func(*http.Server, *tls.Conn, http.Handler), 0)

return srv
}

Copy link
Copy Markdown

Choose a reason for hiding this comment

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

📐 Maintainability & Code Quality | 🟠 Major | ⚡ Quick win

Add unit tests for Default before merge.

This is new Go logic on a shared security path, but no test coverage is included in the provided PR files for defaults/middleware behavior.

As per coding guidelines, **/*.go: All new Go code must include unit test coverage using standard Go testing patterns.

🧰 Tools
🪛 ast-grep (0.44.0)

[warning] 36-36: MinVersionis missing from this TLS configuration. By default, TLS 1.2 is currently used as the minimum when acting as a client, and TLS 1.0 when acting as a server. General purpose web applications should default to TLS 1.3 with all other protocols disabled. Only where it is known that a web server must support legacy clients with unsupported an insecure browsers (such as Internet Explorer 10), it may be necessary to enable TLS 1.0 to provide support. AddMinVersion: tls.VersionTLS13' to the TLS configuration to bump the minimum version to TLS 1.3.
Context: tls.Config{}
Note: [CWE-327]: Use of a Broken or Risky Cryptographic Algorithm [OWASP A03:2017]: Sensitive Data Exposure [OWASP A02:2021]: Cryptographic Failures

(missing-ssl-minversion-go)

🤖 Prompt for AI Agents
Verify each finding against current code. Fix only still-valid issues, skip the
rest with a brief reason, keep changes minimal, and validate.

In `@pkg/server/common.go` around lines 13 - 46, The `Default` function in
pkg/server/common.go lacks unit test coverage. Create a test file
(pkg/server/common_test.go) using Go's standard testing package with test cases
that verify the `Default` function correctly sets all default timeout values,
MaxHeaderBytes, TLSConfig settings, and disables HTTP/2. Include a test case
that verifies the handler is wrapped with http.MaxBytesHandler when srv.Handler
is not nil, and another that confirms the warning is logged when srv.Handler is
nil. Ensure all conditional branches in the `Default` function are covered by
your tests.

Source: Coding guidelines

@openshift-ci

openshift-ci Bot commented Jun 23, 2026

Copy link
Copy Markdown

@jotak: The following test failed, say /retest to rerun all failed tests or /retest-required to rerun all mandatory failed tests:

Test name Commit Details Required Rerun command
ci/prow/qe-e2e-tests 9eeca9f link false /test qe-e2e-tests

Full PR test history. Your PR dashboard.

Details

Instructions for interacting with me using PR comments are available here. If you have questions or suggestions related to my behavior, please file an issue against the kubernetes-sigs/prow repository. I understand the commands that are listed here.

jpinsonneau
jpinsonneau previously approved these changes Jun 25, 2026
@openshift-ci

openshift-ci Bot commented Jun 25, 2026

Copy link
Copy Markdown

New changes are detected. LGTM label has been removed.

@openshift-ci

openshift-ci Bot commented Jun 25, 2026

Copy link
Copy Markdown

[APPROVALNOTIFIER] This PR is NOT APPROVED

This pull-request has been approved by:
Once this PR has been reviewed and has the lgtm label, please ask for approval from jpinsonneau. For more information see the Code Review Process.

The full list of commands accepted by this bot can be found here.

Details Needs approval from an approver in each of these files:

Approvers can indicate their approval by writing /approve in a comment
Approvers can cancel approval by writing /approve cancel in a comment

@jotak jotak merged commit cd2c2a1 into netobserv:main Jun 25, 2026
5 of 8 checks passed
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