diff options
author | OpenShift Merge Robot <openshift-merge-robot@users.noreply.github.com> | 2020-07-15 14:03:14 -0400 |
---|---|---|
committer | GitHub <noreply@github.com> | 2020-07-15 14:03:14 -0400 |
commit | 38f73db9decd4f692e9cfc2fd4dde2251389fca7 (patch) | |
tree | 0f40a02bd24a10b51a0868875c9ab13afe712eaf /libpod/container_internal_linux.go | |
parent | 8704b78a6fbb953acb6b74d1671d5ad6456bf81f (diff) | |
parent | 1ad7042a34771ccaae2960decc93367fcf898dad (diff) | |
download | podman-38f73db9decd4f692e9cfc2fd4dde2251389fca7.tar.gz podman-38f73db9decd4f692e9cfc2fd4dde2251389fca7.tar.bz2 podman-38f73db9decd4f692e9cfc2fd4dde2251389fca7.zip |
Merge pull request #6977 from mheon/fix_6953
Preserve passwd on container restart
Diffstat (limited to 'libpod/container_internal_linux.go')
-rw-r--r-- | libpod/container_internal_linux.go | 13 |
1 files changed, 12 insertions, 1 deletions
diff --git a/libpod/container_internal_linux.go b/libpod/container_internal_linux.go index b2711745e..255505416 100644 --- a/libpod/container_internal_linux.go +++ b/libpod/container_internal_linux.go @@ -214,6 +214,9 @@ func (c *Container) getUserOverrides() *lookup.Overrides { } } } + if path, ok := c.state.BindMounts["/etc/passwd"]; ok { + overrides.ContainerEtcPasswdPath = path + } return &overrides } @@ -1513,6 +1516,14 @@ func (c *Container) generatePasswd() (string, error) { if !c.config.AddCurrentUserPasswdEntry && c.config.User == "" { return "", nil } + if MountExists(c.config.Spec.Mounts, "/etc/passwd") { + return "", nil + } + // Re-use passwd if possible + passwdPath := filepath.Join(c.config.StaticDir, "passwd") + if _, err := os.Stat(passwdPath); err == nil { + return passwdPath, nil + } pwd := "" if c.config.User != "" { entry, err := c.generateUserPasswdEntry() @@ -1536,7 +1547,7 @@ func (c *Container) generatePasswd() (string, error) { if err != nil && !os.IsNotExist(err) { return "", errors.Wrapf(err, "unable to read passwd file %s", originPasswdFile) } - passwdFile, err := c.writeStringToRundir("passwd", string(orig)+pwd) + passwdFile, err := c.writeStringToStaticDir("passwd", string(orig)+pwd) if err != nil { return "", errors.Wrapf(err, "failed to create temporary passwd file") } |