[PR #5903] [MERGED] [client] Fix incorrect SSH client config combining Host and Match directives #27086

Open
opened 2026-08-05 07:08:11 -04:00 by saavagebueno · 0 comments
Owner

📋 Pull Request Information

Original PR: https://github.com/netbirdio/netbird/pull/5903
Author: @lixmal
Created: 4/16/2026
Status: Merged
Merged: 4/20/2026
Merged by: @lixmal

Base: mainHead: fix-ssh-config-match-host


📝 Commits (1)

  • c528be1 Use Match host+exec instead of Host+Match in SSH client config

📊 Changes

2 files changed (+43 additions, -13 deletions)

View changed files

📝 client/ssh/config/manager.go (+12 -13)
📝 client/ssh/config/manager_test.go (+31 -0)

📄 Description

Describe your changes

The generated 99-netbird.conf combined Host and Match exec incorrectly. Per ssh_config(5), a Host block ends at the next Host or Match keyword, so the Host line was a no-op: the Match exec block was unscoped, causing netbird ssh detect to run for every SSH connection, not just known peers.

  • Replace Host <peers> + Match exec with a single Match host "<peers>" exec "..." so SSH checks the host pattern first and only runs the detect command for known NetBird peers
  • Add test validating the Match host format

Closes #5901

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)

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

  • Bug Fixes

    • Enhanced SSH configuration generation to use improved directive formatting for host pattern matching.
  • Tests

    • Added test coverage to validate SSH configuration output format correctness.

🔄 This issue represents a GitHub Pull Request. It cannot be merged through Gitea due to API limitations.

## 📋 Pull Request Information **Original PR:** https://github.com/netbirdio/netbird/pull/5903 **Author:** [@lixmal](https://github.com/lixmal) **Created:** 4/16/2026 **Status:** ✅ Merged **Merged:** 4/20/2026 **Merged by:** [@lixmal](https://github.com/lixmal) **Base:** `main` ← **Head:** `fix-ssh-config-match-host` --- ### 📝 Commits (1) - [`c528be1`](https://github.com/netbirdio/netbird/commit/c528be101097f1e80786ba38ff50af5da097cb4b) Use Match host+exec instead of Host+Match in SSH client config ### 📊 Changes **2 files changed** (+43 additions, -13 deletions) <details> <summary>View changed files</summary> 📝 `client/ssh/config/manager.go` (+12 -13) 📝 `client/ssh/config/manager_test.go` (+31 -0) </details> ### 📄 Description ## Describe your changes The generated `99-netbird.conf` combined `Host` and `Match exec` incorrectly. Per `ssh_config(5)`, a `Host` block ends at the next `Host` or `Match` keyword, so the `Host` line was a no-op: the `Match exec` block was unscoped, causing `netbird ssh detect` to run for every SSH connection, not just known peers. - Replace `Host <peers>` + `Match exec` with a single `Match host "<peers>" exec "..."` so SSH checks the host pattern first and only runs the detect command for known NetBird peers - Add test validating the Match host format ## Issue ticket number and link Closes #5901 ## Stack <!-- branch-stack --> ### Checklist - [x] Is it a bug fix - [ ] Is a typo/documentation fix - [ ] Is a feature enhancement - [ ] It is a refactor - [x] 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](https://github.com/netbirdio/netbird/blob/main/CONTRIBUTOR_LICENSE_AGREEMENT.md). ## Documentation Select exactly one: - [ ] I added/updated documentation for this change - [x] Documentation is **not needed** for this change (explain why) ### 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/__ <!-- This is an auto-generated comment: release notes by coderabbit.ai --> ## Summary by CodeRabbit * **Bug Fixes** * Enhanced SSH configuration generation to use improved directive formatting for host pattern matching. * **Tests** * Added test coverage to validate SSH configuration output format correctness. <!-- end of auto-generated comment: release notes by coderabbit.ai --> --- <sub>🔄 This issue represents a GitHub Pull Request. It cannot be merged through Gitea due to API limitations.</sub>
saavagebueno added the pull-request label 2026-08-05 07:08:11 -04:00
Sign in to join this conversation.
No Label pull-request
1 Participants
Notifications
Due Date
No due date set.
Dependencies

No dependencies set.

Reference: DYNR/netbird#27086