@@ -17,12 +17,11 @@ import (
1717 "text/template"
1818 "time"
1919
20- "github.com/gbrlsnchs/jwt/v3"
21-
2220 "emperror.dev/errors"
2321 "github.com/acobaugh/osrelease"
2422 "github.com/apex/log"
2523 "github.com/creasty/defaults"
24+ "github.com/gbrlsnchs/jwt/v3"
2625 "golang.org/x/sys/unix"
2726 "gopkg.in/yaml.v2"
2827
@@ -129,9 +128,9 @@ type RemoteQueryConfiguration struct {
129128 // be less likely to cause performance issues on the Panel.
130129 BootServersPerPage int `default:"50" yaml:"boot_servers_per_page"`
131130
132- //When using services like Cloudflare Access to manage access to
133- //a specific system via an external authentication system,
134- //it is possible to add special headers to bypass authentication.
131+ //When using services like Cloudflare Access to manage access to
132+ //a specific system via an external authentication system,
133+ //it is possible to add special headers to bypass authentication.
135134 //The mentioned headers can be appended to queries sent from Wings to the panel.
136135 CustomHeaders map [string ]string `yaml:"custom_headers"`
137136}
@@ -187,11 +186,23 @@ type SystemConfiguration struct {
187186 Uid int `yaml:"uid"`
188187 Gid int `yaml:"gid"`
189188
190- // Passwd controls weather a passwd file is mounted in the container
191- // at /etc/passwd to resolve missing user issues
192- Passwd bool `json:"mount_passwd" yaml:"mount_passwd" default:"true"`
193- PasswdFile string `json:"passwd_file" yaml:"passwd_file" default:"/etc/pelican/passwd"`
194- } `yaml:"user"`
189+ // Passwd controls weather a passwd and group file is mounted in the container
190+ // at /etc/passwd to resolve missing user/group issues inside the container
191+ Passwd struct {
192+ Enable bool `json:"enable" yaml:"enable" default:"true"`
193+ Directory string `json:"directory" yaml:"directory" default:"/etc/pelican"`
194+ } `json:"passwd" yaml:"passwd"`
195+ } `json:"user" yaml:"user"`
196+
197+ // MachineID manages the mounting of a 'machine-id' file for containers as required for
198+ // some game servers. I.E. Hytale
199+ MachineID struct {
200+ // Enable controls if the machine-id file is generated and mounted into the server container
201+ // This is enabled by default
202+ Enable bool `json:"enable" yaml:"enable" default:"true"`
203+ // FilePath is the full path to the machine-id file that will be generated and mounted
204+ Directory string `json:"directory" yaml:"directory" default:"/etc/pelican/machine-id"`
205+ } `json:"machine_id" yaml:"machine_id"`
195206
196207 // The amount of time in seconds that can elapse before a server's disk space calculation is
197208 // considered stale and a re-check should occur. DANGER: setting this value too low can seriously
@@ -604,19 +615,6 @@ func ConfigureDirectories() error {
604615 return err
605616 }
606617
607- log .WithField ("filepath" , _config .System .User .PasswdFile ).Debug ("ensuring passwd file exists" )
608- if passwd , err := os .Create (_config .System .User .PasswdFile ); err != nil {
609- return err
610- } else {
611- // the WriteFile method returns an error if unsuccessful
612- 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 )
613- // handle this error
614- if err != nil {
615- // print it out
616- fmt .Println (err )
617- }
618- }
619-
620618 // There are a non-trivial number of users out there whose data directories are actually a
621619 // symlink to another location on the disk. If we do not resolve that final destination at this
622620 // point things will appear to work, but endless errors will be encountered when we try to
@@ -638,6 +636,11 @@ func ConfigureDirectories() error {
638636 return err
639637 }
640638
639+ log .WithField ("path" , _config .System .TmpDirectory ).Debug ("ensuring temporary data directory exists" )
640+ if err := os .MkdirAll (_config .System .TmpDirectory , 0o700 ); err != nil {
641+ return err
642+ }
643+
641644 log .WithField ("path" , _config .System .ArchiveDirectory ).Debug ("ensuring archive data directory exists" )
642645 if err := os .MkdirAll (_config .System .ArchiveDirectory , 0o700 ); err != nil {
643646 return err
@@ -648,9 +651,42 @@ func ConfigureDirectories() error {
648651 return err
649652 }
650653
654+ log .WithField ("path" , _config .System .User .Passwd .Directory ).Debug ("ensuring passwd directory exists" )
655+ if err := os .MkdirAll (_config .System .User .Passwd .Directory , 0o700 ); err != nil {
656+ return err
657+ }
658+
659+ log .WithField ("path" , _config .System .MachineID .Directory ).Debug ("ensuring machine-id directory exists" )
660+ if err := os .MkdirAll (_config .System .MachineID .Directory , 0o700 ); err != nil {
661+ return err
662+ }
651663 return nil
652664}
653665
666+ // ConfigurePasswd generates the passwd and group files to be used by
667+ // this looks cleaner than the previous way and is similar to pterodactyl
668+ func ConfigurePasswd () (err error ) {
669+ if ! _config .System .User .Passwd .Enable {
670+ return
671+ }
672+ log .WithField ("filepath" , filepath .Join (_config .System .User .Passwd .Directory , "passwd" )).
673+ Debug ("ensuring passwd file exists" )
674+ if err = os .WriteFile (filepath .Join (_config .System .User .Passwd .Directory , "passwd" ),
675+ []byte (fmt .Sprintf ("container:x:%d:%d::/home/container:/usr/sbin/nologin" ,
676+ _config .System .User .Uid , _config .System .User .Gid )), 0644 ); err != nil {
677+ return fmt .Errorf ("could not write passwd file: %w" , err )
678+ }
679+
680+ log .WithField ("filepath" , filepath .Join (_config .System .User .Passwd .Directory , "group" )).
681+ Debug ("ensuring group file exists" )
682+ if err = os .WriteFile (filepath .Join (_config .System .User .Passwd .Directory , "group" ),
683+ []byte (fmt .Sprintf ("container:x:%d:container" ,
684+ _config .System .User .Gid )), 0644 ); err != nil {
685+ return fmt .Errorf ("could not write group file: %w" , err )
686+ }
687+ return
688+ }
689+
654690// EnableLogRotation writes a logrotate file for wings to the system logrotate
655691// configuration directory if one exists and a logrotate file is not found. This
656692// allows us to basically automate away the log rotation for most installs, but
0 commit comments