Skip to content

getting started changes for l4 proxy#5783

Closed
crn4 wants to merge 1 commit intomainfrom
fix/getting-started
Closed

getting started changes for l4 proxy#5783
crn4 wants to merge 1 commit intomainfrom
fix/getting-started

Conversation

@crn4
Copy link
Copy Markdown
Contributor

@crn4 crn4 commented Apr 2, 2026

Describe your changes

Issue ticket number and link

Stack

Checklist

  • Is it a bug fix
  • Is a typo/documentation fix
  • Is a feature enhancement
  • It is a refactor
  • Created tests that fail without the change (if possible)

By submitting this pull request, you confirm that you have read and agree to the terms of the Contributor License Agreement.

Documentation

Select exactly one:

  • I added/updated documentation for this change
  • Documentation is not needed for this change (explain why)

minor fix

Docs PR URL (required if "docs added" is checked)

Paste the PR link from https://github.com/netbirdio/docs here:

https://github.com/netbirdio/docs/pull/__

Summary by CodeRabbit

  • Chores
    • Updated optional proxy service networking configuration during setup.
    • Modified proxy management port mapping to activate conditionally when proxy is enabled.
    • Adjusted proxy service network connectivity approach for compatibility with Traefik mode.

Copilot AI review requested due to automatic review settings April 2, 2026 17:38
@coderabbitai
Copy link
Copy Markdown
Contributor

coderabbitai Bot commented Apr 2, 2026

📝 Walkthrough

Walkthrough

The proxy service in the Docker Compose configuration was modified to use host networking (network_mode: host) instead of joining the internal netbird Docker network. The management backend address in the proxy environment configuration was updated from the Docker service name to a localhost address with a dynamic port. A conditional port mapping for the management HTTP port was added when the proxy is enabled.

Changes

