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

Adding a rule to restrict an image to build without adding a non-root user. #989

Open
sharmar0790 opened this issue Nov 14, 2023 · 0 comments

Comments

@sharmar0790
Copy link

This is a feature request to add a hadolint rule, so we can restrict building an image or throw the error while linting an image. This rule will basically check whether in the image user has configure the non-root user or not. As we know, when we build the image and not creating a non-root user then by default image will inherit the root user from base image which is not good from a security point of view. So we should add a rule to restrict the image building if user does not create a non-root user in the image.

https://docs.docker.com/develop/develop-images/instructions/#user

Expected behavior

Throw the error if user do not configure the non-root user in the Dockerfile.

Actual behavior

There is no such rule. If user is not creating a non-root user in Dockerfile, still hadolint pass the check.

Steps to reproduce the behavior

  1. Create a Dockerfile
FROM maven:3.8.1-openjdk-17-slim as builder

WORKDIR /build
COPY . /build

RUN mvn dependency:go-offline package -DskipTests=true #remove -DskipTests=true to run the tests while building image

# Step : Package image
FROM openjdk:17-slim
COPY --from=builder /build/target/*.jar /app/app.jar
EXPOSE 9090
#CMD exec java $JAVA_OPTS -jar /app/app.jar
ENV JAVA_OPTS=""
ENTRYPOINT [ "sh", "-c", "java $JAVA_OPTS -jar /app/app.jar ${0} ${@}"
  1. Run hadolint Dockerfile
  2. It will pass the check even though there is no command to create a non-root user/group.
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

No branches or pull requests

1 participant