Skip to content

fix: disable probe and metrics endpoints by default#10

Draft
kvaps wants to merge 1 commit intomainfrom
fix/disable-default-bind-addresses
Draft

fix: disable probe and metrics endpoints by default#10
kvaps wants to merge 1 commit intomainfrom
fix/disable-default-bind-addresses

Conversation

@kvaps
Copy link
Copy Markdown
Member

@kvaps kvaps commented Apr 21, 2026

Summary

Change the defaults for --health-probe-bind-address and --metrics-bind-address from ":0" (bind to a random free port) to "0" (disabled), which is the controller-runtime convention for turning off the server.

Why

netstat on a node running cozy-proxy showed two unexpected high-port listeners:

tcp6  0  0 :::40267  :::*  LISTEN  109979/cozy-proxy
tcp6  0  0 :::33869  :::*  LISTEN  109979/cozy-proxy

Because the chart runs cozy-proxy with hostNetwork: true, those ports were exposed directly on the host. Users who want health probes or metrics can still opt in by passing an explicit bind address via flag.

Verified against controller-runtime v0.20.1:

  • Metrics (pkg/metrics/server/server.go): BindAddress == "0" skips server creation entirely.
  • Probe (pkg/manager/manager.go): addr == "" || addr == "0" returns a nil listener, so no probe server is started.
  • The previous ":0" value instead fell through to net.Listen("tcp", ":0"), which is exactly what produced the random high ports.

Test plan

  • Build and deploy; verify netstat -ltnp on the node shows no cozy-proxy listeners
  • Pass --health-probe-bind-address=:8081 and confirm the probe endpoint comes up on that port
  • Pass --metrics-bind-address=:8080 and confirm metrics are served

Fixes #5

The default values for --health-probe-bind-address and --metrics-bind-address
were ":0", which in controller-runtime means "bind to a random free port"
rather than "disabled". Because the chart runs cozy-proxy with hostNetwork=true,
these showed up as two unexpected high-port listeners on the host. Switch the
defaults to "0", the controller-runtime convention for disabling the server.
Users who want health probes or metrics can pass an explicit bind address.

Refs: #5

Co-Authored-By: Claude <noreply@anthropic.com>
Signed-off-by: Andrei Kvapil <kvapss@gmail.com>
@coderabbitai
Copy link
Copy Markdown

coderabbitai Bot commented Apr 21, 2026

Important

Review skipped

Draft detected.

Please check the settings in the CodeRabbit UI or the .coderabbit.yaml file in this repository. To trigger a single review, invoke the @coderabbitai review command.

⚙️ Run configuration

Configuration used: defaults

Review profile: CHILL

Plan: Pro

Run ID: d1887629-871f-4944-8914-58754c68e2cf

You can disable this status message by setting the reviews.review_status to false in the CodeRabbit configuration file.

Use the checkbox below for a quick retry:

  • 🔍 Trigger review
✨ Finishing Touches
🧪 Generate unit tests (beta)
  • Create PR with unit tests
  • Commit unit tests in branch fix/disable-default-bind-addresses

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 and usage tips.

Copy link
Copy Markdown

@gemini-code-assist gemini-code-assist Bot left a comment

Choose a reason for hiding this comment

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

Code Review

This pull request updates the default bind addresses for the health probe and metrics endpoints to "0", allowing them to be disabled. The review feedback suggests improving the help text by providing example address formats and ensuring consistent pluralization for the metrics endpoint description.

Comment thread main.go
var metricsAddr string
flag.StringVar(&probeAddr, "health-probe-bind-address", ":0", "The address the probe endpoint binds to.")
flag.StringVar(&metricsAddr, "metrics-bind-address", ":0", "The address the metric endpoint binds to.")
flag.StringVar(&probeAddr, "health-probe-bind-address", "0", "The address the probe endpoint binds to. Set to \"0\" to disable.")
Copy link
Copy Markdown

Choose a reason for hiding this comment

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

medium

Consider adding an example of the expected address format (e.g., :8081) to the help text. Since the default is now the special value "0", providing an example helps users understand that they should provide a :port string to enable the endpoint.

Suggested change
flag.StringVar(&probeAddr, "health-probe-bind-address", "0", "The address the probe endpoint binds to. Set to \"0\" to disable.")
flag.StringVar(&probeAddr, "health-probe-bind-address", "0", "The address the probe endpoint binds to (e.g., :8081). Set to \"0\" to disable.")

Comment thread main.go
flag.StringVar(&probeAddr, "health-probe-bind-address", ":0", "The address the probe endpoint binds to.")
flag.StringVar(&metricsAddr, "metrics-bind-address", ":0", "The address the metric endpoint binds to.")
flag.StringVar(&probeAddr, "health-probe-bind-address", "0", "The address the probe endpoint binds to. Set to \"0\" to disable.")
flag.StringVar(&metricsAddr, "metrics-bind-address", "0", "The address the metric endpoint binds to. Set to \"0\" to disable.")
Copy link
Copy Markdown

Choose a reason for hiding this comment

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

medium

Consider adding an example of the expected address format (e.g., :8080) and using the plural 'metrics' in the help text to maintain consistency with the flag name (--metrics-bind-address).

Suggested change
flag.StringVar(&metricsAddr, "metrics-bind-address", "0", "The address the metric endpoint binds to. Set to \"0\" to disable.")
flag.StringVar(&metricsAddr, "metrics-bind-address", "0", "The address the metrics endpoint binds to (e.g., :8080). Set to \"0\" to disable.")

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.

Cozy proxy listens on a couple of high ports with no apparent need

1 participant