controller: prevent duplicate tunnel pairs in rendered configs#3058
Merged
controller: prevent duplicate tunnel pairs in rendered configs#3058
Conversation
…onfigs User tunnels are GRE tunnels identified by (UnderlaySrcIP, UnderlayDstIP) pairs. In normal operation, the activator ensures each device gets unique tunnel pairs, but corrupted onchain state or bugs could create duplicates. If duplicate pairs exist when the controller renders device configs, the resulting configuration will contain conflicting GRE tunnel interface definitions, causing device configuration errors or undefined behavior. Add a defensive deduplication layer in GetConfig() that filters the tunnel list before rendering. When duplicates are detected: - Log an error with full context (device pubkey/code, tunnel IDs, user pubkeys, underlay IPs, VRF ID) - Increment controller_duplicate_tunnel_pairs_total Prometheus metric - Keep the first occurrence and remove subsequent duplicates - Continue rendering the rest of the config normally This fail-safe prevents bad configs from reaching devices even if upstream validation fails. The deduplication happens per-device at render time using a shallow device copy, so the cache remains faithful to onchain state while devices receive only valid configurations. Testing: Added 5 unit tests covering duplicate removal, first-occurrence selection, unallocated tunnel handling, empty lists, and end-to-end integration with GetConfig(). All existing tests pass.
nikw9944
approved these changes
Feb 20, 2026
nikw9944
pushed a commit
that referenced
this pull request
Feb 20, 2026
User tunnels are GRE tunnels identified by (UnderlaySrcIP, UnderlayDstIP) pairs. In normal operation, the activator ensures each device gets unique tunnel pairs, but corrupted onchain state or bugs could create duplicates. If duplicate pairs exist when the controller renders device configs, the resulting configuration will contain conflicting GRE tunnel interface definitions, causing device configuration errors or undefined behavior. ## Summary of Changes * Add a defensive deduplication layer in GetConfig() that filters the tunnel list before rendering. When duplicates are detected: * Log an error with full context (device pubkey/code, tunnel IDs, user pubkeys, underlay IPs, VRF ID) * Increment controller_duplicate_tunnel_pairs_total Prometheus metric * Keep the first occurrence and remove subsequent duplicates * Continue rendering the rest of the config normally This fail-safe prevents bad configs from reaching devices even if upstream validation fails. The deduplication happens per-device at render time using a shallow device copy, so the cache remains faithful to onchain state while devices receive only valid configurations. ## Testing Verification * Added 5 unit tests covering duplicate removal, first-occurrence selection, unallocated tunnel handling, empty lists, and end-to-end integration with GetConfig(). * All existing tests pass.
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
Add this suggestion to a batch that can be applied as a single commit.This suggestion is invalid because no changes were made to the code.Suggestions cannot be applied while the pull request is closed.Suggestions cannot be applied while viewing a subset of changes.Only one suggestion per line can be applied in a batch.Add this suggestion to a batch that can be applied as a single commit.Applying suggestions on deleted lines is not supported.You must change the existing code in this line in order to create a valid suggestion.Outdated suggestions cannot be applied.This suggestion has been applied or marked resolved.Suggestions cannot be applied from pending reviews.Suggestions cannot be applied on multi-line comments.Suggestions cannot be applied while the pull request is queued to merge.Suggestion cannot be applied right now. Please check back later.
User tunnels are GRE tunnels identified by (UnderlaySrcIP, UnderlayDstIP) pairs. In normal operation, the activator ensures each device gets unique tunnel pairs, but corrupted onchain state or bugs could create duplicates. If duplicate pairs exist when the controller renders device configs, the resulting configuration will contain conflicting GRE tunnel interface definitions, causing device configuration errors or undefined behavior.
Summary of Changes
This fail-safe prevents bad configs from reaching devices even if upstream validation fails. The deduplication happens per-device at render time using a shallow device copy, so the cache remains faithful to onchain state while devices receive only valid configurations.
Testing Verification