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

Support disable the default user creation

Setting `users: []` should disable the creation of default user.

Setting `users: [default] should enable it.
This commit is contained in:
Natanael Copa 2024-07-31 16:15:59 +02:00
parent 115dafdfa0
commit 8303a4a3f2
3 changed files with 24 additions and 0 deletions

View File

@ -201,6 +201,10 @@ init__set_default_interfaces() {
init__create_default_user() {
local user="$CLOUD_USER"
if [ "$user" = "none" ] || [ -z "$user" ]; then
log -i -t "$phase" info "$ACTION: skip"
return
fi
# don't do anything if it already exists
if getent passwd "$user" >/dev/null; then
log -i -t "$phase" info "$ACTION: already exists"

View File

@ -24,6 +24,13 @@ init__userdata_user() {
return
fi
fi
if get_userdata | grep -q -x users; then
local default_user="$(get_userdata users/1)"
if [ "$default_user" != "default" ]; then
CLOUD_USER="$(get_userdata users/1/name)"
return 0
fi
fi
CLOUD_USER="${name:-$CLOUD_USER}"
}

View File

@ -15,6 +15,7 @@ init_tests \
userdata_user_name \
userdata_user_missing_name \
userdata_create_default_user \
userdata_no_default_user \
userdata_ssh_authorized_keys \
userdata_groups \
userdata_bootcmd \
@ -136,6 +137,18 @@ userdata_create_default_user_body() {
tiny-cloud main
}
userdata_no_default_user_body() {
fake_userdata_nocloud <<-EOF
#alpine-config
users: []
EOF
atf_check -e ignore -o ignore tiny-cloud early
atf_check \
-e match:"create_default_user: done" \
-o not-match:"adduser" \
tiny-cloud main
}
userdata_ssh_authorized_keys_body() {
fake_bin getent <<-EOF
#!/bin/sh