Skip to content

Commit 535adbc

Browse files
authored
Fix unintended password reset for existing users (#358)
<!-- Description: Please provide a summary of the changes and the motivation behind them. --> updates the addOrUpdateUser logic to avoid unintentionally clearing a pre-existing user's password when no new password is explicitly provided in the config. --- ### **Checklist** - [ ] Tests added/updated - [ ] Documentation updated (if needed) - [ ] Code conforms to style guidelines --------- Signed-off-by: Elaine Zhao <[email protected]>
1 parent 364f7ff commit 535adbc

File tree

1 file changed

+10
-4
lines changed

1 file changed

+10
-4
lines changed

toolkit/tools/pkg/imagecustomizerlib/customizeusers.go

Lines changed: 10 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -52,7 +52,11 @@ func addOrUpdateUser(user imagecustomizerapi.User, baseConfigPath string, imageC
5252
}
5353

5454
hashedPassword := ""
55+
shouldUpdatePassword := false
56+
5557
if user.Password != nil {
58+
shouldUpdatePassword = true
59+
5660
passwordIsFile := user.Password.Type == imagecustomizerapi.PasswordTypePlainTextFile ||
5761
user.Password.Type == imagecustomizerapi.PasswordTypeHashedFile
5862

@@ -92,10 +96,12 @@ func addOrUpdateUser(user imagecustomizerapi.User, baseConfigPath string, imageC
9296
user.HomeDirectory, user.Name)
9397
}
9498

95-
// Update the user's password.
96-
err = userutils.UpdateUserPassword(imageChroot.RootDir(), user.Name, hashedPassword)
97-
if err != nil {
98-
return err
99+
// Only update password if explicitly provided
100+
if shouldUpdatePassword {
101+
err = userutils.UpdateUserPassword(imageChroot.RootDir(), user.Name, hashedPassword)
102+
if err != nil {
103+
return err
104+
}
99105
}
100106
} else {
101107
var uidStr string

0 commit comments

Comments
 (0)