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

Use busybox from alpine #51

Open
wants to merge 4 commits into
base: master
Choose a base branch
from
Open
Show file tree
Hide file tree
Changes from 3 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
14 changes: 14 additions & 0 deletions README.md
Original file line number Diff line number Diff line change
Expand Up @@ -27,6 +27,20 @@ The following files are added (taken from Debian) to fix some common issues:
- `/etc/services` : for named ports resolution
- `/lib/x86_64-linux-gnu/libpthread.so.0` : common required lib for project binaries that cannot be statically built.

### prom/busybox:alpine-glibc : glibc

Based on the official `busybox:glibc` base image.

The `busybox` executable is replaced by the [statically linked busybox](https://pkgs.alpinelinux.org/package/v3.16/main/x86_64/busybox-static) from `alpine:latest`.
The Alpine project provides far more timely security patches to `busybox` that the official `busybox` release. No other parts of Alpine are needed or used in this image.

The following files are added (taken from Debian) to fix some common issues:

- `/etc/ssl/certs/ca-certificates.crt` : for HTTPS support
- `/usr/share/zoneinfo` : for timezones
- `/etc/services` : for named ports resolution
- `/lib/x86_64-linux-gnu/libpthread.so.0` : common required lib for project binaries that cannot be statically built.

## Build Docker images locally

```
Expand Down
49 changes: 49 additions & 0 deletions alpine-glibc/Dockerfile
Original file line number Diff line number Diff line change
@@ -0,0 +1,49 @@
ARG ARCH=""
FROM ${ARCH}debian:buster-slim

RUN \
apt-get update && apt-get install -y --no-install-recommends \
ca-certificates \
gcc \
netbase \
&& rm -rf /var/lib/apt/lists/*

RUN set -x \
&& mkdir -p rootfs/lib \
&& set -- \
/etc/nsswitch.conf \
/etc/ssl/certs/ca-certificates.crt \
/usr/share/zoneinfo \
/etc/services \
/lib/"$(gcc -print-multiarch)"/libpthread.so.* \
&& while [ "$#" -gt 0 ]; do \
f="$1"; shift; \
fn="$(basename "$f")"; \
if [ -e "rootfs/lib/$fn" ]; then continue; fi; \
if [ "${f#/lib/}" != "$f" ]; then \
ln -vL "$f" "rootfs/lib/$fn"; \
else \
d="$(dirname $f)" \
&& mkdir -p "rootfs/${d#/}" \
&& cp -av "$f" "rootfs/${f#/}"; \
fi; \
done

FROM ${ARCH}alpine:latest as alpine
RUN apk add busybox-static && \
rm /bin/* && \
/tmp/busybox --install /bin && \
mv /tmp/busybox /bin/

FROM ${ARCH}busybox:glibc
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Why not FROM scratch? If we're not going to use the busybox binary from this package, why use this as the image? All of the prometheus project binaries are static, we don't actually use glibc anymore.

Also, maybe we can simplify this to just pull the misc etc files from alpine as well, skip the debian layer as well.

Copy link
Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I consume this image: https://hub.docker.com/r/prom/prometheus

I opened this PR to try to produce a more secure base image for that image to be based on so I (and every other consumer) don't have to repackage it for busybox security issues. I was trying to do this with the least set of changes in order to have the least risk of breakages and to respect the intent of the existing images.

As I noted above, I believe:

From the perspective of consumers of these images, the key features are:

  • The busybox toolset
  • The specified libc flavor

This PR provides the above with the least changes from the existing behavior.

What you're suggesting is I skip this and go make the case for prometheus scratch images. Fair enough.

Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Yeah I don't get why this isn't FROM scratch either. I would also assume that the final image will contain both the original busybox (in a hidden layer) as well as the new one.

MAINTAINER The Prometheus Authors <[email protected]>

# Use the busybox executable from alpine which is generally patched more quickly for vulnerabilities
# Use the busybox.static to avoid dynamic library dependencies.
COPY --from=alpine /bin/busybox.static /tmp/busybox

RUN rm /bin/* && \
/tmp/busybox --install /bin && \
mv /tmp/busybox /bin/

COPY --from=0 /rootfs /