Skip to content

Commit caa66dd

Browse files
committed
github: basic variety unprivileged support
1 parent 9bde235 commit caa66dd

File tree

1 file changed

+51
-11
lines changed
  • github/server/scripts/variety/basic

1 file changed

+51
-11
lines changed

github/server/scripts/variety/basic/setup.sh

Lines changed: 51 additions & 11 deletions
Original file line numberDiff line numberDiff line change
@@ -6,13 +6,53 @@ set -o xtrace
66

77
kern="$(uname -s)"
88

9+
build_user='build'
10+
build_uid=12345
11+
12+
work_dir='/work'
13+
input_dir='/input'
14+
15+
if [[ $UID == $build_uid ]]; then
16+
#
17+
# Most workers allow tasks to run as root, and thus to have total
18+
# control of the system. This works for factories that generate an
19+
# empeheral environment (e.g., a virtual machine or a physical machine
20+
# booted from the network) where the environment can be destroyed
21+
# at the end of the job.
22+
#
23+
# If we were unable to get superuser privileges here, we must be
24+
# operating in an environment created by a factory that requires jobs
25+
# be run unprivileged. In that case, the factory must have done all of
26+
# the environment setup that we require for the target; e.g., creating
27+
# /work, installing any required commands into a system directory, etc.
28+
#
29+
printf 'INFO: running unprivileged!\n'
30+
31+
#
32+
# Make sure we can write to directories that we use in the job.
33+
#
34+
for d in "$HOME" "$input_dir" "$work_dir"; do
35+
#
36+
# Create and remove a file in each required directory:
37+
#
38+
fp="$d/.buildomat.write.trial"
39+
if rm -f "$fp" && touch "$fp" && rm "$fp"; then continue
40+
fi
41+
42+
printf 'ERROR: directory "%s" not available?\n' "$d" >&2
43+
exit 1
44+
done
45+
46+
exit 0
47+
fi
48+
949
case "$kern" in
1050
SunOS)
11-
groupadd -g 12345 build
12-
useradd -u 12345 -g build -d /home/build -s /bin/bash \
13-
-c 'build' -P 'Primary Administrator' build
51+
groupadd -g "$build_uid" "$build_user"
52+
useradd -u "$build_uid" -g "$build_user" -d /home/build -s /bin/bash \
53+
-c "$build_user" -P 'Primary Administrator' "$build_user"
1454

15-
zfs create -o mountpoint=/work rpool/work
55+
zfs create -o mountpoint="$work_dir" rpool/work
1656

1757
#
1858
# Some illumos images use autofs by default for /home, which is not
@@ -32,14 +72,14 @@ Linux)
3272
apt-get -y update
3373
apt-get -y install sysvbanner build-essential
3474

35-
groupadd -g 12345 build
36-
useradd -u 12345 -g build -d /home/build -s /bin/bash \
37-
-c 'build' build
75+
groupadd -g "$build_uid" "$build_user"
76+
useradd -u "$build_uid" -g "$build_user" -d /home/build -s /bin/bash \
77+
-c "$build_user" "$build_user"
3878

3979
#
4080
# Simulate pfexec and the 'Primary Administrator' role with sudo:
4181
#
42-
echo 'build ALL=(ALL:ALL) NOPASSWD:ALL' > /etc/sudoers.d/build
82+
echo "$build_user ALL=(ALL:ALL) NOPASSWD:ALL" > /etc/sudoers.d/build
4383
chmod 0440 /etc/sudoers.d/build
4484
cat >/bin/pfexec <<-'EOF'
4585
#!/bin/bash
@@ -81,7 +121,7 @@ Linux)
81121
done
82122
fi
83123

84-
mkdir -p /work
124+
mkdir -p "$work_dir"
85125
;;
86126
*)
87127
printf 'ERROR: unknown OS: %s\n' "$kern" >&2
@@ -90,5 +130,5 @@ Linux)
90130
esac
91131

92132
mkdir -p /home/build
93-
chown build:build /home/build /work
94-
chmod 0700 /home/build /work
133+
chown "$build_user":"$build_user" /home/build "$work_dir"
134+
chmod 0700 /home/build "$work_dir"

0 commit comments

Comments
 (0)