Skip to content

Commit 7f30dc8

Browse files
committed
Make sure that root is in the sudoers file on Alpine
Because the Alpine cloud image doesn't include /etc/sudoers, and cloud-init just writes a single line to it: #includedir /etc/sudoers.d Without an entry for root we cannot run user provisioning scripts because we use `sudo -u $USER …` to do it. Signed-off-by: Jan Dubois <[email protected]>
1 parent 0e93110 commit 7f30dc8

File tree

1 file changed

+17
-8
lines changed

1 file changed

+17
-8
lines changed
Lines changed: 17 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -1,12 +1,21 @@
11
#!/bin/sh
2-
# Remove the user embedded in the image,
3-
# and use cloud-init for users and groups.
42
test -f /etc/alpine-release || exit 0
5-
test "$LIMA_CIDATA_USER" != "alpine" || exit 0
63

7-
if [ "$(id -u alpine 2>&1)" = "1000" ]; then
8-
userdel alpine
9-
rmdir /home/alpine
10-
cloud-init clean --logs
11-
reboot
4+
# Make sure that root is in the sudoers file.
5+
# This is needed to run the user provisioning scripts.
6+
SUDOERS=/etc/sudoers.d/00-root-user
7+
if [ ! -f $SUDOERS ]; then
8+
echo "root ALL=(ALL) NOPASSWD:ALL" >$SUDOERS
9+
chmod 660 $SUDOERS
10+
fi
11+
12+
# Remove the user embedded in the image,
13+
# and use cloud-init for users and groups.
14+
if [ "$LIMA_CIDATA_USER" != "alpine" ]; then
15+
if [ "$(id -u alpine 2>&1)" = "1000" ]; then
16+
userdel alpine
17+
rmdir /home/alpine
18+
cloud-init clean --logs
19+
reboot
20+
fi
1221
fi

0 commit comments

Comments
 (0)