diff --git a/config/config.go b/config/config.go index 4c65bf74..7f2a5a15 100644 --- a/config/config.go +++ b/config/config.go @@ -168,6 +168,11 @@ type SystemConfiguration struct { Uid int `yaml:"uid"` Gid int `yaml:"gid"` + + // Passwd controls weather a passwd file is mounted in the container + // at /etc/passwd to resolve missing user issues + Passwd bool `json:"mount_passwd" yaml:"mount_passwd" default:"true"` + PasswdFile string `json:"passwd_file" yaml:"passwd_file" default:"/etc/pterodactyl/passwd"` } `yaml:"user"` // The amount of time in seconds that can elapse before a server's disk space calculation is @@ -526,6 +531,19 @@ func ConfigureDirectories() error { return err } + log.WithField("filepath", _config.System.User.PasswdFile).Debug("ensuring passwd file exists") + if passwd, err := os.Create(_config.System.User.PasswdFile); err != nil { + return err + } else { + // the WriteFile method returns an error if unsuccessful + err := os.WriteFile(passwd.Name(), []byte(fmt.Sprintf("container:x:%d:%d::/home/container:/usr/sbin/nologin", _config.System.User.Uid, _config.System.User.Gid)), 0644) + // handle this error + if err != nil { + // print it out + fmt.Println(err) + } + } + // There are a non-trivial number of users out there whose data directories are actually a // symlink to another location on the disk. If we do not resolve that final destination at this // point things will appear to work, but endless errors will be encountered when we try to diff --git a/server/mounts.go b/server/mounts.go index 97c80946..9d2d126f 100644 --- a/server/mounts.go +++ b/server/mounts.go @@ -29,6 +29,18 @@ func (s *Server) Mounts() []environment.Mount { }, } + // Mount passwd file if set to true + if config.Get().System.User.Passwd { + passwdMount := environment.Mount{ + Default: true, + Target: "/etc/passwd", + Source: config.Get().System.User.PasswdFile, + ReadOnly: true, + } + + m = append(m, passwdMount) + } + // Also include any of this server's custom mounts when returning them. return append(m, s.customMounts()...) }