Skip to content

testing: fall back to getent passwd for LDAP users in getHome#37

Merged
iyiguncevik merged 1 commit intojuju:masterfrom
iyiguncevik:fix-home-dir
Mar 5, 2026
Merged

testing: fall back to getent passwd for LDAP users in getHome#37
iyiguncevik merged 1 commit intojuju:masterfrom
iyiguncevik:fix-home-dir

Conversation

@iyiguncevik
Copy link
Contributor

/etc/passwd only contains local users, so getHome would fail for users
authenticated via LDAP or other NSS backends. Fall back to running
'getent passwd ' when the user is not found in /etc/passwd, which
queries all configured NSS sources and handles LDAP transparently.

The common case (local user) retains the original fast file-read path.

/etc/passwd only contains local users, so getHome would fail for users
authenticated via LDAP or other NSS backends. Fall back to running
'getent passwd <uid>' when the user is not found in /etc/passwd, which
queries all configured NSS sources and handles LDAP transparently.

The common case (local user) retains the original fast file-read path.
Copy link
Member

@jameinel jameinel left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I know that @goldberl ran into this trying to run the Juju test suite on her corporate laptop, so thank you for putting this patch together.
I do wonder whether we would be better just always using the 'getent' path, since it can read home directly, but I suppose this is a graceful path towards that.
I also looked around a bit, and the only golang 'getent' parser that I found just shelled out to the cli command as well.

I think this is a good improvement, though I haven't tried to run this test suite directly.
I did confirm the outputs of getent passwd jameinel and getent passwd 1000 to make sure that was working correctly.

@iyiguncevik
Copy link
Contributor Author

Using only getent should also work in all cases. Running the command requires spawning an external process (exec.Command) on every call so it has slightly more overhead. As you mentioned this approach is a graceful path.

@iyiguncevik iyiguncevik merged commit 8a6082e into juju:master Mar 5, 2026
1 check failed
@iyiguncevik iyiguncevik deleted the fix-home-dir branch March 5, 2026 16:03
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.

2 participants