Skip to content

Additional relay support.#6724

Open
PizzaLovingNerd wants to merge 4 commits into
netbirdio:mainfrom
PizzaLovingNerd:additional-relays
Open

Additional relay support.#6724
PizzaLovingNerd wants to merge 4 commits into
netbirdio:mainfrom
PizzaLovingNerd:additional-relays

Conversation

@PizzaLovingNerd

@PizzaLovingNerd PizzaLovingNerd commented Jul 10, 2026

Copy link
Copy Markdown
Contributor

Describe your changes

Add server.additionalRelays support to the combined server so operators can
advertise external relay servers without disabling the embedded relay and STUN
service.

The automatically generated embedded relay address remains first in the relay
list, followed by the configured additional relay addresses. The existing
server.relays replacement behavior is unchanged and continues to take
precedence when configured.

This change also:

  • documents the new setting in combined/config.yaml.example;
  • verifies that the embedded relay and STUN service remain enabled;
  • verifies relay address ordering and shared-secret configuration;
  • verifies that the existing server.relays override behavior is preserved;
  • verifies YAML loading and local relay secret validation.

The focused unit tests, race detector, go vet, and golangci-lint pass. The
configuration was also tested end-to-end with a combined server, two external
relays, and independent NetBird peers, including active-relay failover.

Issue ticket number and link

Closes #5351

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)
  • This change does not modify the public API, gRPC protocols, functionality behavior, CLI / service flags, or introduce a new feature — OR I have discussed it with the NetBird team beforehand (link the issue / Slack thread in the description). See CONTRIBUTING.md.

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)

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

netbirdio/docs#847

Summary by CodeRabbit

  • New Features
    • Added support for advertising extra relays via additionalRelays while keeping the embedded/local relay enabled.
    • Client relay auto-configuration now includes the auto-detected local relay address followed by any configured additionalRelays.
  • Documentation
    • Clarified the difference between additionalRelays (augment) and relays (replace), including authSecret behavior and configuration examples.
  • Bug Fixes
    • Ensured relay configuration/validation requires the relay auth secret even when only additionalRelays are configured.
    • Confirmed that setting relays overrides additionalRelays (no augmentation).

Copilot AI review requested due to automatic review settings July 10, 2026 21:38
@coderabbitai

coderabbitai Bot commented Jul 10, 2026

Copy link
Copy Markdown
Contributor

Review Change Stack

No actionable comments were generated in the recent review. 🎉

ℹ️ Recent review info
⚙️ Run configuration

Configuration used: Path: .coderabbit.yaml

Review profile: CHILL

Plan: Pro

Run ID: 91bec86d-5047-43eb-ad62-108e80161b5f

📥 Commits

Reviewing files that changed from the base of the PR and between 3a902b9 and ae33fc2.

📒 Files selected for processing (1)
  • combined/cmd/config_test.go
🚧 Files skipped from review as they are similar to previous changes (1)
  • combined/cmd/config_test.go

📝 Walkthrough

Walkthrough

The combined server adds server.additionalRelays, appends those addresses to the auto-configured local relay, preserves local relay and STUN services, and documents and tests the distinction from server.relays.

Changes

Additional relay configuration

Layer / File(s) Summary
Relay configuration and default application
combined/cmd/config.go, combined/config.yaml.example
Adds server.additionalRelays, appends configured addresses after the local relay address, and documents how it differs from server.relays.
Relay behavior validation
combined/cmd/config_test.go
Tests local relay/STUN retention, relay overrides, secret validation, and YAML parsing of additional relay addresses.

Estimated code review effort: 3 (Moderate) | ~20 minutes

Sequence Diagram(s)

sequenceDiagram
  participant YAML as Server YAML
  participant LoadConfig
  participant ApplySimplifiedDefaults
  participant ManagementRelays
  YAML->>LoadConfig: Parse additionalRelays
  LoadConfig->>ApplySimplifiedDefaults: Apply relay defaults
  ApplySimplifiedDefaults->>ManagementRelays: Set local and additional relay addresses
Loading
🚥 Pre-merge checks | ✅ 5
✅ Passed checks (5 passed)
Check name Status Explanation
Title check ✅ Passed The title is concise and accurately reflects the main change: additional relay support.
Description check ✅ Passed The description fills the required template with changes, issue link, stack, checklist, and docs details.
Linked Issues check ✅ Passed The PR implements #5351 by adding additional relays while preserving the embedded relay and STUN service.
Out of Scope Changes check ✅ Passed The changes stay focused on relay config, docs, and tests, with no clear unrelated additions.
Docstring Coverage ✅ Passed No functions found in the changed files to evaluate docstring coverage. Skipping docstring coverage check.
✨ Finishing Touches
🧪 Generate unit tests (beta)
  • Create PR with unit tests

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.

Copilot AI left a comment

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.

Pull request overview

Adds support for server.additionalRelays in the combined server configuration so operators can advertise extra external relay endpoints while keeping the embedded relay (and embedded STUN) running.

Changes:

  • Introduces server.additionalRelays and appends its entries after the auto-generated local relay address in client relay settings.
  • Updates the combined server config example to document the new setting.
  • Adds focused unit tests to validate embedded relay/STUN behavior, relay ordering, override precedence, YAML loading, and authSecret validation.

Reviewed changes

Copilot reviewed 3 out of 3 changed files in this pull request and generated 3 comments.

File Description
combined/config.yaml.example Documents server.additionalRelays usage in the combined server example config.
combined/cmd/config.go Adds AdditionalRelays to ServerConfig and appends them to the advertised relay list when auto-configuring client settings.
combined/cmd/config_test.go Adds unit tests covering relay ordering, embedded relay/STUN enablement, override precedence, config loading, and validation.

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

