Description
Briefly describe the problem you are having in a few paragraphs.
When I spin up the docker container on the single/standalone server with below command, I am able to perform all my task mentioned in Dockerfile such as pulling, building and pushing the image onto registry:
FYI - I pulled the docker image "tomkukral/buildah" from https://hub.docker.com/r/tomkukral/buildah
It works fine with below
```docker run --rm --privileged -it tomkukral/buildah bash
Inside container:
buildah bud -t ${IMAGENAME}
buildah push --creds ${registryUSER}:${registryPASS} ${IMAGENAME}
On the other hand, when I run this with k8s, I have been facing a write operations issue with buildah such as below:
Error:
13:23:39 STEP 5: RUN mkdir /apps
13:23:39 error running container: error creating container for [/bin/sh -c mkdir /apps]: container_linux.go:344: starting container process caused "process_linux.go:275: applying cgroup configuration for process caused "mkdir /sys/fs/cgroup/cpuset/buildah-buildah005644356: read-only file system""
13:23:39 : exit status 1
For more detailed logs/info:
While running with k8s, getting below mount points in readonly mode:
sysfs on /sys type sysfs (ro,nosuid,nodev,noexec,relatime,seclabel)
tmpfs on /sys/fs/cgroup type tmpfs (ro,nosuid,nodev,noexec,relatime,seclabel,mode=755)
cgroup on /sys/fs/cgroup/systemd type cgroup (ro,nosuid,nodev,noexec,relatime,seclabel,xattr,release_agent=/usr/lib/systemd/systemd-cgroups-agent,name=systemd)
cgroup on /sys/fs/cgroup/cpuset type cgroup (ro,nosuid,nodev,noexec,relatime,seclabel,cpuset)
Whereas, with docker container:
Getting below mount points in read+write mode, which is helping to create docker image using buildah container:
sysfs on /sys type sysfs (rw,nosuid,nodev,noexec,relatime)
tmpfs on /sys/fs/cgroup type tmpfs (rw,nosuid,nodev,noexec,relatime,mode=755)
cpuset on /sys/fs/cgroup/cpuset type cgroup (rw,nosuid,nodev,noexec,relatime,cpuset)
cgroup on /sys/fs/cgroup/systemd type cgroup (rw,nosuid,nodev,noexec,relatime,name=systemd)
**Steps to reproduce the issue:**
1. Running POD with buildah container with k8s
2.
3.
**Describe the results you received:**
While running with k8s, getting below mount points in readonly mode:
sysfs on /sys type sysfs (ro,nosuid,nodev,noexec,relatime,seclabel)
tmpfs on /sys/fs/cgroup type tmpfs (ro,nosuid,nodev,noexec,relatime,seclabel,mode=755)
cgroup on /sys/fs/cgroup/systemd type cgroup (ro,nosuid,nodev,noexec,relatime,seclabel,xattr,release_agent=/usr/lib/systemd/systemd-cgroups-agent,name=systemd)
cgroup on /sys/fs/cgroup/cpuset type cgroup (ro,nosuid,nodev,noexec,relatime,seclabel,cpuset)
**Describe the results you expected:**
With the k8s, I should be able to get the mount points in read+write mode as same as spinninig
**Output of `rpm -q buildah` or `apt list buildah`:**
buildah-1.7-2.git873f001.fc29.x86_64
**Output of `buildah version`:**
Version: 1.7
Go Version: go1.11.5
Image Spec: 1.0.0
Runtime Spec: 1.0.0
CNI Spec: 0.4.0
libcni Version:
Git Commit:
Built: Thu Jan 1 00:00:00 1970
OS/Arch: linux/amd64
**Output of `podman version` if reporting a `podman build` issue:**
Version: 1.1.2
RemoteAPI Version: 1
Go Version: go1.11.5
Git Commit: a95a49d3038462d033f84ac314ec8a3064a99cff
Built: Tue Mar 5 18:10:31 2019
OS/Arch: linux/amd64
**Output of `cat /etc/*release`:**
Fedora release 29 (Twenty Nine)
NAME=Fedora
VERSION="29 (Container Image)"
ID=fedora
VERSION_ID=29
VERSION_CODENAME=""
PLATFORM_ID="platform:f29"
PRETTY_NAME="Fedora 29 (Container Image)"
ANSI_COLOR="0;34"
LOGO=fedora-logo-icon
CPE_NAME="cpe:/o:fedoraproject:fedora:29"
HOME_URL="https://fedoraproject.org/"
DOCUMENTATION_URL="https://docs.fedoraproject.org/en-US/fedora/f29/system-administrators-guide/"
SUPPORT_URL="https://fedoraproject.org/wiki/Communicating_and_getting_help"
BUG_REPORT_URL="https://bugzilla.redhat.com/"
REDHAT_BUGZILLA_PRODUCT="Fedora"
REDHAT_BUGZILLA_PRODUCT_VERSION=29
REDHAT_SUPPORT_PRODUCT="Fedora"
REDHAT_SUPPORT_PRODUCT_VERSION=29
PRIVACY_POLICY_URL="https://fedoraproject.org/wiki/Legal:PrivacyPolicy"
VARIANT="Container Image"
VARIANT_ID=container
Fedora release 29 (Twenty Nine)
Fedora release 29 (Twenty Nine)
**Output of `uname -a`:**
Linux 67b1eed5d8d6 4.9.125-linuxkit #1 SMP Fri Sep 7 08:20:28 UTC 2018 x86_64 x86_64 x86_64 GNU/Linux
**Output of `cat /etc/containers/storage.conf`:**
[storage]
driver = "overlay"
runroot = "/var/run/containers/storage"
graphroot = "/var/lib/containers/storage"
[storage.options]
additionalimagestores = [
]
size = ""
mount_program = "/usr/bin/fuse-overlayfs"
override_kernel_check = "true"
mountopt = "root"
#
#
[storage.options.thinpool]
ostree_repo = ""
skip_mount_home = "false"
```
@sourabhsharma487 I really do not know what you are reporting here. What buildah commands were you trying to run in a container. We are working on documenting how to run buildah within a locked down container. But most people currently need to do it in a privileged container. With /var/lib/containers volume mounted in.
@rhatdan : My bad, I had updated the issue with proper information however that Description block was commented. Please have a look at the description and let me know in case further information is required.
@sourabhsharma487 Inside a locked down container we are recommending that people use
buildah bud --isolation chroot ...
Which might get your further.
The Buildah container we are experimenting with has BUILDAH_ISOLATION=chroot environment variable set. We have also found SELinux issues with this, so make sure you have the latest container-selinux-2.94 installed, (If you are running with SELinux).
@TomSweeneyRedHat Could you paste in the Dockerfile we are using now for the experiments.
@sourabhsharma487 We've a Demo in progress that covers this: https://github.com/containers/Demos/pull/17
However @rhatdan found an issue with the way volumes were being recursively bind mounted, so I changed the Dockerfile from that script to build Buildah from GitHub and to pull in a PR that I'd put together. This is all a big WIP, no production machines should come near this. I'm still having issues getting stuff to run fully, but it's closer.
# cat /root/Dockerfile.plus
FROM fedora
ENV GOPATH=/root/buildah
#RUN yum -y install buildah --exclude container-selinux --enablerepo updates-testing; rm -rf /var/cache /var/log/dnf* /var/log/yum.*
RUN dnf -y install --enablerepo=updates-testing \
make \
golang \
bats \
btrfs-progs-devel \
device-mapper-devel \
glib2-devel \
gpgme-devel \
libassuan-devel \
libseccomp-devel \
ostree-devel \
git \
bzip2 \
go-md2man \
runc \
fuse-overlayfs \
fuse3 \
containers-common; \
mkdir /root/buildah; \
git clone https://github.com/containers/buildah /root/buildah/src/github.com/containers/buildah; \
cd /root/buildah/src/github.com/containers/buildah; \
git checkout -b TomSweeneyRedHat-dev/tsweeney/cinc master;\
git pull https://github.com/TomSweeneyRedHat/buildah.git dev/tsweeney/cinc;\
make;\
make install
RUN sed 's|^#mount_program|mount_program|g' -i /etc/containers/storage.conf
ENV _BUILDAH_STARTED_IN_USERNS="" BUILDAH_ISOLATION=chroot
COPY Dockerfile.plus /root
Then to run it:
podman build -t buildahimage -f /root/Dockerfile.plus .
podman run --net=host --device=/dev/fuse -v /var/lib/mycontainers:/var/lib/containers:Z -ti --uidmap 0:5000:1000 buildahimage buildah --debug bud -f /root/Dockerfile.plus --isolation=chroot /root
You can remove the --debug from the second line to get a little less output. Currently it's having a problem bind mouting /dev
@rhatdan , @TomSweeneyRedHat : After adding "--isolation chroot " in buildah bud command as below, I am getting a different error:
buildah bud --isolation chroot -t ${IMAGENAME} .
Error
20:56:48 STEP 5: RUN mkdir /apps /root/.ssh
20:56:48 process exited with error: fork/exec /bin/sh: no such file or directorysubprocess exited with status 1
Just for quick oversight on this, I have updated my k8s YAML with below securityContext but no luck:
securityContext:
privileged: true
runAsUser: 0
fsGroup: 0
capabilities:
add: ["SYS_ADMIN"]
FYI - I don`t see any challenge with standalone docker, however, it is an issue while running with kubernetes (k8s) only.
Please, can you help me with this? Appreciate your quick help.
@sourabhsharma487 Could you try this with Podman and make sure we can get it to work there, Then we can attempt this in K8s.
Hi @rhatdan : I managed myself fixing and running buildah container on k8s to create docker image(s) successfully by adding the following parameters:
spec:
volumes:
- name: volume
containers:
- name: buildah-image
image: <REGISTRY_NAME>/<IMAGE_NAME>:<TAG>
imagePullPolicy: Always
securityContext:
privileged: true
args:
command: [ "sleep", "infinity" ]
env:
resources:
requests:
cpu: 250m
memory: 500Mi
volumeMounts:
- mountPath: /var/lib/containers
name: volume
command:
- cat
tty: true
I am attaching this k8s sample template so that if anyone else tries to run buildah container on k8s may use this and this will help for sure to run it on k8s.
Closing this Issue now.
I am also seeing this error:
➜ docker run -it --privileged quay.io/buildah/stable:v1.9.0
[root@aa04fe2dafff /]# buildah bud -t foo:latest .
STEP 1: FROM alpine
Getting image source signatures
Copying blob 921b31ab772b done
Copying config 4d90542f06 done
Writing manifest to image destination
Storing signatures
STEP 2: RUN date
process exited with error: fork/exec /bin/sh: no such file or directorysubprocess exited with status 1
error building at STEP "RUN date": exit status 1
[root@aa04fe2dafff /]# cat Dockerfile
FROM alpine
RUN date
[root@aa04fe2dafff /]#
@marshallford This worked for me, but I think the seccomp bit is not happy in k8s:
podman run -it --rm --security-opt label=disable --security-opt seccomp=unconfined --device /dev/fuse:rw -v /var/lib/mycontainer:/var/lib/containers:Z quay.io/buildah/stable
@TomSweeneyRedHat Thanks. Apologizes for the similar questions in multiple threads. I was trying to tie similar errors together. See my comments here: https://github.com/containers/buildah/issues/1335#issuecomment-501537272 for a better explanation of what I am trying to accomplish. Day job security policies around limiting container permissions in k8s is driving a lot of my questions and confusion.
I've just seen this problem in quay.io/buildah/stable:v1.10.1 and quay.io/buildah/stable:latest. Reverting to quay.io/buildah/stable:v1.10.0 has fixed it for me.
Most helpful comment
Hi @rhatdan : I managed myself fixing and running buildah container on k8s to create docker image(s) successfully by adding the following parameters:
I am attaching this k8s sample template so that if anyone else tries to run buildah container on k8s may use this and this will help for sure to run it on k8s.
Closing this Issue now.