mirror of
https://gitlab.alpinelinux.org/alpine/cloud/tiny-cloud.git
synced 2025-12-15 11:22:43 +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:
parent
115dafdfa0
commit
8303a4a3f2
@ -201,6 +201,10 @@ init__set_default_interfaces() {
|
|||||||
|
|
||||||
init__create_default_user() {
|
init__create_default_user() {
|
||||||
local user="$CLOUD_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
|
# don't do anything if it already exists
|
||||||
if getent passwd "$user" >/dev/null; then
|
if getent passwd "$user" >/dev/null; then
|
||||||
log -i -t "$phase" info "$ACTION: already exists"
|
log -i -t "$phase" info "$ACTION: already exists"
|
||||||
|
|||||||
@ -24,6 +24,13 @@ init__userdata_user() {
|
|||||||
return
|
return
|
||||||
fi
|
fi
|
||||||
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}"
|
CLOUD_USER="${name:-$CLOUD_USER}"
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|||||||
@ -15,6 +15,7 @@ init_tests \
|
|||||||
userdata_user_name \
|
userdata_user_name \
|
||||||
userdata_user_missing_name \
|
userdata_user_missing_name \
|
||||||
userdata_create_default_user \
|
userdata_create_default_user \
|
||||||
|
userdata_no_default_user \
|
||||||
userdata_ssh_authorized_keys \
|
userdata_ssh_authorized_keys \
|
||||||
userdata_groups \
|
userdata_groups \
|
||||||
userdata_bootcmd \
|
userdata_bootcmd \
|
||||||
@ -136,6 +137,18 @@ userdata_create_default_user_body() {
|
|||||||
tiny-cloud main
|
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() {
|
userdata_ssh_authorized_keys_body() {
|
||||||
fake_bin getent <<-EOF
|
fake_bin getent <<-EOF
|
||||||
#!/bin/sh
|
#!/bin/sh
|
||||||
|
|||||||
Loading…
x
Reference in New Issue
Block a user