Avoid writing to /etc/passwd unless needed

Port #461 by mac-chaffee to v4 branch.
This commit is contained in:
Tim Hockin 2021-12-23 09:04:14 -08:00
parent 65a5bc7f90
commit c6c19dc61a
1 changed files with 5 additions and 0 deletions

View File

@ -29,6 +29,7 @@ import (
"os"
"os/exec"
"os/signal"
"os/user"
"path/filepath"
"strconv"
"strings"
@ -772,6 +773,10 @@ func handleError(log *logging.Logger, printUsage bool, format string, a ...inter
// Put the current UID/GID into /etc/passwd so SSH can look it up. This
// assumes that we have the permissions to write to it.
func addUser() error {
// Skip if the UID already exists. The Dockerfile already adds the default UID/GID.
if _, err := user.LookupId(strconv.Itoa(os.Getuid())); err == nil {
return nil
}
home := os.Getenv("HOME")
if home == "" {
cwd, err := os.Getwd()