Closed savemuri closed 9 months ago
make sure the newuidmap
and newgidmap
binaries have the right capabilities set (i.e. the equivalent of rpm --setcaps shadow-utils
in the Containerfile you've linked) as it is specified in the warning message:
/usr/bin/newgidmap should be setgid or have filecaps setgid
Also make sure the file system that contains newuidmap and newgidmap is not mounted nosuid.
Thanks for the quick response. This fixed it for me. For future reference, here is a working Containerfile with ubuntu
FROM docker.io/ubuntu:22.04
# Configurations
ARG HOST_ARCH=amd64
ARG CONDA_VER=latest
ARG OS_TYPE=x86_64
ARG CONDA_ENV_NAME=deploy
ARG PYTHON_VERSION=3.10
# Setup enviroment variables
ENV NB_USER jovyan
ENV NB_UID 1000
ENV HOME=/home/$NB_USER
ENV PIP_NO_CACHE_DIR=off
ENV DEBUG_IGNORE_VERSION_MISMATCH="1"
ENV JAVA_HOME="/usr/lib/jvm/java-8-openjdk-amd64/jre/"
ENV SSH_HOME=/etc/ssh/$NB_USER
USER root
# Setup the user jovyan
RUN useradd -M -s /bin/bash -N -u ${NB_UID} ${NB_USER} \
&& mkdir -p ${HOME} && mkdir -p /etc/ssh/$NB_USER
# Install Ubuntu Packages
RUN export DEBIAN_FRONTEND=noninteractive \
&& apt-get -yq update \
&& apt-get remove --auto-remove -yq openjdk* \
&& apt-get purge -yq openjdk* \
&& apt-get install -yq \
lsb-release \
openjdk-8-jdk \
openjdk-8-jre \
curl \
git \
gnupg \
openssh-server \
&& apt-get autoremove -y \
&& apt-get remove --auto-remove -yq python3-blinker \
&& apt-get clean \
&& rm -rf /var/lib/apt/lists/*
# Install Podman
RUN key_url="https://download.opensuse.org/repositories/devel:/kubic:/libcontainers:/unstable/xUbuntu_22.04/Release.key" \
sources_url="https://download.opensuse.org/repositories/devel:/kubic:/libcontainers:/unstable/xUbuntu_22.04" \
&& echo "deb $sources_url/ /" | tee /etc/apt/sources.list.d/devel:kubic:libcontainers:unstable.list \
&& curl -fsSL $key_url | gpg --dearmor | tee /etc/apt/trusted.gpg.d/devel_kubic_libcontainers_unstable.gpg > /dev/null \
&& apt -yq update \
&& apt install -yq podman fuse-overlayfs buildah slirp4netns uidmap
RUN echo "${NB_USER}:1001:64535" > /etc/subuid && \
echo "${NB_USER}:1001:64535" > /etc/subgid
ARG _REPO_URL="https://raw.githubusercontent.com/containers/podman/main/contrib/podmanimage/stable"
ADD $_REPO_URL/containers.conf /etc/containers/containers.conf
ADD $_REPO_URL/podman-containers.conf /home/${NB_USER}/.config/containers/containers.conf
RUN apt-get install -y libcap2-bin && \
chmod 0755 /usr/bin/newuidmap /usr/bin/newgidmap && \
setcap cap_setuid=ep /usr/bin/newuidmap && \
setcap cap_setgid=ep /usr/bin/newgidmap && \
apt-get autoremove --purge -y libcap2-bin
RUN mkdir -p /home/${NB_USER}/.local/share/containers \
&& chmod 644 /etc/containers/containers.conf
RUN sed -e 's|^#mount_program|mount_program|g' \
-e '/additionalimage.*/a "/var/lib/shared",' \
-e 's|^mountopt[[:space:]]*=.*$|mountopt = "nodev,fsync=0"|g' \
/usr/share/containers/storage.conf \
> /etc/containers/storage.conf
# Setup internal Podman to pass subscriptions down from host to internal container
RUN printf '/run/secrets/etc-pki-entitlement:/run/secrets/etc-pki-entitlement\n/run/secrets/rhsm:/run/secrets/rhsm\n' > /etc/containers/mounts.conf
ENV _CONTAINERS_USERNS_CONFIGURED=""
# Setup Environment
RUN chown -R ${NB_USER}:users ${HOME} /usr/local/etc /usr/local/share \
&& if [ -d /opt/tritonserver ]; then chown -R ${NB_USER}:users /opt/tritonserver; fi
USER $NB_UID
CMD ["bin/sh", "-c", "while :; do echo '.'; sleep 5 ; done"]
And this post I found in another issue was helpful - https://samuel.forestier.app/blog/security/podman-rootless-in-podman-rootless-the-debian-way
Apologies for closing issue prematurely. The above solution lets me run podman pull
and podman push
commands. However I can't seem to be able to build or run an image as it fails as shown below
jovyan@savemuri-test-0:~$ podman run -it --rm docker.io/nginx:latest --entrypoint sh
WARN[0000] "/" is not a shared mount, this could cause issues or missing mounts with rootless containers
Trying to pull docker.io/library/nginx:latest...
Getting image source signatures
Copying blob dc9c4fdb83d6 done
Copying blob 8b7dd3ed1dc3 done
Copying blob 36664b6ce66b done
Copying blob 2f44b7a888fa done
Copying blob 2d455521f76c done
Copying blob 35497dd96569 done
Copying blob 8056d2bcf3b6 done
Copying config a8758716bb done
Writing manifest to image destination
Error: crun: mount `proc` to `proc`: Operation not permitted: OCI permission denied
This means podman is running within a mount namespace that the /proc has been modified. Podman wants to modify the /proc itself, which is not allowed by the kernel.
You could try a -v /proc:/proc
Thanks, that did get me past the issue. However when trying to run a docker build with /proc mounted, it lands to a different issue
STEP 1/2: FROM docker.io/ubuntu:22.04
STEP 2/2: RUN apt-get -yq update
E: setgroups 65534 failed - setgroups (22: Invalid argument)
E: setegid 65534 failed - setegid (22: Invalid argument)
Reading package lists...
E: setgroups 65534 failed - setgroups (22: Invalid argument)
E: setegid 65534 failed - setegid (22: Invalid argument)
E: Method gave invalid 400 URI Failure message: Failed to setgroups - setgroups (22: Invalid argument)
E: Method gave invalid 400 URI Failure message: Failed to setgroups - setgroups (22: Invalid argument)
E: Method http has died unexpectedly!
E: Sub-process http returned an error code (112)
Error: building at STEP "RUN apt-get -yq update": while running runtime: exit status 100
Containerfile that I am trying to build
FROM docker.io/ubuntu:22.04
RUN apt-get -yq update
let's not reuse the same issue for a different question.
Using -v /proc:/proc
means you cannot create a new PID namespace, otherwise the PIDs won't match, you need to add --pid=host
.
The other error you've reported seems like you've not enough GIDs available. Please verify that in the idMappings
field in the podman info
output, or check the ones currently available with cat /proc/self/gid_map
Issue Description
Issue with running podman on a rootless container in k8s.
Steps to reproduce the issue
Steps to reproduce the issue
Configurations
ARG HOST_ARCH=amd64 ARG OS_TYPE=x86_64 ARG PYTHON_VERSION=3.10
ENV JUPYTER_USER jovyan ENV NB_UID 1000 ENV HOME=/home/$JUPYTER_USER ENV JAVA_HOME="/usr/lib/jvm/java-8-openjdk-amd64/jre/" ENV SSH_HOME=/etc/ssh/$JUPYTER_USER
USER root
RUN useradd -M -s /bin/bash -N -u ${NB_UID} ${JUPYTER_USER} \ && mkdir -p ${HOME} && mkdir -p /etc/ssh/$JUPYTER_USER
RUN export DEBIAN_FRONTEND=noninteractive \ && apt-get -yq update \ && apt-get remove --auto-remove -yq openjdk \ && apt-get purge -yq openjdk \ && apt-get install -yq \ lsb-release \ openjdk-8-jdk \ openjdk-8-jre \ curl \ git \ gnupg \ openssh-server \ && apt-get autoremove -y \ && apt-get remove --auto-remove -yq python3-blinker \ && apt-get clean \ && rm -rf /var/lib/apt/lists/*
Install Podman
RUN key_url="https://download.opensuse.org/repositories/devel:/kubic:/libcontainers:/unstable/xUbuntu_22.04/Release.key" \ sources_url="https://download.opensuse.org/repositories/devel:/kubic:/libcontainers:/unstable/xUbuntu_22.04" \ && echo "deb $sources_url/ /" | tee /etc/apt/sources.list.d/devel:kubic:libcontainers:unstable.list \ && curl -fsSL $key_url | gpg --dearmor | tee /etc/apt/trusted.gpg.d/devel_kubic_libcontainers_unstable.gpg > /dev/null \ && apt -yq update \ && apt install -yq podman fuse-overlayfs buildah
RUN echo -e "${JUPYTER_USER}:1:999\n${JUPYTER_USER}:1001:64535" > /etc/subuid \ && echo -e "${JUPYTER_USER}:1:999\n${JUPYTER_USER}:1001:64535" > /etc/subgid
ARG _REPO_URL="https://raw.githubusercontent.com/containers/podman/main/contrib/podmanimage/stable" ADD $_REPO_URL/containers.conf /etc/containers/containers.conf ADD $_REPO_URL/podman-containers.conf /home/${JUPYTER_USER}/.config/containers/containers.conf
RUN mkdir -p /home/${JUPYTER_USER}/.local/share/containers \ && chmod 644 /etc/containers/containers.conf
RUN sed -e 's|^#mount_program|mount_program|g' \ -e '/additionalimage./a "/var/lib/shared",' \ -e 's|^mountopt[[:space:]]=.*$|mountopt = "nodev,fsync=0"|g' \ /usr/share/containers/storage.conf \
Setup internal Podman to pass subscriptions down from host to internal container
RUN printf '/run/secrets/etc-pki-entitlement:/run/secrets/etc-pki-entitlement\n/run/secrets/rhsm:/run/secrets/rhsm\n' > /etc/containers/mounts.conf
ENV _CONTAINERS_USERNS_CONFIGURED=""
RUN chown -R ${JUPYTER_USER}:users ${HOME} /usr/local/etc /usr/local/share
USER $NB_UID
CMD ["bin/sh", "-c", "while :; do echo '.'; sleep 5 ; done"]
jovyan@sasank-test-0:~$ podman pull docker.io/nginx:latest WARN[0000] "/" is not a shared mount, this could cause issues or missing mounts with rootless containers ERRO[0000] running
/usr/bin/newuidmap 456 0 1000 1 1 1 999 1000 1001 64535
: newuidmap: write to uid_map failed: Operation not permitted Error: cannot set up namespace using "/usr/bin/newuidmap": exit status 1jovyan@sasank-test-0:~$ buildah unshare WARN[0000] running newgidmap: exit status 1: newgidmap: write to gid_map failed: Operation not permitted WARN[0000] /usr/bin/newgidmap should be setgid or have filecaps setgid WARN[0000] Falling back to single mapping
WARN[0000] Error running newuidmap: exit status 1: newuidmap: write to uid_map failed: Operation not permitted WARN[0000] Falling back to single mapping
root@sasank-test-0:~# podman --storage-opt mount_program=/usr/bin/fuse-overlayfs --storage-opt ignore_chown_errors=true run -it --rm docker.io/library/python:latest Trying to pull docker.io/library/python:latest... Getting image source signatures Copying blob fa6efb383f81 done
Copying blob 1c74526957fc done
Copying blob ad5739181616 done
Copying blob 1b13d4e1a46e done
Copying blob 30d855997954 done
Copying blob 75e2b45cbee5 done
Copying blob 0c6213e9c29b done
Copying blob 1b1e18053fdc done
Copying config e7177b0afd done
Writing manifest to image destination WARN[0014] Path "/run/secrets/etc-pki-entitlement" from "/etc/containers/mounts.conf" doesn't exist, skipping WARN[0014] Path "/run/secrets/rhsm" from "/etc/containers/mounts.conf" doesn't exist, skipping Error: crun: mount
proc
toproc
: Operation not permitted: OCI permission denied