From c6c19dc61a6bf8cf9ea5508c664cffe089273fc6 Mon Sep 17 00:00:00 2001 From: Tim Hockin Date: Thu, 23 Dec 2021 09:04:14 -0800 Subject: [PATCH] Avoid writing to /etc/passwd unless needed Port #461 by mac-chaffee to v4 branch. --- cmd/git-sync/main.go | 5 +++++ 1 file changed, 5 insertions(+) diff --git a/cmd/git-sync/main.go b/cmd/git-sync/main.go index 498d02f..2327081 100644 --- a/cmd/git-sync/main.go +++ b/cmd/git-sync/main.go @@ -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()