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

initContainer: Only remove password when needed #533

Closed
Closed
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
27 changes: 21 additions & 6 deletions src/cmd/initContainer.go
Original file line number Diff line number Diff line change
Expand Up @@ -348,6 +348,8 @@ func initContainerHelp(cmd *cobra.Command, args []string) {
func configureUsers(targetUserUid int,
targetUser, targetUserHome, targetUserShell string,
homeLink, targetUserExists bool) error {
var stdout strings.Builder

if homeLink {
if err := redirectPath("/home", "/var/home", true); err != nil {
return err
Expand Down Expand Up @@ -401,16 +403,29 @@ func configureUsers(targetUserUid int,
}
}

logrus.Debugf("Removing password for user %s", targetUser)
if err := shell.Run("passwd", nil, &stdout, nil, "--status", initContainerFlags.user); err != nil {
return fmt.Errorf("failed to check password status of user %s: %w", initContainerFlags.user, err)
}
userPasswordStatus := strings.Split(stdout.String(), " ")[1]
if userPasswordStatus != "NP" {
logrus.Debugf("Removing password for user %s", initContainerFlags.user)

if err := shell.Run("passwd", nil, nil, nil, "--delete", targetUser); err != nil {
return fmt.Errorf("failed to remove password for user %s", targetUser)
if err := shell.Run("passwd", nil, nil, nil, "--delete", initContainerFlags.user); err != nil {
return fmt.Errorf("failed to remove password for user %s", initContainerFlags.user)
}
}
stdout.Reset()

logrus.Debug("Removing password for user root")
if err := shell.Run("passwd", nil, &stdout, nil, "--status", "root"); err != nil {
return fmt.Errorf("failed to check password status of root: %w", err)
}
rootPasswordStatus := strings.Split(stdout.String(), " ")[1]
if rootPasswordStatus != "NP" {
logrus.Debug("Removing password for user root")

if err := shell.Run("passwd", nil, nil, nil, "--delete", "root"); err != nil {
return errors.New("failed to remove password for root")
if err := shell.Run("passwd", nil, nil, nil, "--delete", "root"); err != nil {
return errors.New("failed to remove password for root")
}
}

return nil
Expand Down