1
0
mirror of https://gitlab.alpinelinux.org/alpine/cloud/tiny-cloud.git synced 2025-12-15 11:22:43 +03:00

Compare commits

...

5 Commits

Author SHA1 Message Date
Aleksandr Berkuta
8a9f895365 Add tests for passwd and hashed_passwd user-data parameters 2025-06-24 12:29:48 +00:00
Aleksandr Berkuta
6c377c76da Add passwd parameter to user-data 2025-06-24 12:29:48 +00:00
Aleksandr Berkuta
0dc24601b2 Undo auto-formatted space deletions 2025-06-24 12:29:48 +00:00
Aleksandr Berkuta
f52d0d6d2d fix: separate lock_passwd and hashed_passwd 2025-06-24 12:29:48 +00:00
Aleksandr Berkuta
18a4111b4c Add passwd_hash
Without password hash '$user:*' to `chpasswd -e` will result to
inability for user to login, or change password. So I've add parameter
passwd_hash for the user. Password hash could be generated via command
`openssl passwd -5 your_password`.
2025-06-24 12:29:48 +00:00
2 changed files with 46 additions and 3 deletions

View File

@ -243,7 +243,7 @@ in_list() {
init__userdata_users() {
local users="$(get_userdata users)"
for i in $users; do
local name="" gecos="" homedir="" shell="" primary_group="" groups=""
local name="" gecos="" homedir="" shell="" primary_group="" groups="" passwd="" hashed_passwd=""
local system=false no_create_home=false lock_passwd=true
local keys="$(get_userdata users/$i)"
if [ "$i" = 1 ] && [ "$keys" = "default" ]; then
@ -272,6 +272,10 @@ init__userdata_users() {
if in_list no_create_home $keys; then
no_create_home="$(get_userdata users/$i/no_create_home)"
fi
if in_list passwd $keys; then
passwd="$(get_userdata users/$i/passwd)"
echo "${user}:${passwd}" | $MOCK chpasswd -e
fi
if getent passwd "$user" >/dev/null; then
log -i -t "$phase" info "$ACTION: user $user already exists"
@ -285,12 +289,17 @@ init__userdata_users() {
$MOCK adduser -D ${gecos:+-g "$gecos"} ${homedir:+-h "$homedir"} ${shell:+-s "$shell"} ${primary_group:+-G "$primary_group"} ${system:+-S} ${no_create_home:+-H} "$name"
fi
if in_list hashed_passwd $keys; then
hashed_passwd="$(get_userdata users/$i/hashed_passwd)"
echo "${name}:${hashed_passwd}" | $MOCK chpasswd -e
fi
if in_list lock_passwd $keys; then
lock_passwd="$(get_userdata users/$i/lock_passwd)"
fi
if [ "$lock_passwd" != "false" ]; then
echo "$name:*" | $MOCK chpasswd -e
if [ "$lock_passwd" != "false" ] && [ -z "$hashed_passwd" ]; then
echo "${name}:*" | $MOCK chpasswd -e
fi
if in_list ssh_authorized_keys $keys; then

View File

@ -30,6 +30,8 @@ init_tests \
userdata_users_system \
userdata_users_no_create_home \
userdata_users_groups \
userdata_users_passwd \
userdata_users_hashed_passwd \
userdata_users_lock_passwd \
userdata_users_doas \
userdata_users_ssh_authorized_keys \
@ -384,6 +386,38 @@ userdata_users_groups_body() {
tiny-cloud main
}
userdata_users_passwd_body() {
# first specified user will replace default user
fake_userdata_nocloud <<-EOF
#alpine-config
users:
- none
- name: foo
passwd: $6$foosalt$QuhZ.r54aqCAn7mTnU4jBh9LPyuVQCa8.H0dZWCMYHVaNzsPX/heqKqI3EtnB6j.YLuaENmnlEHTiwu.iVVcG1
EOF
atf_check -e ignore -o ignore tiny-cloud early
atf_check \
-e match:"userdata_users: done" \
-o match:"chpasswd -e" \
tiny-cloud main
}
userdata_users_hashed_passwd_body() {
# first specified user will replace default user
fake_userdata_nocloud <<-EOF
#alpine-config
users:
- none
- name: foo
hashed_passwd: $6$foosalt$QuhZ.r54aqCAn7mTnU4jBh9LPyuVQCa8.H0dZWCMYHVaNzsPX/heqKqI3EtnB6j.YLuaENmnlEHTiwu.iVVcG1
EOF
atf_check -e ignore -o ignore tiny-cloud early
atf_check \
-e match:"userdata_users: done" \
-o match:"chpasswd -e" \
tiny-cloud main
}
userdata_users_lock_passwd_body() {
# first specified user will replace default user
fake_userdata_nocloud <<-EOF