Merge pull request #462 from thockin/master

Avoid writing to /etc/passwd unless needed
This commit is contained in:
Kubernetes Prow Robot 2022-01-03 04:41:00 -08:00 committed by GitHub
commit eb822be2e5
No known key found for this signature in database
GPG Key ID: 4AEE18F83AFDEB23
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()