Skip to content

Commit 587c4eb

Browse files
ci: harden Java dedup Docker sample
Signed-off-by: Asish Kumar <officialasishkumar@gmail.com>
1 parent 86369f9 commit 587c4eb

3 files changed

Lines changed: 10 additions & 5 deletions

File tree

java-dedup/Dockerfile

Lines changed: 8 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -2,10 +2,15 @@ ARG JAVA_VERSION=8
22
FROM eclipse-temurin:${JAVA_VERSION}-jre
33

44
WORKDIR /app
5-
COPY target/java-dedup-0.0.1-SNAPSHOT.jar /app/app.jar
6-
COPY target/jacocoagent.jar /app/jacocoagent.jar
7-
COPY target/classes /app/target/classes
5+
6+
RUN groupadd --gid 10001 appuser \
7+
&& useradd --uid 10001 --gid 10001 --home-dir /home/appuser --create-home --shell /usr/sbin/nologin appuser
8+
9+
COPY --chown=10001:10001 target/java-dedup-0.0.1-SNAPSHOT.jar /app/app.jar
10+
COPY --chown=10001:10001 target/jacocoagent.jar /app/jacocoagent.jar
11+
COPY --chown=10001:10001 target/classes /app/target/classes
812

913
ENV KEPLOY_JAVA_CLASS_DIRS=/app/target/classes
1014
EXPOSE 8080
15+
USER 10001:10001
1116
ENTRYPOINT ["java", "-javaagent:/app/jacocoagent.jar=address=127.0.0.1,port=36320,destfile=/tmp/jacoco-keploy.exec,output=tcpserver", "-jar", "/app/app.jar"]

java-dedup/README.md

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -35,7 +35,7 @@ Run it with Docker Compose after the Maven package step has created `target/java
3535
docker compose up --build
3636
```
3737

38-
For a more restricted container run:
38+
The image runs as a non-root user. For a more restricted container run with a read-only root filesystem, dropped capabilities, `no-new-privileges`, and a writable `/tmp` tmpfs:
3939

4040
```bash
4141
docker compose -f docker-compose.yml -f docker-compose.restricted.yml up --build

java-dedup/docker-compose.restricted.yml

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -2,7 +2,7 @@ services:
22
java-dedup:
33
read_only: true
44
tmpfs:
5-
- /tmp
5+
- /tmp:rw,nosuid,nodev,mode=1777
66
cap_drop:
77
- ALL
88
security_opt:

0 commit comments

Comments
 (0)