@@ -1351,21 +1351,31 @@ func verifyUserCreated(installRoot, username string) error {
13511351
13521352 // Check if user exists in passwd file
13531353 passwdCmd := fmt .Sprintf ("grep '^%s:' /etc/passwd" , username )
1354- output , err := shell .ExecCmd (passwdCmd , true , installRoot , nil )
1354+ // output, err := shell.ExecCmd(passwdCmd, true, installRoot, nil)
1355+ _ , err := shell .ExecCmd (passwdCmd , true , installRoot , nil )
13551356 if err != nil {
1356- log .Errorf ("User %s not found in passwd file: %v" , username , err )
1357- return fmt .Errorf ("user %s not found in passwd file: %w" , username , err )
1357+ // log.Errorf("User %s not found in passwd file: %v", username, err)
1358+ // return fmt.Errorf("user %s not found in passwd file: %w", username, err)
1359+ // Do not log command output or sensitive file contents
1360+ log .Errorf ("User %s not found in passwd file" , username )
1361+ return fmt .Errorf ("user %s not found in passwd file" , username )
13581362 }
1359- log .Debugf ("User in passwd: %s" , strings .TrimSpace (output ))
1363+ // log.Debugf("User in passwd: %s", strings.TrimSpace(output))
1364+ // User was found in passwd; avoid logging the line content to prevent leaking sensitive data
13601365
13611366 // Check if user has password in shadow file
13621367 shadowCmd := fmt .Sprintf ("grep '^%s:' /etc/shadow" , username )
1363- output , err = shell .ExecCmd (shadowCmd , true , installRoot , nil )
1368+ // output, err = shell.ExecCmd(shadowCmd, true, installRoot, nil)
1369+ _ , err = shell .ExecCmd (shadowCmd , true , installRoot , nil )
13641370 if err != nil {
1365- log .Errorf ("User %s not found in shadow file: %v" , username , err )
1366- return fmt .Errorf ("user %s not found in shadow file: %w" , username , err )
1371+ // log.Errorf("User %s not found in shadow file: %v", username, err)
1372+ // return fmt.Errorf("user %s not found in shadow file: %w", username, err)
1373+ // Do not log command output or sensitive file contents
1374+ log .Errorf ("User %s not found in shadow file" , username )
1375+ return fmt .Errorf ("user %s not found in shadow file" , username )
13671376 }
1368- log .Debugf ("User in shadow: %s" , strings .TrimSpace (output ))
1377+ // log.Debugf("User in shadow: %s", strings.TrimSpace(output))
1378+ // User was found in shadow; avoid logging the line content to prevent leaking sensitive data
13691379
13701380 return nil
13711381}
@@ -1508,8 +1518,10 @@ func setUserPassword(installRoot string, user config.UserConfig) error {
15081518 // Password is already hashed, use usermod to set it directly
15091519 usermodCmd := fmt .Sprintf ("usermod -p '%s' %s" , user .Password , user .Name )
15101520 if _ , err := shell .ExecCmd (usermodCmd , true , installRoot , nil ); err != nil {
1511- log .Errorf ("Failed to set hashed password for user %s: %v" , user .Name , err )
1512- return fmt .Errorf ("failed to set hashed password for user %s: %w" , user .Name , err )
1521+ // log.Errorf("Failed to set hashed password for user %s: %v", user.Name, err)
1522+ // return fmt.Errorf("failed to set hashed password for user %s: %w", user.Name, err)
1523+ log .Errorf ("Failed to set hashed password for user %s" , user .Name )
1524+ return fmt .Errorf ("failed to set hashed password for user %s" , user .Name )
15131525 }
15141526 } else {
15151527 // Password is plaintext, need to hash it first
@@ -1520,17 +1532,21 @@ func setUserPassword(installRoot string, user config.UserConfig) error {
15201532
15211533 usermodCmd := fmt .Sprintf ("usermod -p '%s' %s" , hashedPassword , user .Name )
15221534 if _ , err := shell .ExecCmd (usermodCmd , true , installRoot , nil ); err != nil {
1523- log .Errorf ("Failed to set hashed password for user %s: %v" , user .Name , err )
1524- return fmt .Errorf ("failed to set hashed password for user %s: %w" , user .Name , err )
1535+ // log.Errorf("Failed to set hashed password for user %s: %v", user.Name, err)
1536+ // return fmt.Errorf("failed to set hashed password for user %s: %w", user.Name, err)
1537+ log .Errorf ("Failed to set password for user %s" , user .Name )
1538+ return fmt .Errorf ("failed to set password for user %s" , user .Name )
15251539 }
15261540 }
15271541 } else {
15281542 // No hash algorithm specified, use interactive passwd command (legacy behavior)
15291543 passwdInput := fmt .Sprintf ("%s\n %s\n " , user .Password , user .Password )
15301544 passwdCmd := fmt .Sprintf ("passwd %s" , user .Name )
15311545 if _ , err := shell .ExecCmdWithInput (passwdInput , passwdCmd , true , installRoot , nil ); err != nil {
1532- log .Errorf ("Failed to set password for user %s: %v" , user .Name , err )
1533- return fmt .Errorf ("failed to set password for user %s: %w" , user .Name , err )
1546+ // log.Errorf("Failed to set password for user %s: %v", user.Name, err)
1547+ // return fmt.Errorf("failed to set password for user %s: %w", user.Name, err)
1548+ log .Errorf ("Failed to set password for user %s" , user .Name )
1549+ return fmt .Errorf ("failed to set password for user %s" , user .Name )
15341550 }
15351551 }
15361552
@@ -1562,7 +1578,8 @@ func hashPassword(password, hashAlgo, installRoot string) (string, error) {
15621578 log .Debugf ("Hashing password with algorithm %s" , hashAlgo )
15631579 output , err := shell .ExecCmd (cmd , true , installRoot , nil )
15641580 if err != nil {
1565- log .Errorf ("Failed to hash password with algorithm %s: %v" , hashAlgo , err )
1581+ // log.Errorf("Failed to hash password with algorithm %s: %v", hashAlgo, err)
1582+ log .Errorf ("Failed to hash password with algorithm %s" , hashAlgo )
15661583 return "" , fmt .Errorf ("failed to hash password with algorithm %s: %w" , hashAlgo , err )
15671584 }
15681585
@@ -1591,7 +1608,9 @@ func configUserStartupScript(installRoot string, user config.UserConfig) error {
15911608 passwdFile := filepath .Join (installRoot , "etc" , "passwd" )
15921609
15931610 if err := file .ReplaceRegexInFile (findPattern , replacePattern , passwdFile ); err != nil {
1594- log .Errorf ("Failed to update user %s startup command: %v" , user .Name , err )
1611+ // log.Errorf("Failed to update user %s startup command: %v", user.Name, err)
1612+ // Log only high-level context to avoid leaking potentially sensitive details from the underlying error.
1613+ log .Errorf ("Failed to update startup command for user %s" , user .Name )
15951614 return fmt .Errorf ("failed to update user %s startup command: %w" , user .Name , err )
15961615 }
15971616 return nil
0 commit comments