mirror of
https://github.com/iv-org/inv_sig_helper.git
synced 2025-01-30 15:01:35 +01:00
Docker: further security hardening
- Run as a non-privileged user within the scratch container - Add security_opt: - no-new-privileges:true to docker-compose.yml
This commit is contained in:
parent
6a07a2f47c
commit
1329745627
2 changed files with 15 additions and 1 deletions
13
Dockerfile
13
Dockerfile
|
@ -24,19 +24,30 @@ RUN RUST_TARGET=$(rustc -vV | sed -n 's/host: //p') && \
|
|||
rustup target add $RUST_TARGET && \
|
||||
RUSTFLAGS='-C target-feature=+crt-static' cargo build --release --target $RUST_TARGET
|
||||
|
||||
# Create a new stage for a smaller final image
|
||||
# Stage for creating the non-privileged user
|
||||
FROM alpine:3.20 AS user-stage
|
||||
|
||||
RUN adduser -u 10001 -S appuser
|
||||
|
||||
# Stage for a smaller final image
|
||||
FROM scratch
|
||||
|
||||
# Copy necessary files from the builder stage, using the correct architecture path
|
||||
COPY --from=builder /usr/src/app/target/*/release/inv_sig_helper_rust /app/inv_sig_helper_rust
|
||||
COPY --from=builder /etc/ssl/certs/ca-certificates.crt /etc/ssl/certs/
|
||||
|
||||
# Copy passwd file for the non-privileged user from the user-stage
|
||||
COPY --from=user-stage /etc/passwd /etc/passwd
|
||||
|
||||
# Set the working directory
|
||||
WORKDIR /app
|
||||
|
||||
# Expose port 12999
|
||||
EXPOSE 12999
|
||||
|
||||
# Switch to non-privileged user
|
||||
USER appuser
|
||||
|
||||
# Set the entrypoint to the binary name
|
||||
ENTRYPOINT ["/app/inv_sig_helper_rust"]
|
||||
|
||||
|
|
|
@ -11,3 +11,6 @@ services:
|
|||
cap_drop:
|
||||
- ALL
|
||||
read_only: true
|
||||
user: 10001:10001
|
||||
security_opt:
|
||||
- no-new-privileges:true
|
||||
|
|
Loading…
Add table
Reference in a new issue