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

Heroku-24: Use the same user for the run and build images #281

Merged
merged 1 commit into from
Mar 27, 2024
Merged
Show file tree
Hide file tree
Changes from all 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
3 changes: 1 addition & 2 deletions heroku-20-cnb-build/Dockerfile
Original file line number Diff line number Diff line change
Expand Up @@ -7,6 +7,7 @@ RUN groupadd heroku --gid 1000 \
&& chown heroku:heroku /app

# https://github.com/buildpacks/spec/blob/platform/0.13/platform.md#build-image
USER heroku
ENV CNB_USER_ID=1000
ENV CNB_GROUP_ID=1000
# Note: This image doesn't inherit from the CNB run image variant so we have
Expand All @@ -20,5 +21,3 @@ LABEL io.buildpacks.base.maintainer="Heroku"
# https://github.com/buildpacks/spec/blob/platform/0.13/platform.md#iobuildpacksstack-labels
ENV CNB_STACK_ID="heroku-20"
LABEL io.buildpacks.stack.id="heroku-20"

USER heroku
3 changes: 1 addition & 2 deletions heroku-22-cnb-build/Dockerfile
Original file line number Diff line number Diff line change
Expand Up @@ -7,6 +7,7 @@ RUN groupadd heroku --gid 1000 \
&& chown heroku:heroku /app

# https://github.com/buildpacks/spec/blob/platform/0.13/platform.md#build-image
USER heroku
ENV CNB_USER_ID=1000
ENV CNB_GROUP_ID=1000
# Note: This image doesn't inherit from the CNB run image variant so we have
Expand All @@ -20,5 +21,3 @@ LABEL io.buildpacks.base.maintainer="Heroku"
# https://github.com/buildpacks/spec/blob/platform/0.13/platform.md#iobuildpacksstack-labels
ENV CNB_STACK_ID="heroku-22"
LABEL io.buildpacks.stack.id="heroku-22"

USER heroku
6 changes: 3 additions & 3 deletions heroku-24-build/Dockerfile
Original file line number Diff line number Diff line change
@@ -1,14 +1,14 @@
ARG BASE_IMAGE=heroku/heroku:24
FROM $BASE_IMAGE

# We have to temporarily switch back to root, since the run image sets a non-root default USER.
# We have to temporarily switch back to root, since the run image sets a non-root default `USER`.
USER root
RUN --mount=target=/build /build/setup.sh

# https://github.com/buildpacks/spec/blob/platform/0.13/platform.md#build-image
# The `io.buildpacks.base.*` labels are inherited from the run image, so don't need to be repeated here.
USER 1002
ENV CNB_USER_ID=1002
USER heroku
ENV CNB_USER_ID=1000
ENV CNB_GROUP_ID=1000

# Stack IDs are deprecated, but we still set this for backwards compatibility:
Expand Down
2 changes: 1 addition & 1 deletion heroku-24/Dockerfile
Original file line number Diff line number Diff line change
Expand Up @@ -3,7 +3,7 @@ FROM ubuntu:24.04
RUN --mount=target=/build /build/setup.sh

# https://github.com/buildpacks/spec/blob/platform/0.13/platform.md#run-image
USER 1001
USER heroku
LABEL io.buildpacks.base.distro.name="ubuntu"
LABEL io.buildpacks.base.distro.version="24.04"
LABEL io.buildpacks.base.homepage="https://github.com/heroku/base-images"
Expand Down
10 changes: 6 additions & 4 deletions heroku-24/setup.sh
Original file line number Diff line number Diff line change
Expand Up @@ -189,10 +189,12 @@ apt-get purge -y openjdk-8-jre-headless
apt-get autoremove -y --purge
test "$(file -b /etc/ssl/certs/java/cacerts)" = "Java KeyStore"

useradd heroku --uid 1001 --gid 1000 --shell /bin/bash --create-home
useradd heroku-build --uid 1002 --gid 1000 --shell /bin/bash --create-home
groupmod --new-name heroku ubuntu
deluser --remove-home ubuntu
# Ubuntu 24.04 ships with a default user and group named 'ubuntu' (with user+group ID of 1000)
# that we have to remove before creating our own (`userdel` will remove the group too).
userdel ubuntu --remove

groupadd heroku --gid 1000
useradd heroku --uid 1000 --gid 1000 --shell /bin/bash --create-home

rm -rf /root/*
rm -rf /tmp/*
Expand Down