chore: shell out to getent to get user home directory#30
Open
kian99 wants to merge 1 commit intojuju:masterfrom
Open
chore: shell out to getent to get user home directory#30kian99 wants to merge 1 commit intojuju:masterfrom
kian99 wants to merge 1 commit intojuju:masterfrom
Conversation
On coporate laptops with authd, the user's account does not exist in /etc/passwd. Instead NSS (Name Server Switch) is used to contact an external service for auth details. Shell out to `get passwd <userID>` to get the user's home directory and fallback to reading /etc/passwd.
Author
|
Tests are failing with, |
| // falling back to reading /etc/passwd if the command fails. | ||
| // In some environments /etc/passwd may not be available or | ||
| // is not the source of truth (e.g., LDAP, NSS). | ||
| // And don't use os/user package as it requires CGO on Linux. |
Member
There was a problem hiding this comment.
That's not quite true.
For most Unix systems, this package has two internal implementations of resolving user and group ids to names, and listing supplementary group IDs. One is written in pure Go and parses /etc/passwd and /etc/group. The other is cgo-based and relies on the standard C library (libc) routines such as getpwuid_r, getgrnam_r, and getgrouplist.
Author
There was a problem hiding this comment.
Yes true, let me know if you want me to add add that clarification, in our case reading /etc/passwd is insufficient and the implementation we want relies on CGO
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
Add this suggestion to a batch that can be applied as a single commit.This suggestion is invalid because no changes were made to the code.Suggestions cannot be applied while the pull request is closed.Suggestions cannot be applied while viewing a subset of changes.Only one suggestion per line can be applied in a batch.Add this suggestion to a batch that can be applied as a single commit.Applying suggestions on deleted lines is not supported.You must change the existing code in this line in order to create a valid suggestion.Outdated suggestions cannot be applied.This suggestion has been applied or marked resolved.Suggestions cannot be applied from pending reviews.Suggestions cannot be applied on multi-line comments.Suggestions cannot be applied while the pull request is queued to merge.Suggestion cannot be applied right now. Please check back later.
I encountered the following error when running a Juju test that uses the Mongo suite.
mgo.go:566: failed to find HOME directory: UNIX user 1591302234 not foundThis only occured after switching to a Canonical corporate laptop. I was able to trace the issue down to how we determine the user's home directory in tests that spin up Mongo.
On coporate laptops with authd, the user's account does not exist in /etc/passwd. Instead NSS (Name Server Switch) is used to obtain the user's details. To fix the issue, shell out to
getent passwd <userID>to get the user's home directory and fallback to reading /etc/passwd in case the command execution fails.Some semi-related docs that helped explain the issue can be found here and here.