kaniko icon indicating copy to clipboard operation
kaniko copied to clipboard

Build arg value not included in the Docker image history

Open sisp opened this issue 5 years ago • 8 comments

I noticed that Kaniko does not include build arg values in the Docker image history while docker build does.

This is a minimal example:

  1. A simple Dockerfile:

    FROM alpine:latest
    ARG TOKEN
    RUN echo "$TOKEN" > token.txt \
        # Do something with the token
     && rm token.txt
    
  2. Build the Docker image ...

    • ... with Docker:

      $ docker build --build-arg TOKEN=t0k3n -t test:docker .
      
    • ... with Kaniko:

      $ /kaniko/executor \
          --context /path/to/context \
          --dockerfile /path/to/context/Dockerfile \
          --destination test:kaniko \
          --build-arg TOKEN=t0k3n
      
  3. Check the Docker image history ...

    • ... of the Docker-based image:

      $ docker history test:docker
      IMAGE               CREATED             CREATED BY                                      SIZE                
      COMMENT
      c2e78d4bb3ca        6 seconds ago       |1 TOKEN=t0k3n /bin/sh -c echo "$TOKEN" > to…   0B                  
      4d7c543079e9        7 seconds ago       /bin/sh -c #(nop)  ARG TOKEN                    0B                  
      a24bb4013296        3 weeks ago         /bin/sh -c #(nop)  CMD ["/bin/sh"]              0B                  
      <missing>           3 weeks ago         /bin/sh -c #(nop) ADD file:c92c248239f8c7b9b…   5.57MB              
      
    • ... of the Kaniko-based image:

      $ docker history test:kaniko
      IMAGE               CREATED             CREATED BY                                      SIZE                COMMENT
      996a9e52fa25        292 years ago       RUN echo "$TOKEN" > token.txt  && rm token.t…   0B                  
      <missing>           3 weeks ago         /bin/sh -c #(nop)  CMD ["/bin/sh"]              0B                  
      <missing>           3 weeks ago         /bin/sh -c #(nop) ADD file:c92c248239f8c7b9b…   5.57MB              
      

Docker introduced a new --secret flag in Docker 18.09 (when BuildKit is enabled) for first-class support of Docker build secrets: https://docs.docker.com/develop/develop-images/build_enhancements/

I wonder

  • whether Kaniko's behavior is intended and
  • whether Kaniko should support Docker build secrets.

sisp avatar Jun 20 '20 17:06 sisp

Incidentally for anyone looking into this: for a few build-arg names that you might try, standard docker build won't save them in the docker history. https://docs.docker.com/engine/reference/builder/#predefined-args (Everyone knows that, but I didn't know that, and it confused me when looking into this.)

dHannasch avatar Jul 24 '20 23:07 dHannasch

Hey @dHannasch that is very handy to know, I'm now passing a token via NO_PROXY to git until Kaniko has added a way of passing secrets into the build-job. I see that the history/ARG behavior is different for Kaniko, but using NO_PROXY will avoid developers accidentally having their tokens in the history when working on their local machine.

clushie avatar Oct 14 '20 12:10 clushie

Just double checking here - is this an intended feature?

I saw that BuildKit is doing something similar but more specific using a --secret argument https://docs.docker.com/develop/develop-images/build_enhancements/#new-docker-build-secret-information

If --build-arg is behaving as stated above then I'd say it's enough security wise, however it might be better to be more explicit same as BuildKit does.

What do you think?

Shaked avatar Nov 11 '20 18:11 Shaked

Also curious about whether this behavior is intentional! I'm happy it's working this way (kaniko keeping the build args out of the image history), but would like to know that this won't change in the future, or that there is an explicit way to ensure this behavior.

sethetter avatar Mar 25 '21 20:03 sethetter

same here, it would be great if the maintainers could clarify

adrian-gierakowski avatar Jul 12 '21 11:07 adrian-gierakowski

Compared to the trick of mounting secrets in /kaniko ( e.g. #489 ) we really prefer passing them as args or more explicitly with a --secret flag (Buildkit). Would be great to have the assurance that this behavior is intended and will stay as it is so we can rely on it.

fellhorn avatar Mar 03 '22 10:03 fellhorn

I'd also like to be able to rely on this from a security perspective

papb avatar Mar 15 '22 00:03 papb

Also interesting about this one.

fad3t avatar Mar 12 '25 08:03 fad3t