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

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

Original Pull Request: https://github.com/netbirdio/netbird/pull/5510

State: closed
Merged: Yes


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.
**Original Pull Request:** https://github.com/netbirdio/netbird/pull/5510 **State:** closed **Merged:** Yes --- ## 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 -->
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#26039