@@ -16,37 +16,75 @@ trap "{ rm -r $IMGDIRECTORY; }" EXIT
16
16
17
17
DIFFOSCOPE=" diffoscope"
18
18
19
+ function get_subguids() {
20
+ local user=$( id -u)
21
+ local subuids
22
+ local subgids
23
+ while IFS=: read uid start count ; do
24
+ if [[ $user == $( id -u $uid ) ]] ; then
25
+ subuids=" 1:$start :$count "
26
+ break
27
+ fi
28
+ done < /etc/subuid
29
+ while IFS=: read uid start count ; do
30
+ if [[ $user == $( id -u $uid ) ]] ; then
31
+ subgids=" 1:$start :$count "
32
+ break
33
+ fi
34
+ done < /etc/subgid
35
+ [[ $subuids && $subgids ]] || return 1
36
+ printf " --uid_mapping %s --gid_mapping %s " " $subuids " " $subgids "
37
+ }
38
+
39
+ # Desc: Enter a user namespace with virtual privileges
40
+ function become_rootless() {
41
+ (( rootless_userns)) || return
42
+ (( __REPRO_NSJAIL == 1 )) && return
43
+ local subguids=$( get_subguids)
44
+ if (( $? )) ; then
45
+ error " Your user has no subuids or subgids"
46
+ exit 1
47
+ fi
48
+ exec nsjail -Mo --quiet --skip_setsid \
49
+ --disable_clone_newnet --disable_clone_newpid \
50
+ --disable_rlimit --disable_proc --keep_caps \
51
+ --chroot / --cwd " $( pwd) " --rw \
52
+ --uid 0 --gid 0 $subguids \
53
+ --keep_env -E ' __REPRO_NSJAIL=1' -- " ${orig_argv[@]} "
54
+ # exec become-root unshare --mount "${orig_argv[@]}"
55
+ }
56
+
19
57
# Desc: Escalates privileges
20
58
orig_argv=(" $0 " " $@ " )
21
59
src_owner=${SUDO_USER:- $USER }
22
60
function check_root() {
23
61
(( EUID == 0 )) && return
24
- if (( rootless_userns)) ; then
25
- exec become-root unshare --mount " ${orig_argv[@]} "
26
- elif type -P sudo > /dev/null; then
62
+ if type -P sudo > /dev/null; then
27
63
exec sudo -- " ${orig_argv[@]} "
28
64
else
29
65
exec su root -c " $( printf ' %q' " ${orig_argv[@]} " ) "
30
66
fi
31
67
}
32
68
33
69
function require_userns_tools() {
34
- if command -v become-root > /dev/null \
70
+ # if command -v become-root >/dev/null \
71
+ if command -v unshare > /dev/null \
35
72
&& command -v nsjail > /dev/null \
36
73
&& command -v fuse-overlayfs > /dev/null
37
74
then
38
75
return 0
39
76
fi
40
- warning " nsjail, fuse-overlayfs and become-root are necessary for rootless operation"
41
- warning " https://github.com/giuseppe/become-root"
77
+ warning " nsjail, fuse-overlayfs and unshare (util-linux) are necessary for rootless operation"
78
+ # warning "nsjail, fuse-overlayfs and become-root are necessary for rootless operation"
79
+ # warning "https://github.com/giuseppe/become-root"
42
80
warning " https://github.com/containers/fuse-overlayfs"
43
81
warning " https://github.com/google/nsjail"
44
82
return 1
45
83
}
46
84
47
85
function mountoverlay() {
48
86
if (( rootless_userns)) ; then
49
- fuse-overlayfs " $@ "
87
+ ~ /Projekte/fuse-overlayfs/ fuse-overlayfs " $@ "
50
88
else
51
89
mount -t overlayfs overlayfs " $@ "
52
90
fi
@@ -61,7 +99,11 @@ function umountoverlay() {
61
99
62
100
# Use a private gpg keyring
63
101
function gpg() {
102
+ local res
64
103
command gpg --homedir=" $BUILDDIRECTORY /gnupg" " $@ "
104
+ res=$?
105
+ gpgconf --homedir=" $BUILDDIRECTORY /gnupg" --kill gpg-agent
106
+ return $res
65
107
}
66
108
67
109
function init_gnupg() {
@@ -257,14 +299,19 @@ function init_chroot(){
257
299
exec_container root pacman -R arch-install-scripts --noconfirm
258
300
exec_container root locale-gen
259
301
260
- printf ' builduser ALL = NOPASSWD: /usr/bin/pacman\n' > " $BUILDDIRECTORY " /root/etc/sudoers.d/builduser-pacman
302
+ printf ' %s\n\n' ' Defaults preserve_groups' \
303
+ ' builduser ALL = NOPASSWD: /usr/bin/pacman' \
304
+ > " $BUILDDIRECTORY " /root/etc/sudoers.d/builduser-pacman
261
305
exec_container root useradd -m -G wheel -s /bin/bash -d /build builduser
262
306
echo " keyserver-options auto-key-retrieve" | install -Dm644 /dev/stdin " $BUILDDIRECTORY /root" /build/.gnupg/gpg.conf
263
307
exec_container root chown -R builduser /build/.gnupg
264
308
else
265
309
printf ' Server = %s\n' " $HOSTMIRROR " > " $BUILDDIRECTORY " /root/etc/pacman.d/mirrorlist
266
310
exec_container root pacman -Syu --noconfirm
267
311
fi
312
+ exec_container root gpgconf --homedir=" /etc/pacman.d/gnupg" --kill gpg-agent
313
+ # FIXME: Why is this necessary?
314
+ rm -f " $BUILDDIRECTORY " /root/etc/pacman.d/gnupg/S.gpg-agent{,.browser,.extra,.ssh}
268
315
269
316
trap - ERR INT
270
317
}
@@ -390,6 +437,7 @@ Usage:
390
437
General Options:
391
438
-h Print this help message
392
439
-d Run diffoscope if packages are not reproducible
440
+ -r Run without root privileges in nsjail containers
393
441
__END__
394
442
}
395
443
@@ -420,6 +468,7 @@ while getopts :hdorC:P:M: arg; do
420
468
d) run_diffoscope=1;;
421
469
r) rootless_userns=1;
422
470
require_userns_tools || exit 1
471
+ become_rootless
423
472
# TODO: better detection for valid writable build directory
424
473
[[ $BUILDDIRECTORY == /var/lib/repro ]] && BUILDDIRECTORY=" ${XDG_CACHE_HOME:- $HOME / .cache} /archlinux-repro"
425
474
;;
0 commit comments