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

Implement doas for users

Add config line for doas under user creation
This commit is contained in:
Natanael Copa 2024-07-31 23:21:22 +02:00
parent e791e0494d
commit 34681ae220
2 changed files with 36 additions and 0 deletions

View File

@ -331,6 +331,21 @@ init__userdata_users() {
$MOCK addgroup "$name" "$group"
done
fi
if in_list doas $keys; then
if [ -d "$ROOT/etc/doas.d" ]; then
touch "$ROOT/etc/doas.d/$name.conf"
chmod 660 "$ROOT/etc/doas.d/$name.conf"
fi
local j
for j in $(get_userdata users/$i/doas); do
local line="$(get_userdata users/$i/doas/$j)"
if [ -d "$ROOT/etc/doas.d" ]; then
echo "$line" >> "$ROOT/etc/doas.d/$name.conf"
elif [ -f "$ROOT/etc/doas.conf" ]; then
add_once "$ROOT/etc/doas.conf" "$line"
fi
done
fi
done
}

View File

@ -27,6 +27,7 @@ init_tests \
userdata_users_no_create_home \
userdata_users_groups \
userdata_users_lock_passwd \
userdata_users_doas \
userdata_users_ssh_authorized_keys \
userdata_ssh_authorized_keys \
userdata_groups \
@ -332,6 +333,26 @@ userdata_users_lock_passwd_body() {
tiny-cloud main
}
userdata_users_doas_body() {
# first specified user will replace default user
fake_userdata_nocloud <<-EOF
#alpine-config
users:
- none
- name: foo
doas: ["permit nopass foo"]
EOF
mkdir -p etc/doas.d
atf_check -e ignore -o ignore tiny-cloud early
atf_check \
-e match:"userdata_users: done" \
-o ignore \
tiny-cloud main
find .
grep "permit nopass foo" etc/doas.d/foo.conf \
|| atf_fail "etc/doas.d/foo.conf is not as expected"
}
userdata_users_ssh_authorized_keys_body() {
fake_bin getent <<-EOF
#!/bin/sh