Escaping double quote leads to 3 instead of 4 parameter

Viewed 1371

strace reveals that the escaping I used may cause a problem compared to the shell form (shell form vs exec form see https://docs.docker.com/engine/reference/builder/ )

exec form with [/* 3 vars */] - breaks / makes trouble

ENTRYPOINT ["strace", "hugo", "server", "--watch=true", "--bind=0.0.0.0", "--source=\"/src\"", "--destination=\"/output\""]
execve("hugo", ["hugo", "server", "--watch=true", "--bind=0.0.0.0", "--source=\"/src\"", "--destination=\"/output\""], [/* 3 vars */]) = 0

shell form with [/* 4 vars */] - works fine

ENTRYPOINT strace hugo server --watch=true --bind=0.0.0.0 --source=""/src"" --destination=""/output""
execve("hugo", ["hugo", "server", "--watch=true", "--bind=0.0.0.0", "--source=/src", "--destination=/output"], [/* 4 vars */]) = 0"

Dockerfile: (used ubuntu as i wasn't able to run strace with alpine:latest.)

# escape=\
# first line can be removed and doesn't change the behavior of the described issue
FROM ubuntu:latest
RUN apt-get update && apt-get install hugo strace
RUN hugo new site src
WORKDIR /src
ENTRYPOINT ["strace", "hugo", "server", "--watch=true", "--bind=0.0.0.0", "--source=\"/src\"", "--destination=\"/output\""]
EXPOSE 1313

Command to run and save output:

 sudo docker run --security-opt seccomp:unconfined docker-hugo &> docker-hugo.strace

(see https://github.com/moby/moby/issues/20064#issuecomment-291095117 for info regarding --security-opt )

Overview of possible scenarios:

+------------------+-------------------------------------------+------------------------+---------------------------------------------------+
|                  | No Entrypoint                             | Entrypoint (JSON-form) | Entrypoint (shell-form)                           |
+------------------+-------------------------------------------+------------------------+---------------------------------------------------+
| No CMD           | HostConfig.Config.cmd=/bin/bash is called | breaks                 | ok                                                |
|                  | (assumption as of docker inspect)         |                        |                                                   |
+------------------+-------------------------------------------+------------------------+---------------------------------------------------+
| CMD (JSON-form)  | breaks                                    | breaks                 | breaks                                            |
|                  |                                           |                        | (other issue; not handled here                    |
+------------------+-------------------------------------------+------------------------+---------------------------------------------------+
| CMD (shell-form) | ok                                        | ok                     | Breaks [seems to work as designed]                |
|                  |                                           |                        | (both are called with a shell concatinated)       |
|                  |                                           |                        | Example: /bin/sh -c <ENTRYPOINT> /bin/sh -c <CMD> |
+------------------+-------------------------------------------+------------------------+---------------------------------------------------+

So my question: Am I escaping the JSON Array not correctly?

0 Answers
Related