No password: Use `*` instead of `!`. (#6668)

This commit is contained in:
Chris Gunn 2023-11-05 18:05:43 -08:00 коммит произвёл GitHub
Родитель ef627c4380
Коммит e363b43969
Не найден ключ, соответствующий данной подписи
Идентификатор ключа GPG: 4AEE18F83AFDEB23
2 изменённых файлов: 11 добавлений и 5 удалений

Просмотреть файл

@ -93,8 +93,14 @@ func UpdateUserPassword(installRoot, username, hashedPassword string) error {
shadowFilePath := filepath.Join(installRoot, ShadowFile)
if hashedPassword == "" {
// In the /etc/shadow file, `!` means there is no password and password login is disabled.
hashedPassword = "!"
// In the /etc/shadow file, the values `*` and `!` both mean the user's password login is disabled but the user
// may login using other means (e.g. ssh, auto-login, etc.). This interpretation is also used by PAM. When sshd
// has `UsePAM` set to `yes`, then sshd defers to PAM the decision on whether or not the user is disabled.
// However, when `UsePAM` is set to `no`, then sshd must make this interpretation for itself. And the Mariner
// build of sshd is configured to interpret the `!` in the shadow file to mean the user is fully disabled, even
// for ssh login. But it interprets `*` to mean that only password login is disabled but sshd public/private key
// login is fine.
hashedPassword = "*"
}
// Find the line that starts with "<user>:<password>:..."

Просмотреть файл

@ -80,20 +80,20 @@ func TestHashPasswordNotEmpty(t *testing.T) {
}
func TestUpdateUserPasswordEmptyToEmpty(t *testing.T) {
testUpdateUserPassword(t, "root:!:19634:7:99999:7:::", "root:!:19634:7:99999:7:::", "root", "")
testUpdateUserPassword(t, "root:*:19634:7:99999:7:::", "root:*:19634:7:99999:7:::", "root", "")
}
func TestUpdateUserPasswordSomethingToEmpty(t *testing.T) {
testUpdateUserPassword(t,
"root:$6$E0M9VkDvOLvO$nr9FjmIiSSP5C5V3Lhuqv4VzWmscABoiQ0mF.ZTbwKEN4nS60nsiU17qA/RGMbXHtJfci/DeLT1Zu2nhNFbwQ.:19634:7:99999:7:::",
"root:!:19634:7:99999:7:::",
"root:*:19634:7:99999:7:::",
"root",
"")
}
func TestUpdateUserPassword(t *testing.T) {
testUpdateUserPassword(t,
"root:!:19634:7:99999:7:::",
"root:*:19634:7:99999:7:::",
"root:$6$E0M9VkDvOLvO$nr9FjmIiSSP5C5V3Lhuqv4VzWmscABoiQ0mF.ZTbwKEN4nS60nsiU17qA/RGMbXHtJfci/DeLT1Zu2nhNFbwQ.:19634:7:99999:7:::",
"root",
"$6$E0M9VkDvOLvO$nr9FjmIiSSP5C5V3Lhuqv4VzWmscABoiQ0mF.ZTbwKEN4nS60nsiU17qA/RGMbXHtJfci/DeLT1Zu2nhNFbwQ.")