Skip to content

non-root user #537

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

Open
wants to merge 3 commits into
base: master
Choose a base branch
from
Open
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
6 changes: 3 additions & 3 deletions pom.xml
Original file line number Diff line number Diff line change
Expand Up @@ -6,7 +6,7 @@
<parent>
<groupId>org.springframework.boot</groupId>
<artifactId>spring-boot-starter-parent</artifactId>
<version>3.1.0</version>
<version>3.1.1</version>
</parent>
<groupId>com.obsidiandynamics.kafdrop</groupId>
<artifactId>kafdrop</artifactId>
Expand Down Expand Up @@ -239,9 +239,9 @@
</configuration>
</plugin>
<plugin>
<groupId>com.spotify</groupId>
<groupId>io.fabric8</groupId>
<artifactId>docker-maven-plugin</artifactId>
<version>1.2.2</version>
Comment on lines -242 to -244
Copy link
Collaborator

Choose a reason for hiding this comment

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

Please revert this change, as the current change is incomplete, leading to these warnings that make the image build fail:

[WARNING] Parameter 'dockerDirectory' is unknown for plugin 'docker-maven-plugin:0.43.0:build (default-cli)'
[WARNING] Parameter 'imageName' is unknown for plugin 'docker-maven-plugin:0.43.0:build (default-cli)'
[WARNING] Parameter 'forceTags' is unknown for plugin 'docker-maven-plugin:0.43.0:build (default-cli)'
[WARNING] Parameter 'resources' is unknown for plugin 'docker-maven-plugin:0.43.0:build (default-cli)'
[WARNING] Parameter 'imageTags' is unknown for plugin 'docker-maven-plugin:0.43.0:build (default-cli)'

With that, pom.xml can be removed from your change set.

<version>0.43.0</version>
<configuration>
<imageName>obsidiandynamics/kafdrop</imageName>
<forceTags>true</forceTags>
Expand Down
25 changes: 21 additions & 4 deletions src/main/docker/Dockerfile
Original file line number Diff line number Diff line change
@@ -1,10 +1,27 @@
FROM eclipse-temurin:17.0.7_7-jdk

ADD kafdrop.sh /
ADD kafdrop*tar.gz /
COPY kafdrop*.tar.gz /tmp/kafdrop.tar.gz

RUN chmod +x /kafdrop.sh
RUN mkdir /opt/kafdrop && \
tar \
Copy link
Collaborator

Choose a reason for hiding this comment

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

This became a lot more complex than it used to be. Let's simplify this.

  • Through ADD, Docker can extract the zip to the /opt/kafdrop. That causes a bit of an ugly directory structure, but nobody needs to go through it, so it doesn't matter
  • The chmod can be prevented by adding the execution permission in Git. I created Make kafdrop.sh executable #539 for that

With these changes, the Dockerfile can be come this simple:

FROM eclipse-temurin:17.0.7_7-jdk

WORKDIR /opt/kafdrop
ADD kafdrop*tar.gz .
COPY kafdrop.sh .

RUN groupadd -g 1000 kafdrop && \
    useradd -u 1000 -g kafdrop kafdrop && \
    chown --recursive kafdrop:kafdrop /opt/kafdrop

USER kafdrop

ENV PATH="/opt/java/openjdk/bin:$PATH"

EXPOSE 9000

ENTRYPOINT ["/opt/kafdrop/kafdrop.sh"]

-xz \
--strip-components=1 \
--no-same-owner \
-C /opt/kafdrop \
-f /tmp/kafdrop.tar.gz && \
rm /tmp/kafdrop.tar.gz && \
groupadd -g 1000 kafdrop && \
useradd -u 1000 -g kafdrop kafdrop && \
chown kafdrop:kafdrop /opt/kafdrop

COPY --chmod=755 kafdrop.sh /opt/kafdrop

USER kafdrop

ENV PATH="/opt/java/openjdk/bin:$PATH"

EXPOSE 9000

ENTRYPOINT ["/kafdrop.sh"]
WORKDIR /opt/kafdrop

ENTRYPOINT ["/opt/kafdrop/kafdrop.sh"]
2 changes: 1 addition & 1 deletion src/main/docker/kafdrop.sh
Original file line number Diff line number Diff line change
Expand Up @@ -65,4 +65,4 @@ ARGS="--add-opens=java.base/sun.nio.ch=ALL-UNNAMED -Xss256K \
$HEAP_ARGS \
$JVM_OPTS"

exec java $ARGS -jar /kafdrop*/kafdrop*jar ${CMD_ARGS}
exec java $ARGS -jar /opt/kafdrop/kafdrop*.jar ${CMD_ARGS}
Copy link
Collaborator

Choose a reason for hiding this comment

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

Due to the above mentioned changes, this path needs to be changed:

Suggested change
exec java $ARGS -jar /opt/kafdrop/kafdrop*.jar ${CMD_ARGS}
exec java $ARGS -jar /opt/kafdrop/kafdrop*/kafdrop*jar ${CMD_ARGS}