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

Conversation

liam-verta
Copy link

@liam-verta liam-verta commented Oct 19, 2022

@SuperQ @discordianfish
I'll admit this is a little hacky, but it is sufficient.

Fixes #50

Signed-off-by: Liam Newman <[email protected]>
@SuperQ
Copy link
Member

SuperQ commented Oct 20, 2022

I'm wondering if we should make a new prometheus busybox:alpine, since this changes the libc.

It doesn't quite make sense to me to call it busybox:glibc if we're not actually using glibc here.

@discordianfish
Copy link
Member

Looks like this will create an image from busybox:glibc, then copy over alpine busybox and musl which seems like fragile. Why do we still need to base this on the upstream busybox image if we replace it anyway? I'd rather to FROM scratch and copy in from alpine. But then, yes a new image tag.

Signed-off-by: Liam Newman <[email protected]>
@liam-verta
Copy link
Author

@discordianfish @SuperQ
I'm trying another pass at this PR using a statically-linked busybox.

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

  • The busybox toolset
  • The specified libc flavor

This is why I chose to continue to base this image on the same busybox:* images as before. Those images provide a specific libc flavor and minimal folder layout. We want to keep that.

Given that a particular libc flavor is present, it is convenient for busybox to link to those libraries, but that linkage is not a significant feature. The internal structure/linking of thebusybox toolset is an implementation detail.

Using a statically-linked busybox does have some effect, but it is not significant from a downstream user perspective. For example, static linking changes memory usage but probably not to a degree worth noting for the scenarios these tools are used in. See https://busybox.net/FAQ.html#tips_memory for discussion.

The size on of the busybox files is similar, with the statically linked alpine version being slightly smaller than the dynamic official executable:

  • alpine:latest - /bin/busybox: 0.82 MB (841376 bytes)
  • alpine:latest - /bin/busybox.static: 0.98 MB (1001288 bytes)
  • busybox:glibc - /bin/busybox: 1.00 MB (1025504 bytes)
  • busybox:uclibc - /bin/busybox: 1.13 MB (1157408 bytes)

Taking this change will improve the security profile of projects based on these images with minimal change to user facing features.

@SuperQ
Copy link
Member

SuperQ commented Nov 17, 2022

I don't think we should touch the existing package flavors. Rather, we should create a new image prom/busybox:alpine or something that is something we can transition to.

@liam-verta
Copy link
Author

liam-verta commented Nov 18, 2022

@SuperQ @discordianfish
Done. I made a new alpine-glibc and added a section to the readme.

Signed-off-by: Liam Newman <[email protected]>
/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.

@liam-verta
Copy link
Author

liam-verta commented Dec 15, 2022

@discordianfish @SuperQ
Another attempt at this, now from scratch. The final image is flat with no vestige of the non-static busybox. It also is stripped of libc-utils and apk.

I'm sure there is more that can be removed from this image, but perhaps this is good enough a first iteration?

Signed-off-by: Liam Newman <[email protected]>
Comment on lines +7 to +11
# Use the busybox.static to avoid dynamic library dependencies.
RUN apk add busybox-static && \
mv /bin/busybox.static /bin/busybox && \
/bin/busybox --install -s /bin

Copy link
Author

Choose a reason for hiding this comment

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

Previous iterations were trying to not include musl-libc . In this iteration, I haven't remove it. If that is okay, then we can leave the default dynamic linked busybox.

Suggested change
# Use the busybox.static to avoid dynamic library dependencies.
RUN apk add busybox-static && \
mv /bin/busybox.static /bin/busybox && \
/bin/busybox --install -s /bin

@liam-verta
Copy link
Author

@SuperQ @discordianfish
Ping?

Comment on lines +23 to +26
FROM scratch
MAINTAINER The Prometheus Authors <[email protected]>

COPY --from=alpine / /
Copy link
Member

Choose a reason for hiding this comment

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

This is copying everything, so, doing FROM scratch seems unnecessary. Our other images only copy over specific configuration files in order to make sure busybox is the only binary in the final image.

Copy link
Author

Choose a reason for hiding this comment

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

I'm not sure what you're asking for here.

Copy link
Member

Choose a reason for hiding this comment

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

I think what @SuperQ is suggesting is instead of removing the unneeded things in the base image and then copying everything here, we should use explicitly only COPY here what we need.
Can you only copy busybox here and then run /bin/busybox --install -s /bin in the final image?

Comment on lines +13 to +17
RUN apk del libc-utils

# remove apk files and directories
RUN apk del apk-tools && \
find / -name apk -prune -exec rm -rf {} ";"
Copy link
Member

Choose a reason for hiding this comment

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

Combine these steps to reduce layers.

Copy link
Author

Choose a reason for hiding this comment

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

We don't need to worry about these layers because the COPY on line 26 flattens all the build layers to a single layer in the final image.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

Successfully merging this pull request may close these issues.

Request: Use the Alpine build of BusyBox for greater security
3 participants