Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Different workaround for default user/group in 24.04 #137

Merged
Merged
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
27 changes: 13 additions & 14 deletions linux/ubuntu/scripts/runner.sh
Original file line number Diff line number Diff line change
Expand Up @@ -7,36 +7,34 @@ set -Eeuxo pipefail

printf "\n\t🐋 Creating runner users 🐋\t\n"

# 24.04 has default user 'ubuntu' with id=1000
if [ "$ID" = "24.04" ]; then
sed -i 's/ubuntu/runneradmin/' /etc/passwd
sed -i 's/ubuntu/runneradmin/' /etc/group
else
groupadd -g 1000 "${RUNNER}admin"
useradd -u 1000 -g "${RUNNER}admin" -G sudo -m -s /bin/bash "${RUNNER}admin"
fi
# Default admin user/group
RUNNERADMIN="${RUNNER}admin"

groupadd -g 1001 "${RUNNER}"
groupadd -g 1000 "${RUNNERADMIN}" || RUNNERADMIN="$(id -gn 1000)" # 24.04 has default user 'ubuntu' with id=1000

useradd -u 1001 -g "${RUNNER}" -G sudo -m -s /bin/bash "${RUNNER}"
useradd -u 1000 -g "${RUNNERADMIN}" -G sudo -m -s /bin/bash "${RUNNERADMIN}" || true

usermod -aG docker "runner"
usermod -aG docker "runneradmin"
usermod -aG docker "${RUNNER}"
usermod -aG docker "${RUNNERADMIN}"

{
echo "${RUNNER} ALL=(ALL) NOPASSWD: ALL"
echo "${RUNNER}admin ALL=(ALL) NOPASSWD: ALL"
echo "${RUNNERADMIN} ALL=(ALL) NOPASSWD: ALL"
} | tee -a /etc/sudoers

printf "\n\t🐋 Runner user 🐋\t\n"
su - "${RUNNER}" -c id

printf "\n\t🐋 Runner admin 🐋\t\n"
su - "${RUNNER}admin" -c id
su - "${RUNNERADMIN}" -c id

printf "\n\t🐋 Created non-root user 🐋\t\n"
grep "${RUNNER}" /etc/passwd

printf "\n\t🐋 Created non-root admin 🐋\t\n"
grep "${RUNNER}admin" /etc/passwd
grep "${RUNNERADMIN}" /etc/passwd

sed -i /etc/environment -e "s/USER=root/USER=${RUNNER}/g"

Expand All @@ -45,6 +43,7 @@ mkdir -p "/home/${RUNNER}/work/_temp"
chown -R "${RUNNER}":"${RUNNER}" "/home/${RUNNER}/work"

mkdir -m 0700 -p "/home/${RUNNER}/.ssh"

{
ssh-keyscan -t rsa github.com
ssh-keyscan -t rsa ssh.dev.azure.com
Expand All @@ -57,6 +56,6 @@ chown -R "${RUNNER}":"${RUNNER}" "/home/${RUNNER}/.ssh"

# Word is of the form "A"B"C" (B indicated). Did you mean "ABC" or "A\"B\"C"?shellcheck(SC2140)
# shellcheck disable=SC2140
chown -R "${RUNNER}":"${RUNNER}admin" "$AGENT_TOOLSDIRECTORY"
chown -R "${RUNNER}":"${RUNNERADMIN}" "$AGENT_TOOLSDIRECTORY"

printf "\n\t🐋 Finished building 🐋\t\n"
Loading