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

[pull] master from tianon:master #2

Open
wants to merge 76 commits into
base: master
Choose a base branch
from
Open
Show file tree
Hide file tree
Changes from all commits
Commits
Show all changes
76 commits
Select commit Hold shift + click to select a range
549de11
Add scripts/files used to generate https://hub.docker.com/r/tianon/gosu
tianon Apr 9, 2021
975771e
Switch from GPL to Apache-2.0
tianon Jun 7, 2021
ef96dbb
Update to Go 1.16
tianon Jun 7, 2021
7d5b3b5
Update to Alpine 3.13
tianon Jun 7, 2021
7e121ca
Add riscv64 binary
tianon Jun 7, 2021
c5d1d96
Update to runc 1.0.0-rc95
tianon Jun 7, 2021
7b8c929
Bump version to 1.13
tianon Jun 7, 2021
8cddd86
Add initial GitHub Actions
tianon Jun 7, 2021
cc6a155
Remove unused build badge
tianon Jun 7, 2021
d543925
Pre-emptively update a few more version numbers to 1.13
tianon Jun 7, 2021
34383f6
Fix sorting in latest.yml
tianon Jun 7, 2021
8afd3de
Disallow installing gosu with setuid
tianon Aug 17, 2021
abfaaa5
Merge pull request #89 from tianon/setuid
tianon Aug 17, 2021
220296a
Update to Alpine 3.14 and Debian Bullseye
tianon Aug 17, 2021
4c33a2f
Merge pull request #90 from tianon/update
tianon Aug 17, 2021
c5f80cc
Update to runc 1.0.1
tianon Aug 17, 2021
9f7cd13
Update to 1.14
tianon Aug 17, 2021
c8ad227
Update build deps, esp. runc to v1.0.3
tianon Dec 14, 2021
23e6390
Merge pull request #96 from tianon/runc-1.0.3
tianon Dec 14, 2021
b185278
Update to Alpine 3.15, Go 1.17, runc 1.1.0 (#102)
PascalBourdier Mar 9, 2022
66c26c5
Invoke "go mod tidy"
tianon Mar 9, 2022
e0192f9
Update to runc 1.1.2
tianon May 25, 2022
b6fb261
Merge pull request #110 from self-five/runc-1.1.2
tianon May 25, 2022
e407282
Update to Go 1.19, Alpine 3.16, runc 1.1.4
tianon Sep 7, 2022
f9e5ae0
Add SECURITY.md that points to `govulncheck`
tianon Dec 16, 2022
e6d5129
Merge pull request #120 from self-five/govulncheck
tianon Dec 19, 2022
50e26df
Update to 1.15
tianon Dec 19, 2022
e086fb4
Use QEMU and "arch-test" to avoid bad binaries in the future
tianon Dec 19, 2022
8eb1914
Backport https://github.com/golang/go/commit/2c7c98c3ad719aa9d6d25948…
tianon Dec 20, 2022
bb69d2a
Merge pull request #121 from self-five/qemu
tianon Dec 20, 2022
0e73477
Update to 1.16
tianon Dec 20, 2022
6a1967c
Update CI's govulncheck (to https://github.com/golang/vuln/commit/a42…
tianon Mar 31, 2023
bf158f3
Update "govulncheck" and add "-mode=binary"
tianon Apr 14, 2023
93cfc61
Remove explicit `dirmngr` reference
tianon Apr 28, 2023
bfab97a
Update govulncheck to the explicit new v0.1.0 release
tianon May 3, 2023
4f8f387
Merge pull request #126 from self-five/govulncheck-0.1.0
tianon May 3, 2023
d0aba52
Add new "govulncheck-with-excludes.sh" wrapper script
tianon Jun 27, 2023
d347213
Merge pull request #129 from self-five/govulncheck-with-excludes
tianon Jun 27, 2023
facd58e
Update to govulncheck v1.0.0
tianon Jul 13, 2023
a430ca0
Update govulncheck JSON parsing for v1.0.0
tianon Jul 13, 2023
7059acb
Update govulncheck to v1.0.1
tianon Sep 5, 2023
512d5e6
setup-user: use syscall instead of libcontainer/system
neersighted Oct 11, 2023
f7d40f0
setup-user: use golang.org/x/sys/unix
neersighted Oct 11, 2023
165a750
setup-user: use github.com/moby/sys/user
neersighted Oct 11, 2023
99f2f75
Merge pull request #134 from neersighted/dep_cleanup
tianon Nov 2, 2023
d126529
Update "tianon/gosu" Docker Hub image to build via bashbrew instead o…
tianon Nov 2, 2023
0d18474
Update to 1.17
tianon Nov 2, 2023
bd5b5e8
Update published images to Debian Bookworm, Alpine 3.18
tianon Nov 2, 2023
2dada3b
Rewrite gsl.sh so it relies less on SharedTags
tianon Nov 2, 2023
056c5dc
Add `-trimpath` to builds for cleaner embedded paths
tianon Dec 21, 2023
b73cc93
Merge pull request #137 from self-five/trimpath
tianon Dec 21, 2023
96e1ec4
Remove use of text/template
AlexanderYastrebov Mar 19, 2024
a7a1ca6
Merge pull request #138 from AlexanderYastrebov/remove-template
tianon Mar 20, 2024
04fac5a
Ditch `fmt`, `log`, `path/filepath`, and `strings` for ~17KB more sav…
tianon Mar 20, 2024
53c4966
Merge pull request #139 from self-five/no-log-fmt-strings
tianon Mar 20, 2024
f0ea85b
Update `tianon/gosu` Alpine images to 3.19
tianon Mar 20, 2024
2176ec2
Add `COPY --from=tianon/gosu` to `INSTALL.md`
tianon Mar 20, 2024
0396450
Slightly better / more up-to-date comment in setup-user.go
tianon Mar 20, 2024
64a0cd9
Update `SECURITY.md` to better reflect the move to `github.com/moby/s…
tianon Mar 20, 2024
9ea56fe
Update to Go 1.20.5
tianon Mar 20, 2024
21b5265
Adjust minimum required `golang.org/x/sys` down to v0.1.0
tianon Mar 20, 2024
ea17b79
Add a reference to the blog post about Go's "Minimal Version Selection"
tianon Mar 20, 2024
ccc5c46
Switch from `io.Writer` to explicit `*os.File` (shaving off a tiny am…
tianon Mar 20, 2024
75129e1
Merge pull request #140 from self-five/go1.20.5
tianon Mar 21, 2024
1cd234d
Update govulncheck to 1.0.4, actions versions
tianon Mar 21, 2024
a1f38ca
Improve grammar around tooling in SECURITY
tianon Mar 21, 2024
08ad027
Add an "RPM-based" section back to `INSTALL.md`
tianon May 29, 2024
2189d77
Merge pull request #142 from self-five/rpm-install
tianon May 29, 2024
6828632
Adjust `su-exec` references, especially to note the severe years-long…
tianon Jun 3, 2024
a094511
Fix version reference
tianon Jun 3, 2024
7b1b498
Fix govulncheck wrapper + run govulncheck on latest release periodica…
tianon Jun 6, 2024
dcb68b2
Merge pull request #145 from tianon/govulncheck-latest
tianon Jun 6, 2024
46d6258
Update broken dockerfile.test link
LukeParky Jul 16, 2024
052c5c2
Merge pull request #147 from LukeParky/fix-dockerfile-test-link
tianon Jul 20, 2024
9842436
Add "suite" aliases to published images (`bookworm`, `alpine3.19`)
tianon Sep 27, 2024
4233b79
Update to Alpine 3.20
tianon Sep 27, 2024
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
33 changes: 33 additions & 0 deletions .github/workflows/ci.yml
Original file line number Diff line number Diff line change
@@ -0,0 +1,33 @@
name: CI

on:
pull_request:
push:
schedule:
- cron: 0 0 * * 0
workflow_dispatch:

defaults:
run:
shell: 'bash -Eeuo pipefail -x {0}'

jobs:
test:
name: Test
runs-on: ubuntu-latest
steps:
- uses: actions/checkout@v4
- run: sudo apt-get update && sudo apt-get install -y --no-install-recommends binfmt-support qemu-user-static
- run: ./build.sh
- run: ./test.sh gosu-amd64
- run: ./test.sh gosu-i386
- run: ./test.sh --debian gosu-amd64
- run: ./test.sh --debian gosu-i386
- run: docker build --pull --file hub/Dockerfile.alpine hub
- run: docker build --pull --file hub/Dockerfile.debian hub

- name: govulncheck
run: |
for gosu in gosu-*; do
./govulncheck-with-excludes.sh -mode=binary "$gosu"
done
52 changes: 52 additions & 0 deletions .github/workflows/release.yml
Original file line number Diff line number Diff line change
@@ -0,0 +1,52 @@
name: Release

on:
pull_request:
paths:
- '.github/workflows/release.yml'
- 'govulncheck-with-excludes.sh'
push:
paths:
- '.github/workflows/release.yml'
- 'govulncheck-with-excludes.sh'
schedule:
- cron: 0 0 * * 0
workflow_dispatch:

defaults:
run:
shell: 'bash -Eeuo pipefail -x {0}'

jobs:
test:
name: govulncheck
runs-on: ubuntu-latest
steps:
- uses: actions/checkout@v4

- name: download
run: |
# find and download the latest release for testing
tags="$(git ls-remote --tags https://github.com/tianon/gosu.git | cut -d/ -f3 | cut -d^ -f1 | sort -urV)"
for tag in $tags; do
echo >&2 "checking $tag ..."
url="https://github.com/tianon/gosu/releases/download/$tag"
if wget -O SHA256SUMS "$url/SHA256SUMS" && [ -s SHA256SUMS ]; then
files="$(grep -oE '[ *]gosu-[^.]+$' SHA256SUMS | grep -oE 'gosu-.*$')"
for file in $files; do
wget -O "$file" "$url/$file"
done
if grep -E '[ *]gosu-[^.]+$' SHA256SUMS | sha256sum --strict --check -; then
echo >&2 "success with $tag !"
exit 0
fi
fi
done

echo >&2 'error: failed to find latest release'

- name: govulncheck
run: |
for gosu in gosu-*; do
./govulncheck-with-excludes.sh -mode=binary "$gosu"
done
9 changes: 0 additions & 9 deletions .travis.yml

This file was deleted.

85 changes: 38 additions & 47 deletions Dockerfile
Original file line number Diff line number Diff line change
@@ -1,6 +1,31 @@
FROM golang:1.14-alpine3.12

RUN apk add --no-cache file
FROM golang:1.20.5-bookworm

RUN set -eux; \
apt-get update; \
apt-get install -y --no-install-recommends \
arch-test \
file \
; \
rm -rf /var/lib/apt/lists/*

# note: we cannot add "-s" here because then "govulncheck" does not work (see SECURITY.md); the ~0.2MiB increase (as of 2022-12-16, Go 1.18) is worth it
ENV BUILD_FLAGS="-v -trimpath -ldflags '-d -w'"

RUN set -eux; \
{ \
echo '#!/usr/bin/env bash'; \
echo 'set -Eeuo pipefail -x'; \
echo 'eval "go build $BUILD_FLAGS -o /go/bin/gosu-$ARCH"'; \
echo 'file "/go/bin/gosu-$ARCH"'; \
echo 'if arch-test "$ARCH"; then'; \
# there's a fun QEMU + Go 1.18+ bug that causes our binaries (especially on ARM arches) to hang indefinitely *sometimes*, hence the "timeout" and looping here
echo ' try() { for (( i = 0; i < 30; i++ )); do if timeout 1s "$@"; then return 0; fi; done; return 1; }'; \
echo ' try "/go/bin/gosu-$ARCH" --version'; \
echo ' try "/go/bin/gosu-$ARCH" nobody id'; \
echo ' try "/go/bin/gosu-$ARCH" nobody ls -l /proc/self/fd'; \
echo 'fi'; \
} > /usr/local/bin/gosu-build-and-test.sh; \
chmod +x /usr/local/bin/gosu-build-and-test.sh

# disable CGO for ALL THE THINGS (to help ensure no libc)
ENV CGO_ENABLED 0
Expand All @@ -12,52 +37,18 @@ RUN set -eux; \
go mod download; \
go mod verify

ENV BUILD_FLAGS="-v -ldflags '-d -s -w'"

COPY *.go ./

# gosu-$(dpkg --print-architecture)
RUN set -eux; \
eval "GOARCH=amd64 go build $BUILD_FLAGS -o /go/bin/gosu-amd64"; \
file /go/bin/gosu-amd64; \
/go/bin/gosu-amd64 --version; \
/go/bin/gosu-amd64 nobody id; \
/go/bin/gosu-amd64 nobody ls -l /proc/self/fd

RUN set -eux; \
eval "GOARCH=386 go build $BUILD_FLAGS -o /go/bin/gosu-i386"; \
file /go/bin/gosu-i386; \
/go/bin/gosu-i386 --version; \
/go/bin/gosu-i386 nobody id; \
/go/bin/gosu-i386 nobody ls -l /proc/self/fd

RUN set -eux; \
eval "GOARCH=arm GOARM=5 go build $BUILD_FLAGS -o /go/bin/gosu-armel"; \
file /go/bin/gosu-armel

RUN set -eux; \
eval "GOARCH=arm GOARM=6 go build $BUILD_FLAGS -o /go/bin/gosu-armhf"; \
file /go/bin/gosu-armhf

# boo Raspberry Pi, making life hard (armhf-is-v7 vs armhf-is-v6 ...)
#RUN set -eux; \
# eval "GOARCH=arm GOARM=7 go build $BUILD_FLAGS -o /go/bin/gosu-armhf"; \
# file /go/bin/gosu-armhf

RUN set -eux; \
eval "GOARCH=arm64 go build $BUILD_FLAGS -o /go/bin/gosu-arm64"; \
file /go/bin/gosu-arm64

RUN set -eux; \
eval "GOARCH=mips64le go build $BUILD_FLAGS -o /go/bin/gosu-mips64el"; \
file /go/bin/gosu-mips64el

RUN set -eux; \
eval "GOARCH=ppc64le go build $BUILD_FLAGS -o /go/bin/gosu-ppc64el"; \
file /go/bin/gosu-ppc64el

RUN set -eux; \
eval "GOARCH=s390x go build $BUILD_FLAGS -o /go/bin/gosu-s390x"; \
file /go/bin/gosu-s390x
RUN ARCH=amd64 GOARCH=amd64 gosu-build-and-test.sh
RUN ARCH=i386 GOARCH=386 gosu-build-and-test.sh
RUN ARCH=armel GOARCH=arm GOARM=5 gosu-build-and-test.sh
RUN ARCH=armhf GOARCH=arm GOARM=6 gosu-build-and-test.sh
#RUN ARCH=armhf GOARCH=arm GOARM=7 gosu-build-and-test.sh # boo Raspberry Pi, making life hard (armhf-is-v7 vs armhf-is-v6 ...)
RUN ARCH=arm64 GOARCH=arm64 gosu-build-and-test.sh
RUN ARCH=mips64el GOARCH=mips64le gosu-build-and-test.sh
RUN ARCH=ppc64el GOARCH=ppc64le gosu-build-and-test.sh
RUN ARCH=riscv64 GOARCH=riscv64 gosu-build-and-test.sh
RUN ARCH=s390x GOARCH=s390x gosu-build-and-test.sh

RUN set -eux; ls -lAFh /go/bin/gosu-*; file /go/bin/gosu-*
5 changes: 3 additions & 2 deletions Dockerfile.test-alpine
Original file line number Diff line number Diff line change
@@ -1,7 +1,7 @@
FROM alpine:3.12
FROM alpine:3.20

# add "nobody" to ALL groups (makes testing edge cases more interesting)
RUN cut -d: -f1 /etc/group | xargs -n1 addgroup nobody
RUN cut -d: -f1 /etc/group | xargs -rtn1 addgroup nobody

RUN { \
echo '#!/bin/sh'; \
Expand All @@ -25,6 +25,7 @@ COPY gosu /usr/local/bin/
# adjust users so we can make sure the tests are interesting
RUN chgrp nobody /usr/local/bin/gosu \
&& chmod +s /usr/local/bin/gosu
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."
USER nobody
ENV HOME /omg/really/gosu/nowhere
# now we should be nobody, ALL groups, and have a bogus useless HOME value
Expand Down
5 changes: 3 additions & 2 deletions Dockerfile.test-debian
Original file line number Diff line number Diff line change
@@ -1,7 +1,7 @@
FROM debian:buster-slim
FROM debian:bookworm-slim

# add "nobody" to ALL groups (makes testing edge cases more interesting)
RUN cut -d: -f1 /etc/group | xargs -n1 -I'{}' usermod -aG '{}' nobody
RUN cut -d: -f1 /etc/group | xargs -rtI'{}' usermod -aG '{}' nobody
# emulate Alpine's "games" user (which is part of the "users" group)
RUN usermod -aG users games

Expand All @@ -27,6 +27,7 @@ COPY gosu /usr/local/bin/
# adjust users so we can make sure the tests are interesting
RUN chgrp nogroup /usr/local/bin/gosu \
&& chmod +s /usr/local/bin/gosu
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."
USER nobody
ENV HOME /omg/really/gosu/nowhere
# now we should be nobody, ALL groups, and have a bogus useless HOME value
Expand Down
63 changes: 49 additions & 14 deletions INSTALL.md
Original file line number Diff line number Diff line change
Expand Up @@ -15,21 +15,15 @@ RUN set -eux; \
gosu nobody true
```

Older Debian releases (or newer `gosu` releases):
Newer `gosu` releases:

```dockerfile
ENV GOSU_VERSION 1.12
ENV GOSU_VERSION 1.17
RUN set -eux; \
# save list of currently installed packages for later so we can clean up
savedAptMark="$(apt-mark showmanual)"; \
apt-get update; \
apt-get install -y --no-install-recommends ca-certificates wget; \
if ! command -v gpg; then \
apt-get install -y --no-install-recommends gnupg2 dirmngr; \
elif gpg --version | grep -q '^gpg (GnuPG) 1\.'; then \
# "This package provides support for HKPS keyservers." (GnuPG 1.x only)
apt-get install -y --no-install-recommends gnupg-curl; \
fi; \
apt-get install -y --no-install-recommends ca-certificates gnupg wget; \
rm -rf /var/lib/apt/lists/*; \
\
dpkgArch="$(dpkg --print-architecture | awk -F- '{ print $NF }')"; \
Expand All @@ -40,7 +34,7 @@ RUN set -eux; \
export GNUPGHOME="$(mktemp -d)"; \
gpg --batch --keyserver hkps://keys.openpgp.org --recv-keys B42F6819007F00F88E364FD4036A9C25BF357DD4; \
gpg --batch --verify /usr/local/bin/gosu.asc /usr/local/bin/gosu; \
command -v gpgconf && gpgconf --kill all || :; \
gpgconf --kill all; \
rm -rf "$GNUPGHOME" /usr/local/bin/gosu.asc; \
\
# clean up fetch dependencies
Expand All @@ -56,10 +50,8 @@ RUN set -eux; \

## `FROM alpine` (3.7+)

**Note:** when using Alpine, it's probably also worth checking out [`su-exec`](https://github.com/ncopa/su-exec) (`apk add --no-cache su-exec`) instead, which since version 0.2 is fully `gosu`-compatible in a fraction of the file size.

```dockerfile
ENV GOSU_VERSION 1.12
ENV GOSU_VERSION 1.17
RUN set -eux; \
\
apk add --no-cache --virtual .gosu-deps \
Expand All @@ -76,7 +68,7 @@ RUN set -eux; \
export GNUPGHOME="$(mktemp -d)"; \
gpg --batch --keyserver hkps://keys.openpgp.org --recv-keys B42F6819007F00F88E364FD4036A9C25BF357DD4; \
gpg --batch --verify /usr/local/bin/gosu.asc /usr/local/bin/gosu; \
command -v gpgconf && gpgconf --kill all || :; \
gpgconf --kill all; \
rm -rf "$GNUPGHOME" /usr/local/bin/gosu.asc; \
\
# clean up fetch dependencies
Expand All @@ -87,3 +79,46 @@ RUN set -eux; \
gosu --version; \
gosu nobody true
```

## `FROM centos|oraclelinux|...|ubi|...` (RPM-based distro)

```dockerfile
ENV GOSU_VERSION 1.17
RUN set -eux; \
\
rpmArch="$(rpm --query --queryformat='%{ARCH}' rpm)"; \
case "$rpmArch" in \
aarch64) dpkgArch='arm64' ;; \
armv[67]*) dpkgArch='armhf' ;; \
i[3456]86) dpkgArch='i386' ;; \
ppc64le) dpkgArch='ppc64el' ;; \
riscv64 | s390x) dpkgArch="$rpmArch" ;; \
x86_64) dpkgArch='amd64' ;; \
*) echo >&2 "error: unknown/unsupported architecture '$rpmArch'"; exit 1 ;; \
esac; \
wget -O /usr/local/bin/gosu "https://github.com/tianon/gosu/releases/download/$GOSU_VERSION/gosu-$dpkgArch"; \
wget -O /usr/local/bin/gosu.asc "https://github.com/tianon/gosu/releases/download/$GOSU_VERSION/gosu-$dpkgArch.asc"; \
\
# verify the signature
export GNUPGHOME="$(mktemp -d)"; \
gpg --batch --keyserver hkps://keys.openpgp.org --recv-keys B42F6819007F00F88E364FD4036A9C25BF357DD4; \
gpg --batch --verify /usr/local/bin/gosu.asc /usr/local/bin/gosu; \
gpgconf --kill all; \
rm -rf "$GNUPGHOME" /usr/local/bin/gosu.asc; \
\
chmod +x /usr/local/bin/gosu; \
# verify that the binary works
gosu --version; \
gosu nobody true
```

Notes:

- `gosu`'s `armhf` builds are ARMv6 (not ARMv7 as they might be in Debian proper) thanks to Raspbian, hence the `armv6` allowance above
- `rpm` architecture values sourced from https://rpmfind.net/linux/rpm2html/search.php?query=rpm

## Others / Lazy Method

```dockerfile
COPY --from=tianon/gosu /gosu /usr/local/bin/
```
Loading