Cohort / File(s) Summary
Proxy Network Configuration
infrastructure_files/getting-started.sh
Modified proxy service to use host networking mode instead of internal network, updated management backend address from Docker service name (http://netbird-server:80) to localhost with dynamic port (http://localhost:$MANAGEMENT_HOST_PORT), added conditional port mapping for management HTTP port when ENABLE_PROXY is true, and updated inline comments to reflect host-network operation.

Estimated code review effort

🎯 2 (Simple) | ⏱️ ~10 minutes

Possibly related PRs

  • netbirdio/netbird#5100: Directly overlaps with docker-compose generation and management backend address changes, switching proxy to host network and using localhost address.
  • netbirdio/netbird#5365: Modifies proxy infrastructure rendering in the same file, affecting docker-compose proxy service and proxy.env configuration.
  • netbirdio/netbird#5573: Updates render\_proxy\_env logic in the same file with related proxy configuration changes.

Suggested reviewers

  • mlsmaycon
  • braginini
  • shuuri-labs

Poem

🐰 The proxy hops to the host network bright,
No Docker walls to block its sight,
Localhost ports dance in the dawn,
Configuration complete, the proxy moves on! ✨

🚥 Pre-merge checks | ✅ 1 | ❌ 2

❌ Failed checks (2 warnings)

Check name Status Explanation Resolution
Docstring Coverage ⚠️ Warning Docstring coverage is 50.00% which is insufficient. The required threshold is 80.00%. Write docstrings for the functions missing them to satisfy the coverage threshold.
Description check ⚠️ Warning The PR description is mostly empty with key sections unfilled. While the template structure is followed and documentation needs are addressed, the 'Describe your changes', 'Issue ticket number and link', and 'Stack' sections are blank. Complete the 'Describe your changes' section with details about the Docker networking changes, proxy configuration updates, and management backend address modifications. Add the relevant issue ticket number and link, and clarify the technical justification for these infrastructure changes.
✅ Passed checks (1 passed)
Check name Status Explanation
Title check ✅ Passed The title accurately describes the main change: modifying the getting-started.sh script to support L4 proxy configuration with host networking.

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

✨ Finishing Touches
📝 Generate docstrings
  • Create stacked PR
  • Commit on current branch
🧪 Generate unit tests (beta)
  • Create PR with unit tests
  • Commit unit tests in branch fix/getting-started

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.

@sonarqubecloud
Copy link
Copy Markdown

sonarqubecloud Bot commented Apr 2, 2026

Copy link
Copy Markdown
Contributor

Copilot AI left a comment

Choose a reason for hiding this comment

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

Pull request overview

Updates the getting-started.sh generator to support an L4-oriented NetBird Proxy setup by moving the proxy to host networking and adjusting how it reaches the management service.

Changes:

  • Switch proxy container to network_mode: host to enable binding arbitrary TCP/UDP ports.
  • Conditionally publish the management service port on the host when the proxy is enabled.
  • Update proxy env to connect to management via localhost:$MANAGEMENT_HOST_PORT.

💡 Add Copilot custom instructions for smarter, more guided reviews. Learn how to get started.

Comment on lines 539 to 540
ports:
- 51820:51820/udp
Copy link

Copilot AI Apr 2, 2026

Choose a reason for hiding this comment

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

In the generated Compose YAML for proxy, the ports list item is not indented under ports: (it’s currently at the same indentation level). This produces invalid YAML when the proxy is enabled. Also, with network_mode: host, the ports: section is ignored by Docker Compose (and can be confusing). Fix by either removing ports: entirely for host networking, or indent the list correctly and drop network_mode: host if you intend to use port mappings.

Suggested change
ports:
- 51820:51820/udp

Copilot uses AI. Check for mistakes.
Comment on lines +535 to +542
# Uses host network so it can listen on arbitrary ports for TCP/UDP services
proxy:
image: $NETBIRD_PROXY_IMAGE
container_name: netbird-proxy
ports:
- 51820:51820/udp
restart: unless-stopped
networks: [netbird]
network_mode: host
Copy link

Copilot AI Apr 2, 2026

Choose a reason for hiding this comment

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

proxy is switched to network_mode: host, but Traefik is configured to use only the netbird Docker network (--providers.docker.network=netbird in this same renderer). A host-networked container won’t be on that network, so Traefik’s Docker provider won’t be able to route to it via the existing traefik.tcp.services.proxy-tls... labels. If the intent is to keep Traefik passthrough to the proxy, consider defining the proxy TCP service via the file provider (e.g., point to the host gateway/host IP + 8443) or keep the proxy on the netbird network instead of host networking.

Copilot uses AI. Check for mistakes.
networks: [netbird]
ports:
- '$NETBIRD_STUN_PORT:$NETBIRD_STUN_PORT/udp'
$(if [[ "$ENABLE_PROXY" == "true" ]]; then echo " - '$MANAGEMENT_HOST_PORT:80'"; fi)
Copy link

Copilot AI Apr 2, 2026

Choose a reason for hiding this comment

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

This adds a host port publish for the management service when the proxy is enabled ($MANAGEMENT_HOST_PORT:80). Because there’s no bind address, it will listen on all interfaces by default, exposing the management HTTP endpoint outside of Traefik/TLS. If this is only needed for the host-networked proxy to reach management, bind it to 127.0.0.1 (or reuse the existing bind-localhost logic) to avoid widening the attack surface, and consider updating any “open ports” instructions accordingly.

Suggested change
$(if [[ "$ENABLE_PROXY" == "true" ]]; then echo " - '$MANAGEMENT_HOST_PORT:80'"; fi)
$(if [[ "$ENABLE_PROXY" == "true" ]]; then echo " - '127.0.0.1:$MANAGEMENT_HOST_PORT:80'"; fi)

Copilot uses AI. Check for mistakes.
NB_PROXY_MANAGEMENT_ADDRESS=http://netbird-server:80
# Proxy runs in host network mode for L4 port binding, connect to management via localhost
NB_PROXY_MANAGEMENT_ADDRESS=http://localhost:$MANAGEMENT_HOST_PORT
# Allow insecure gRPC connection to management (required for internal Docker network)
Copy link

Copilot AI Apr 2, 2026

Choose a reason for hiding this comment

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

The comment on NB_PROXY_ALLOW_INSECURE is now misleading. This flag controls whether the proxy can send its auth token over a non-TLS gRPC connection; with NB_PROXY_MANAGEMENT_ADDRESS set to http://..., it’s required because the connection is plaintext, not specifically because it’s an “internal Docker network”. Update the comment to reflect the actual security implication (token over non-TLS) and when it’s safe to use (localhost-only).

Suggested change
# Allow insecure gRPC connection to management (required for internal Docker network)
# Allow sending proxy auth token over a non-TLS gRPC connection (safe only for localhost/plaintext)

Copilot uses AI. Check for mistakes.
Copy link
Copy Markdown
Contributor

@coderabbitai coderabbitai Bot left a comment

Choose a reason for hiding this comment

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

Actionable comments posted: 2

🤖 Prompt for all review comments with AI agents
Verify each finding against the current code and only fix it if needed.

Inline comments:
In `@infrastructure_files/getting-started.sh`:
- Around line 539-542: The docker-compose service configuration for the proxy
includes an incompatible ports mapping while using network_mode: host; remove
the ports block (the line(s) starting with "ports:" and the "- 51820:51820/udp"
mapping) from the proxy service so that only network_mode: host and restart:
unless-stopped remain—ensure no other port mappings exist for the proxy service
when using host networking.
- Line 650: Line uses a hard-coded all-interface port binding; change it to
prepend the bind address variable instead of leaving the host empty so it
respects BIND_LOCALHOST_ONLY (i.e., use bind_addr when building the host:port
mapping rather than just "$MANAGEMENT_HOST_PORT:80"). Call or compute
get_bind_address() here if bind_addr is not in scope, assign it to bind_addr,
and then use that variable in the port binding expression so this entry matches
the other bindings that use ${bind_addr}.
🪄 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: defaults

Review profile: CHILL

Plan: Pro

Run ID: e568cf9f-7a2e-4bbc-b474-4caf6df68d27

📥 Commits

Reviewing files that changed from the base of the PR and between 9d1a37c and e32ad68.

📒 Files selected for processing (1)
  • infrastructure_files/getting-started.sh

Comment on lines 539 to +542
ports:
- 51820:51820/udp
restart: unless-stopped
networks: [netbird]
network_mode: host
Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

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

⚠️ Potential issue | 🔴 Critical

🧩 Analysis chain

🏁 Script executed:

#!/bin/bash
# Verify proxy template mixes host networking with ports mapping (should not).
python - <<'PY'
from pathlib import Path
text = Path("infrastructure_files/getting-started.sh").read_text()
start = text.find("  proxy:")
end = text.find("    depends_on:", start)
block = text[start:end]
has_host = "network_mode: host" in block
has_ports = "\n    ports:" in block
print(f"has_host_network_mode={has_host}")
print(f"has_ports_block={has_ports}")
if has_host and has_ports:
    print("FAIL: proxy template contains both network_mode: host and ports.")
else:
    print("PASS")
PY

Repository: netbirdio/netbird

Length of output: 173


Remove ports from proxy when using host networking.

With network_mode: host, the ports block is incompatible and can cause Docker Compose startup to fail. When a service uses host networking, port mappings are not applicable.

Suggested fix
   proxy:
     image: $NETBIRD_PROXY_IMAGE
     container_name: netbird-proxy
-    ports:
-    - 51820:51820/udp
     restart: unless-stopped
     network_mode: host
📝 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
ports:
- 51820:51820/udp
restart: unless-stopped
networks: [netbird]
network_mode: host
restart: unless-stopped
network_mode: host
🤖 Prompt for AI Agents
Verify each finding against the current code and only fix it if needed.

In `@infrastructure_files/getting-started.sh` around lines 539 - 542, The
docker-compose service configuration for the proxy includes an incompatible
ports mapping while using network_mode: host; remove the ports block (the
line(s) starting with "ports:" and the "- 51820:51820/udp" mapping) from the
proxy service so that only network_mode: host and restart: unless-stopped
remain—ensure no other port mappings exist for the proxy service when using host
networking.

networks: [netbird]
ports:
- '$NETBIRD_STUN_PORT:$NETBIRD_STUN_PORT/udp'
$(if [[ "$ENABLE_PROXY" == "true" ]]; then echo " - '$MANAGEMENT_HOST_PORT:80'"; fi)
Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

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

⚠️ Potential issue | 🟠 Major

🧩 Analysis chain

🏁 Script executed:

# First, let's read the file around line 650 to understand the context
head -n 660 infrastructure_files/getting-started.sh | tail -n 20

Repository: netbirdio/netbird

Length of output: 953


🏁 Script executed:

# Find where MANAGEMENT_HOST_PORT is defined
rg "MANAGEMENT_HOST_PORT" infrastructure_files/getting-started.sh -B 2 -A 2

Repository: netbirdio/netbird

Length of output: 3498


🏁 Script executed:

# Find where ENABLE_PROXY is defined and used
rg "ENABLE_PROXY" infrastructure_files/getting-started.sh -B 2 -A 2

Repository: netbirdio/netbird

Length of output: 1721


🏁 Script executed:

# Search for proxy configuration in the file
rg -i "proxy" infrastructure_files/getting-started.sh -B 2 -A 2 | head -50

Repository: netbirdio/netbird

Length of output: 2120


🏁 Script executed:

# Find where bind_addr is defined and how it's used
rg "bind_addr" infrastructure_files/getting-started.sh -B 3 -A 3

Repository: netbirdio/netbird

Length of output: 2526


🏁 Script executed:

# Check if there are multiple port binding sections and how they differ
rg "ports:" infrastructure_files/getting-started.sh -B 2 -A 4 | head -60

Repository: netbirdio/netbird

Length of output: 1580


Fix port binding to respect BIND_LOCALHOST_ONLY configuration.

Line 650 bypasses the user's localhost-only preference by hard-coding all-interface binding. The script already includes get_bind_address() which respects the BIND_LOCALHOST_ONLY setting (configured during setup), but line 650 ignores it. Other port bindings in the same file correctly use ${bind_addr} to respect this preference. Update line 650 to be consistent:

Suggested fix
-$(if [[ "$ENABLE_PROXY" == "true" ]]; then echo "      - '$MANAGEMENT_HOST_PORT:80'"; fi)
+$(if [[ "$ENABLE_PROXY" == "true" ]]; then echo "      - '${bind_addr}:$MANAGEMENT_HOST_PORT:80'"; fi)

Note: bind_addr needs to be available in this context; if not, extract the get_bind_address() logic locally.

🤖 Prompt for AI Agents
Verify each finding against the current code and only fix it if needed.

In `@infrastructure_files/getting-started.sh` at line 650, Line uses a hard-coded
all-interface port binding; change it to prepend the bind address variable
instead of leaving the host empty so it respects BIND_LOCALHOST_ONLY (i.e., use
bind_addr when building the host:port mapping rather than just
"$MANAGEMENT_HOST_PORT:80"). Call or compute get_bind_address() here if
bind_addr is not in scope, assign it to bind_addr, and then use that variable in
the port binding expression so this entry matches the other bindings that use
${bind_addr}.

@crn4 crn4 closed this Apr 14, 2026
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