Debian Codegraph @

Dockerfile.test-debian

raw
1 FROM debian:bookworm-slim
2
3 # add "nobody" to ALL groups (makes testing edge cases more interesting)
4 RUN cut -d: -f1 /etc/group | xargs -rtI'{}' usermod -aG '{}' nobody
5 # emulate Alpine's "games" user (which is part of the "users" group)
6 RUN usermod -aG users games
7
8 RUN { \
9 echo '#!/bin/sh'; \
10 echo 'set -ex'; \
11 echo; \
12 echo 'spec="$1"; shift'; \
13 echo; \
14 echo 'expec="$1"; shift'; \
15 echo 'real="$(gosu "$spec" id -u):$(gosu "$spec" id -g):$(gosu "$spec" id -G)"'; \
16 echo '[ "$expec" = "$real" ]'; \
17 echo; \
18 echo 'expec="$1"; shift'; \
19 # have to "|| true" this one because of "id: unknown ID 1000" (rightfully) having a nonzero exit code
20 echo 'real="$(gosu "$spec" id -un):$(gosu "$spec" id -gn):$(gosu "$spec" id -Gn)" || true'; \
21 echo '[ "$expec" = "$real" ]'; \
22 } > /usr/local/bin/gosu-t \
23 && chmod +x /usr/local/bin/gosu-t
24
25 COPY gosu /usr/local/bin/
26
27 # adjust users so we can make sure the tests are interesting
28 RUN chgrp nogroup /usr/local/bin/gosu \
29 && chmod +s /usr/local/bin/gosu
30 ENV GOSU_PLEASE_LET_ME_BE_COMPLETELY_INSECURE_I_GET_TO_KEEP_ALL_THE_PIECES="I've seen things you people wouldn't believe. Attack ships on fire off the shoulder of Orion. I watched C-beams glitter in the dark near the Tannhäuser Gate. All those moments will be lost in time, like tears in rain. Time to die."
31 USER nobody
32 ENV HOME /omg/really/gosu/nowhere
33 # now we should be nobody, ALL groups, and have a bogus useless HOME value
34
35 RUN id
36
37 RUN gosu-t 0 "0:0:$(id -G root)" "root:root:$(id -Gn root)"
38 RUN gosu-t 0:0 '0:0:0' 'root:root:root'
39 RUN gosu-t root "0:0:$(id -G root)" "root:root:$(id -Gn root)"
40 RUN gosu-t 0:root '0:0:0' 'root:root:root'
41 RUN gosu-t root:0 '0:0:0' 'root:root:root'
42 RUN gosu-t root:root '0:0:0' 'root:root:root'
43 RUN gosu-t 1000 "1000:$(id -g):$(id -g)" "1000:$(id -gn):$(id -gn)"
44 RUN gosu-t 0:1000 '0:1000:1000' 'root:1000:1000'
45 RUN gosu-t 1000:1000 '1000:1000:1000' '1000:1000:1000'
46 RUN gosu-t root:1000 '0:1000:1000' 'root:1000:1000'
47 RUN gosu-t 1000:root '1000:0:0' '1000:root:root'
48 RUN gosu-t 1000:daemon "1000:$(id -g daemon):$(id -g daemon)" '1000:daemon:daemon'
49 RUN gosu-t games "$(id -u games):$(id -g games):$(id -G games)" 'games:games:games users'
50 RUN gosu-t games:daemon "$(id -u games):$(id -g daemon):$(id -g daemon)" 'games:daemon:daemon'
51
52 RUN gosu-t 0: "0:0:$(id -G root)" "root:root:$(id -Gn root)"
53 RUN gosu-t '' "$(id -u):$(id -g):$(id -G)" "$(id -un):$(id -gn):$(id -Gn)"
54 RUN gosu-t ':0' "$(id -u):0:0" "$(id -un):root:root"
55
56 RUN [ "$(gosu 0 env | grep '^HOME=')" = 'HOME=/root' ]
57 RUN [ "$(gosu 0:0 env | grep '^HOME=')" = 'HOME=/root' ]
58 RUN [ "$(gosu root env | grep '^HOME=')" = 'HOME=/root' ]
59 RUN [ "$(gosu 0:root env | grep '^HOME=')" = 'HOME=/root' ]
60 RUN [ "$(gosu root:0 env | grep '^HOME=')" = 'HOME=/root' ]
61 RUN [ "$(gosu root:root env | grep '^HOME=')" = 'HOME=/root' ]
62 RUN [ "$(gosu 0:1000 env | grep '^HOME=')" = 'HOME=/root' ]
63 RUN [ "$(gosu root:1000 env | grep '^HOME=')" = 'HOME=/root' ]
64 RUN [ "$(gosu 1000 env | grep '^HOME=')" = 'HOME=/' ]
65 RUN [ "$(gosu 1000:0 env | grep '^HOME=')" = 'HOME=/' ]
66 RUN [ "$(gosu 1000:root env | grep '^HOME=')" = 'HOME=/' ]
67 RUN [ "$(gosu games env | grep '^HOME=')" = 'HOME=/usr/games' ]
68 RUN [ "$(gosu games:daemon env | grep '^HOME=')" = 'HOME=/usr/games' ]
69
70 # make sure we error out properly in unexpected cases like an invalid username
71 RUN ! gosu bogus true
72 RUN ! gosu 0day true
73 RUN ! gosu 0:bogus true
74 RUN ! gosu 0:0day true
75
76 # something missing? some other functionality we could test easily? PR! :D