Repository navigation
Description
Describe the bug
When testing different images to create containers with toolbox I have found that with some base images the start command of the container is not set correctly. When trying to enter to one of this containers the toolbox executable inside the container is not called.
I created an image based on parrotsec/core. When entering the toolbox the following error appears.
$ toolbox enter parrot
Error: invalid entry point PID of container parrot
When starting directly from podman, the output is the bash help output.
$ podman start --attach parrot
bash: --log-level: invalid option
Usage: bash [GNU long option] [option] ...
bash [GNU long option] [option] script-file ...
GNU long options:
--debug
--debugger
--dump-po-strings
--dump-strings
--help
--init-file
--login
--noediting
--noprofile
--norc
--posix
--pretty-print
--rcfile
--restricted
--verbose
--version
Shell options:
-ilrsD or -c command or -O shopt_option (invocation only)
-abefhkmnptuvxBCHP or -o option
After inspecting the container, and comparing to another container with a working image, there is a difference in the start path.
$ podman --log-level debug inspect --format json --type container <container>
Not working container looks like:
{
"Path": "/bin/sh",
"Args": [
"-c",
"bash $@",
"toolbox",
"--log-level",
"debug",
"init-container",
"--gid",
"1000",
"--home",
"/home/lopukhv",
"--shell",
"/bin/bash",
"--uid",
"1000",
"--user",
"lopukhv",
"--monitor-host"
]
}Working container look like:
{
"Path": "toolbox",
"Args": [
"--log-level",
"debug",
"init-container",
"--gid",
"1000",
"--home",
"/home/lopukhv",
"--shell",
"/bin/bash",
"--uid",
"1000",
"--user",
"lopukhv",
"--monitor-host"
],
}Steps how to reproduce the behaviour
- Build local image with provided Containerfile (
podman build -t parrot .) - Create a toolbox (
toolbox create -i localhost/parrot parrot) - Enter toolbox (
toolbox enter parrot) - Start container with podman (
podman start --attach parrot)
Expected behaviour
Container should be created with the appropriate start command and should start normally.
Actual behaviour
Container is not created with the appropriate start command, it is not possible to enter the toolbox.
Output of toolbox --version (v0.0.90+)
toolbox version 0.0.99.2
Toolbox package info (rpm -q toolbox)
toolbox-0.0.99.2-7.fc34.x86_64
Output of podman version
Version: 3.3.1
API Version: 3.3.1
Go Version: go1.16.6
Built: Mon Aug 30 22:46:36 2021
OS/Arch: linux/amd64
Podman package info (rpm -q podman)
podman-3.3.1-1.fc34.x86_64
Info about your OS
Fedora Workstation 34
Additional context
Containerfile
FROM docker.io/parrotsec/core
LABEL com.github.containers.toolbox="true" \
name="parrot-toolbox" \
version="rolling" \
usage="This image is meant to be used with the toolbox command" \
summary="Base image for creating Parrot Sec toolbox containers" \
maintainer="lopukhov <[email protected]>"
# Install extra packages
COPY extra-packages /
RUN apt-get update && \
DEBIAN_FRONTEND=noninteractive apt-get -y install $(<extra-packages)
RUN rm /extra-packages
# Allow authentication with empty password, promptless
RUN sed -i '/^auth.*pam_unix.so/s/nullok_secure/try_first_pass nullok/' /etc/pam.d/common-auth
RUN touch /etc/machine-id
CMD /bin/sh
extra-packages
bash
fish
zsh
git
libcap2-bin
libnss-myhostname
sudo
unzip
zip
Activity
debarshiray commentedon Nov 17, 2021
This indicates that somehow you are using the POSIX shell implementation of Toolbox and mixing it up with the Go implementation.
Only use the Go implementation. The other one is long gone. :)
debarshiray commentedon Nov 17, 2021
Closing.
Feel free to leave a comment or re-open if you have reason to believe otherwise.
lopukhov commentedon Nov 24, 2021
Thank you for the response.
I made sure that I was using the Go implementation of the tool.
After some more debugging I think I have found out the root cause:
When podman creates containers with a command like
With some images the command that gets assigned the following command
And with some other images the command that gets assigned is something like
I am not sure why it happens but with the Containerfile in my first post it generates the second one. This produces that
<arg1>and<arg2>get passed to bash instead of<command>.But when podman creates containers with a command like
the command that gets assigned is something like
bash -c "<command> <arg1> <arg2> ..."So the arguments get passed to
<command>as intended. I believe that it should be a simple fix, passingentryPointinstc/cmd/create.goas a string instead of as a slice of strings. I can create a PR this weekend if you think thats an appropiate solution.(Apologies if I was too verbose, I wanted to make sure my explanation was clear)
lopukhov commentedon Nov 24, 2021
@debarshiray I am not sure how would I re-open the issue or if i am able to
lopukhov commentedon Nov 25, 2021
Actually, a better solution would be to unset the entrypoint when creating the container. The other solution would include regressions with the Fedora images.
debarshiray commentedon Nov 26, 2021
Ok, many thanks for the detailed explanation. I can reproduce it now.
The problem originates from the
docker.io/parrotsec/core:latestimage that overrides the entry point of the image to be/bin/sh -c bash "$@". The idea is that the command gets appended to the entry point, and that's why we end up with such a strange command line.You can try to reset the entry point of the image to the default with something like:
We should document this in the
README.md.lopukhov commentedon Nov 28, 2021
When changing the entry point in the Containerfile as you suggested the problem still persists. The command when starting becomes
Which passes the arguments (like
init-container) to /bin/sh. So when starting the container withpodman start -a <name>, it prints the help message from toolbox.From what I have tested I see two solutions:
--entrypoint ""flag to thepodman create ...command. This would help with any other image that also sets the entrypoint also. I have not noticed any impact to other images, but right now my testing has been a little bit limited.README.mdin the image requirements the information that the entrypoint should not be set. And for this image in particular I can take it to upstream to see if it is possible to not set the entrypoint on base images.Do you see any other options? What do you see as the best option between 1 or 2?
images: Remove misleading and redundant CMD
debarshiray commentedon Nov 30, 2021
Oops! I got that wrong. It should be:
Note that there shouldn't be any space between the opening and closing brackets.
podman inspect --type image ...doesn't show any entry point, and the created container works as expected.I had gotten a bit confused because I read somewhere that
ENTRYPOINTdefaults tosh -c, which doesn't look true, and confused myself over how the command line arguments get passed around. Sorry about that.README.md: Update image requirements
debarshiray commentedon Dec 1, 2021
Since Toolbox only works with OCI images that fulfill certain requirements, I feel tempted to put this burden on the image. ie., the image should ensure that there's no entry point.
We can revisit this if it proves to be a problem in the long run.
I have done this now in #940
images: Remove misleading and redundant CMD
README.md: Update image requirements
[-]Incorrectly created containers with some custom images[/-][+]Images with an ENTRYPOINT produce a broken set of command line arguments for the container's entry point[/+]lopukhov commentedon Dec 3, 2021
That works! I thought that
ENTRYPOINT []was not valid. I agree with you in putting the burden on the image. Thank you.