1
0
mirror of https://gitlab.alpinelinux.org/alpine/cloud/tiny-cloud.git synced 2025-12-14 19:02:45 +03:00

Compare commits

...

6 Commits

Author SHA1 Message Date
Aleksandr Berkuta
2ee4edc6e5 Add tests for passwd and hashed_passwd user-data parameters 2025-11-30 18:46:42 +00:00
Aleksandr Berkuta
36eef1bb14 Add passwd parameter to user-data 2025-11-30 18:46:42 +00:00
Aleksandr Berkuta
e243abc2ab Undo auto-formatted space deletions 2025-11-30 18:46:42 +00:00
Aleksandr Berkuta
f84f2c090c fix: separate lock_passwd and hashed_passwd 2025-11-30 18:46:42 +00:00
Aleksandr Berkuta
5aece92a41 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-11-30 18:46:42 +00:00
3e886c87fb BugFix: user-data cloud-config handler user counter "i" overwrite 2025-08-18 19:22:08 +00:00
2 changed files with 52 additions and 8 deletions

View File

@ -75,6 +75,7 @@ set_ssh_authorized_keys_for() {
touch "$keys_file"
chmod 600 "$keys_file"
$MOCK chown -R "$user:$group" "$ssh_dir"
local i
for i in $sshkeys; do
local key="$(get_userdata $userdata_path/$i)"
if [ -n "$key" ]; then
@ -142,7 +143,7 @@ write_file() {
}
init__userdata_write_files() {
local files="$(get_userdata write_files)"
local i files="$(get_userdata write_files)"
for i in $files; do
local path="$(get_userdata write_files/$i/path)"
@ -204,7 +205,7 @@ init__userdata_package_upgrade() {
init__userdata_packages() {
local packages="$(get_userdata packages)"
local pkgs=
local i pkgs=
for i in $packages; do
pkgs="$pkgs $(get_userdata packages/$i)"
done
@ -214,7 +215,7 @@ init__userdata_packages() {
}
init__userdata_runcmd() {
local runcmds="$(get_userdata runcmd)"
local i runcmds="$(get_userdata runcmd)"
for i in $runcmds; do
local cmd="$(get_userdata runcmd/$i)"
sh -c "$cmd"
@ -222,7 +223,7 @@ init__userdata_runcmd() {
}
init__userdata_groups() {
local groups="$(get_userdata groups)"
local i groups="$(get_userdata groups)"
for i in $groups; do
local group="$(get_userdata groups/$i)"
$MOCK addgroup $group
@ -241,9 +242,9 @@ in_list() {
}
init__userdata_users() {
local users="$(get_userdata users)"
local i 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 +273,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 +290,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