Skip to content
Merged
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
26 changes: 23 additions & 3 deletions toolkit/tools/imagegen/installutils/installutils.go
Original file line number Diff line number Diff line change
Expand Up @@ -787,16 +787,28 @@ func addGroups(installChroot *safechroot.Chroot, groups []configuration.Group) (
}

func addUsers(installChroot *safechroot.Chroot, users []configuration.User) (err error) {
const (
squashErrors = false
)

rootUserAdded := false

for _, user := range users {
logger.Log.Infof("Adding user (%s)", user.Name)
ReportActionf("Adding user: %s", user.Name)

var homeDir string
var (
homeDir string
isRoot bool
)

homeDir, err = createUserWithPassword(installChroot, user)
homeDir, isRoot, err = createUserWithPassword(installChroot, user)
Comment thread
christopherco marked this conversation as resolved.
if err != nil {
return
}
if isRoot {
rootUserAdded = true
}

err = configureUserGroupMembership(installChroot, user)
if err != nil {
Expand All @@ -814,10 +826,17 @@ func addUsers(installChroot *safechroot.Chroot, users []configuration.User) (err
}
}

// If no root entry was specified in the config file, never expire the root password
if !rootUserAdded {
logger.Log.Debugf("No root user entry found in config file. Setting root password to never expire.")
err = installChroot.UnsafeRun(func() error {
Comment thread
christopherco marked this conversation as resolved.
return shell.ExecuteLive(squashErrors, "chage", "-M", "-1", "root")
})
}
return
}

func createUserWithPassword(installChroot *safechroot.Chroot, user configuration.User) (homeDir string, err error) {
func createUserWithPassword(installChroot *safechroot.Chroot, user configuration.User) (homeDir string, isRoot bool, err error) {
const (
squashErrors = false
rootHomeDir = "/root"
Expand Down Expand Up @@ -869,6 +888,7 @@ func createUserWithPassword(installChroot *safechroot.Chroot, user configuration

// Update shadow file
err = updateUserPassword(installChroot.RootDir(), user.Name, hashedPassword)
isRoot = true
} else {
homeDir = filepath.Join(userHomeDirPrefix, user.Name)

Expand Down