Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

resolve issues with missing user in containers #2

Merged
merged 2 commits into from
Apr 11, 2024
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
18 changes: 18 additions & 0 deletions config/config.go
Original file line number Diff line number Diff line change
Expand Up @@ -170,6 +170,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/pelican/passwd"`
} `yaml:"user"`

// The amount of time in seconds that can elapse before a server's disk space calculation is
Expand Down Expand Up @@ -530,6 +535,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 {
github-advanced-security[bot] marked this conversation as resolved.
Dismissed
Show resolved Hide resolved
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
Expand Down
10 changes: 10 additions & 0 deletions server/mounts.go
Original file line number Diff line number Diff line change
Expand Up @@ -29,6 +29,16 @@ func (s *Server) Mounts() []environment.Mount {
},
}

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()...)
}
Expand Down
Loading