testing: fall back to getent passwd for LDAP users in getHome#37
testing: fall back to getent passwd for LDAP users in getHome#37iyiguncevik merged 1 commit intojuju:masterfrom
Conversation
/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.
jameinel
left a comment
There was a problem hiding this comment.
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.
|
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. |
/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.