[PR #5510] [MERGED] [client] Fall back to getent/id for SSH user lookup in static builds #26031

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

📋 Pull Request Information

Original PR: https://github.com/netbirdio/netbird/pull/5510
Author: @lixmal
Created: 3/5/2026
Status: Merged
Merged: 3/13/2026
Merged by: @lixmal

Base: mainHead: fix/ssh-nss-user-lookup


📝 Commits (1)

  • 9c9483b Fall back to getent/id for SSH user lookup in static builds

📊 Changes

9 files changed (+848 additions, -18 deletions)

View changed files

client/ssh/server/getent_cgo_unix.go (+24 -0)
client/ssh/server/getent_nocgo_unix.go (+74 -0)
client/ssh/server/getent_test.go (+172 -0)
client/ssh/server/getent_unix.go (+122 -0)
client/ssh/server/getent_unix_test.go (+410 -0)
client/ssh/server/getent_windows.go (+26 -0)
📝 client/ssh/server/shell.go (+7 -3)
📝 client/ssh/server/user_utils.go (+2 -2)
📝 client/ssh/server/userswitching_unix.go (+11 -13)

📄 Description

Describe your changes

When CGO is disabled (CGO_ENABLED=0), Go's os/user only reads /etc/passwd and /etc/group directly, bypassing the system's NSS stack. This means users provided by SSSD, LDAP, Active Directory, or other NSS modules can't be resolved.

This adds getent passwd / id -G fallback for user lookup, group resolution, and shell detection. These commands go through the host's NSS stack regardless of how the Go binary was built. The fallback is only compiled in non-CGO builds (or when osusergo tag is set), since libc handles NSS natively when CGO is enabled.

Closes #4919

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)

No user-facing API or configuration changes. Behavior is transparent.

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

  • New Features

    • More reliable user/group lookups with platform- and build-aware fallbacks, improved input validation, 5s command timeouts, and explicit Windows behavior for shell lookup.
    • Enhanced shell detection with ordered fallbacks: passwd, NSS/getent, SHELL env, then default.
  • Tests

    • Extensive cross-platform tests covering user lookup, group resolution, shell detection, parsing, validation, timeouts, and edge cases.

🔄 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/5510 **Author:** [@lixmal](https://github.com/lixmal) **Created:** 3/5/2026 **Status:** ✅ Merged **Merged:** 3/13/2026 **Merged by:** [@lixmal](https://github.com/lixmal) **Base:** `main` ← **Head:** `fix/ssh-nss-user-lookup` --- ### 📝 Commits (1) - [`9c9483b`](https://github.com/netbirdio/netbird/commit/9c9483b67997eb30c2b272ff9ab4f11cc13a2f10) Fall back to getent/id for SSH user lookup in static builds ### 📊 Changes **9 files changed** (+848 additions, -18 deletions) <details> <summary>View changed files</summary> ➕ `client/ssh/server/getent_cgo_unix.go` (+24 -0) ➕ `client/ssh/server/getent_nocgo_unix.go` (+74 -0) ➕ `client/ssh/server/getent_test.go` (+172 -0) ➕ `client/ssh/server/getent_unix.go` (+122 -0) ➕ `client/ssh/server/getent_unix_test.go` (+410 -0) ➕ `client/ssh/server/getent_windows.go` (+26 -0) 📝 `client/ssh/server/shell.go` (+7 -3) 📝 `client/ssh/server/user_utils.go` (+2 -2) 📝 `client/ssh/server/userswitching_unix.go` (+11 -13) </details> ### 📄 Description ## Describe your changes When CGO is disabled (`CGO_ENABLED=0`), Go's `os/user` only reads `/etc/passwd` and `/etc/group` directly, bypassing the system's NSS stack. This means users provided by SSSD, LDAP, Active Directory, or other NSS modules can't be resolved. This adds `getent passwd` / `id -G` fallback for user lookup, group resolution, and shell detection. These commands go through the host's NSS stack regardless of how the Go binary was built. The fallback is only compiled in non-CGO builds (or when `osusergo` tag is set), since libc handles NSS natively when CGO is enabled. ## Issue ticket number and link Closes #4919 ## 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) No user-facing API or configuration changes. Behavior is transparent. ### 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 * **New Features** * More reliable user/group lookups with platform- and build-aware fallbacks, improved input validation, 5s command timeouts, and explicit Windows behavior for shell lookup. * Enhanced shell detection with ordered fallbacks: passwd, NSS/getent, SHELL env, then default. * **Tests** * Extensive cross-platform tests covering user lookup, group resolution, shell detection, parsing, validation, timeouts, and edge cases. <!-- 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:06:48 -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#26031