Comment thread combined/cmd/config.go
Comment on lines +32 to 34
// - Relay: Runs locally by default; server.additionalRelays adds more relay
// addresses, while server.relays disables the local relay and replaces them
// - STUN: Runs locally on port 3478 by default; disabled if server.stuns is set
Comment on lines +11 to 13
# - Relay: Local by default; set 'additionalRelays' to advertise more relays,
# or set 'relays' to replace the local relay with external relays
# - STUN: Local on port 3478 by default; set 'stuns' to use external instead
Comment thread combined/config.yaml.example Outdated
@codecov

codecov Bot commented Jul 10, 2026

Copy link
Copy Markdown

Codecov Report

✅ All modified and coverable lines are covered by tests.
✅ Project coverage is 34.32%. Comparing base (e0c25ba) to head (ae33fc2).
⚠️ Report is 11 commits behind head on main.

Additional details and impacted files
@@            Coverage Diff             @@
##             main    #6724      +/-   ##
==========================================
+ Coverage   34.28%   34.32%   +0.03%     
==========================================
  Files         977      977              
  Lines      123295   123413     +118     
==========================================
+ Hits        42274    42362      +88     
- Misses      75793    75810      +17     
- Partials     5228     5241      +13     
Flag Coverage Δ
client 35.61% <ø> (+0.08%) ⬆️
management 29.33% <ø> (+0.03%) ⬆️
proxy 50.71% <ø> (-0.13%) ⬇️
relay 36.43% <ø> (ø)
signal 23.35% <ø> (ø)
unit 34.32% <ø> (+0.03%) ⬆️

Flags with carried forward coverage won't be shown. Click here to find out more.

☔ View full report in Codecov by Harness.
📢 Have feedback on the report? Share it here.

🚀 New features to boost your workflow:
  • ❄️ Test Analytics: Detect flaky tests, report on failures, and find test suite problems.
  • 📦 JS Bundle Analysis: Save yourself from yourself by tracking and limiting bundle sizes in JS merges.

Co-authored-by: Copilot Autofix powered by AI <175728472+Copilot@users.noreply.github.com>
@PizzaLovingNerd PizzaLovingNerd marked this pull request as ready for review July 11, 2026 00:31

@coderabbitai coderabbitai Bot left a comment

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.

🧹 Nitpick comments (1)
combined/cmd/config_test.go (1)

41-61: 📐 Maintainability & Code Quality | 🔵 Trivial | ⚡ Quick win

Consider adding a test for the interaction between additionalRelays and relays.addresses.

When both are set simultaneously, additionalRelays should be ignored. A test verifying this would guard against future regressions in the precedence logic.

💡 Suggested test
func TestAdditionalRelaysIgnoredWhenRelayOverride(t *testing.T) {
	cfg := DefaultConfig()
	cfg.Server.ExposedAddress = "https://netbird.example.com:443"
	cfg.Server.AuthSecret = "shared-relay-secret"
	cfg.Server.Relays = RelaysConfig{
		Addresses: []string{"rels://relay.example.com:443"},
		Secret:    "external-relay-secret",
	}
	cfg.Server.AdditionalRelays = []string{"rels://extra.example.com:443"}

	cfg.ApplySimplifiedDefaults()

	wantAddresses := []string{"rels://relay.example.com:443"}
	if !reflect.DeepEqual(cfg.Management.Relays.Addresses, wantAddresses) {
		t.Fatalf("relay addresses = %v, want %v (additionalRelays should be ignored)", cfg.Management.Relays.Addresses, wantAddresses)
	}
}
🤖 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 `@combined/cmd/config_test.go` around lines 41 - 61, Add a regression test
alongside TestApplySimplifiedDefaultsWithRelayOverride covering both
Server.Relays.Addresses and Server.AdditionalRelays. After
ApplySimplifiedDefaults, assert that Management.Relays.Addresses contains only
the explicitly configured relay addresses, confirming additionalRelays is
ignored when the relay override is present.
🤖 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.

Nitpick comments:
In `@combined/cmd/config_test.go`:
- Around line 41-61: Add a regression test alongside
TestApplySimplifiedDefaultsWithRelayOverride covering both
Server.Relays.Addresses and Server.AdditionalRelays. After
ApplySimplifiedDefaults, assert that Management.Relays.Addresses contains only
the explicitly configured relay addresses, confirming additionalRelays is
ignored when the relay override is present.

ℹ️ Review info
⚙️ Run configuration

Configuration used: Path: .coderabbit.yaml

Review profile: CHILL

Plan: Pro

Run ID: 94f2122a-9487-46fa-bb76-605dfb6a05d5

📥 Commits

Reviewing files that changed from the base of the PR and between 8e02154 and 0e46843.

📒 Files selected for processing (3)
  • combined/cmd/config.go
  • combined/cmd/config_test.go
  • combined/config.yaml.example

@CoderSufiyan CoderSufiyan left a comment

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.

Good feature. Before this, operators had to choose between local relay and external relays. Now they can have both. The three-way logic in autoConfigureClientSettings is clean: override takes priority, then additional relays augment the local relay, then fallback to local-only.

Tests cover all five states thoroughly. The YAML example doc is clear.

One minor suggestion: the reflect.DeepEqual assertions on slice order are fragile -- if order changes but semantics stay the same, these tests break. Consider ElementsMatch or Equal with sorting for the relay address assertions. Not a blocker.

LGTM.

@PizzaLovingNerd

Copy link
Copy Markdown
Contributor Author

@CoderSufiyan Thanks for the review, I implemented your suggestion

@sonarqubecloud

Copy link
Copy Markdown

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.

Combined server: server.relays disables built-in relay and STUN — no way to add additional relays

3 participants