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

Implement lock_passwd=false for user

This commit is contained in:
Natanael Copa 2024-07-31 22:18:28 +02:00
parent 4caf5eee18
commit 0faaee62a4
2 changed files with 27 additions and 1 deletions

View File

@ -269,8 +269,8 @@ in_list() {
init__userdata_users() {
local users="$(get_userdata users)"
local name gecos homedir shell
for i in $users; do
local name gecos homedir shell lock_passwd=true
local keys="$(get_userdata users/$i)"
if [ "$i" = 1 ] && [ "$keys" = "default" ]; then
continue
@ -295,6 +295,14 @@ init__userdata_users() {
$MOCK adduser -D ${gecos:+-g "$gecos"} ${homedir:+-h "$homedir"} ${shell:+-s "$shell"} "$name"
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
fi
if in_list ssh_authorized_keys $keys; then
set_ssh_authorized_keys_for "$name" users/$i/ssh_authorized_keys
fi

View File

@ -22,6 +22,7 @@ init_tests \
userdata_users_gecos \
userdata_users_homedir \
userdata_users_shell \
userdata_users_lock_passwd \
userdata_users_ssh_authorized_keys \
userdata_ssh_authorized_keys \
userdata_groups \
@ -180,6 +181,7 @@ userdata_users_default_name_only_body() {
atf_check \
-e match:"userdata_users: done" \
-o match:"adduser.*foo" \
-o match:"chpasswd -e" \
tiny-cloud main
}
@ -245,6 +247,22 @@ userdata_users_shell_body() {
tiny-cloud main
}
userdata_users_lock_passwd_body() {
# first specified user will replace default user
fake_userdata_nocloud <<-EOF
#alpine-config
users:
- none
- name: foo
lock_passwd: false
EOF
atf_check -e ignore -o ignore tiny-cloud early
atf_check \
-e match:"userdata_users: done" \
-o not-match:"chpasswd -e" \
tiny-cloud main
}
userdata_users_ssh_authorized_keys_body() {
fake_bin getent <<-EOF
#!/bin/sh