snapd sets the environment variable
$SNAP_USER_DATA when a command is executed.
$SNAP_USER_DATA is something like
/home/<user>/snap/<snap-name>/<snap-revision>, a path that’s writable by the snap. This works in most of the cases, except in go.
The recommended way to get the user home in go is something like:
usr, _ := user.Current() fmt.Fprintf(usr.HomeDir)
The implementation of the
Current method sets HomeDir by reading and parsing
/etc/passwd, which will point to
/home/<user>, totally ignoring our patched
Should we also present the snap with a patched version of /etc/passwd? or is there a better solution for go snaps accessing the home dir?