buildah: Rootless buildah/stable image not working

Description I cannot run buildah as the non-root user in a podman container locally. It fails to run setuid/setgid.

The issue does not happen if I use the default root user.

Sorry for this issue I see you get a lot; however I have gone through a number of issues and documentation over the last couple days and had no luck.

Rolling back to version 1.16.2 fixes the warnings printed at the top error running new{g,u}idmap. That warning is introduced in version 1.17.0 and later. But the final error is the same.

I tried version 1.14.8 since I noticed it is used in this rootless tutorial. It seemed to go through the whole Containerfile before failing (rather than failing after failing to write the first layer) but failed in the end the same.

I also tried podman with --runtime crun from here but that didn’t fix it either.

Describe the results you received:

[ /src/redhat-actions/openshift-actions-runner-chart ] 03 (main) $ podman run --user build --entrypoint=/bin/bash -it quay.io/buildah/stable:v1.19.6
[build@ee048e1df20d /]$ cd /home/build
[build@ee048e1df20d ~]$ cat > Containerfile.test <<EOF
> FROM fedora:33
> RUN ls -l /test-script.sh
> RUN /test-script.sh "Hello world"
> RUN dnf update -y | tee /output/update-output.txt
> RUN dnf install -y gcc
> EOF
[build@ee048e1df20d ~]$ buildah bud ./Containerfile.test 
WARN error running newgidmap: exit status 1: newgidmap: write to gid_map failed: Operation not permitted 
WARN falling back to single mapping               
WARN error running newuidmap: exit status 1: newuidmap: write to uid_map failed: Operation not permitted 
WARN falling back to single mapping               
STEP 1: FROM fedora:33
Resolved "fedora" as an alias (/etc/containers/registries.conf.d/shortnames.conf)
Getting image source signatures
Copying blob 157ab8011454 done  
Copying config 9f2a560376 done  
Writing manifest to image destination
Storing signatures
error creating build container: Error committing the finished image: error adding layer with blob "sha256:157ab801145489f145f258148bd135102a3294e420f1859a39e824e7cda56b2f": Error processing tar file(exit status 1): potentially insufficient UIDs or GIDs available in user namespace (requested 0:35 for /usr/libexec/utempter): Check /etc/subuid and /etc/subgid: lchown /usr/libexec/utempter: invalid argument
ERRO exit status 125                              
[build@ee048e1df20d ~]$

Describe the results you expected: A successful build

Output of rpm -q buildah or apt list buildah:

(inside container)

buildah-1.19.6-2.fc33.x86_64

Output of buildah version: (inside container)

Version:         1.19.6
Go Version:      go1.15.8
Image Spec:      1.0.1-dev
Runtime Spec:    1.0.2-dev
CNI Spec:        0.4.0
libcni Version:  
image Version:   5.10.2
Git Commit:      
Built:           Thu Jan  1 00:00:00 1970
OS/Arch:         linux/amd64

Output of podman version if reporting a podman build issue: (outside container, because I used podman to run it. No podman inside container)

[ /src/redhat-actions/openshift-actions-runner-chart ] 11 (main) $ podman version
Version:      3.0.1
API Version:  3.0.0
Go Version:   go1.15.8
Built:        Fri Feb 19 11:56:17 2021
OS/Arch:      linux/amd64

Output of cat /etc/*release: (inside container)

Fedora release 33 (Thirty Three)
NAME=Fedora
VERSION="33 (Container Image)"
ID=fedora
VERSION_ID=33
VERSION_CODENAME=""
PLATFORM_ID="platform:f33"
PRETTY_NAME="Fedora 33 (Container Image)"
ANSI_COLOR="0;38;2;60;110;180"
LOGO=fedora-logo-icon
CPE_NAME="cpe:/o:fedoraproject:fedora:33"
HOME_URL="https://fedoraproject.org/"
DOCUMENTATION_URL="https://docs.fedoraproject.org/en-US/fedora/f33/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=33
REDHAT_SUPPORT_PRODUCT="Fedora"
REDHAT_SUPPORT_PRODUCT_VERSION=33
PRIVACY_POLICY_URL="https://fedoraproject.org/wiki/Legal:PrivacyPolicy"
VARIANT="Container Image"
VARIANT_ID=container
Fedora release 33 (Thirty Three)
Fedora release 33 (Thirty Three)

Output of uname -a: (inside container)

Linux 5f0791d24923 5.10.15-200.fc33.x86_64 #1 SMP Wed Feb 10 17:46:55 UTC 2021 x86_64 x86_64 x86_64 GNU/Linux

Output of cat /etc/containers/storage.conf: (inside container)

# This file is is the configuration file for all tools
# that use the containers/storage library.
# See man 5 containers-storage.conf for more information
# The "container storage" table contains all of the server options.
[storage]

# Default Storage Driver, Must be set for proper operation.
driver = "overlay"

# Temporary storage location
runroot = "/run/containers/storage"

# Primary Read/Write location of container storage
graphroot = "/var/lib/containers/storage"

# Storage path for rootless users
#
# rootless_storage_path = "$HOME/.local/share/containers/storage"

[storage.options]
# Storage options to be passed to underlying storage drivers

# AdditionalImageStores is used to pass paths to additional Read/Only image stores
# Must be comma separated list.
additionalimagestores = [
"/var/lib/shared",
]

# Remap-UIDs/GIDs is the mapping from UIDs/GIDs as they should appear inside of
# a container, to the UIDs/GIDs as they should appear outside of the container,
# and the length of the range of UIDs/GIDs.  Additional mapped sets can be
# listed and will be heeded by libraries, but there are limits to the number of
# mappings which the kernel will allow when you later attempt to run a
# container.
#
# remap-uids = 0:1668442479:65536
# remap-gids = 0:1668442479:65536

# Remap-User/Group is a user name which can be used to look up one or more UID/GID
# ranges in the /etc/subuid or /etc/subgid file.  Mappings are set up starting
# with an in-container ID of 0 and then a host-level ID taken from the lowest
# range that matches the specified name, and using the length of that range.
# Additional ranges are then assigned, using the ranges which specify the
# lowest host-level IDs first, to the lowest not-yet-mapped in-container ID,
# until all of the entries have been used for maps.
#
# remap-user = "containers"
# remap-group = "containers"

# Root-auto-userns-user is a user name which can be used to look up one or more UID/GID
# ranges in the /etc/subuid and /etc/subgid file.  These ranges will be partitioned
# to containers configured to create automatically a user namespace.  Containers
# configured to automatically create a user namespace can still overlap with containers
# having an explicit mapping set.
# This setting is ignored when running as rootless.
# root-auto-userns-user = "storage"
#
# Auto-userns-min-size is the minimum size for a user namespace created automatically.
# auto-userns-min-size=1024
#
# Auto-userns-max-size is the minimum size for a user namespace created automatically.
# auto-userns-max-size=65536

[storage.options.overlay]
# ignore_chown_errors can be set to allow a non privileged user running with
# a single UID within a user namespace to run containers. The user can pull
# and use any image even those with multiple uids.  Note multiple UIDs will be
# squashed down to the default uid in the container.  These images will have no
# separation between the users in the container. Only supported for the overlay
# and vfs drivers.
#ignore_chown_errors = "false"

# Path to an helper program to use for mounting the file system instead of mounting it
# directly.
mount_program = "/usr/bin/fuse-overlayfs"

# mountopt specifies comma separated list of extra mount options
mountopt = "nodev,fsync=0"

# Set to skip a PRIVATE bind mount on the storage home directory.
# skip_mount_home = "false"

# Size is used to set a maximum size of the container image.
# size = ""

# ForceMask specifies the permissions mask that is used for new files and
# directories.
#
# The values "shared" and "private" are accepted.
# Octal permission masks are also accepted.
#
#  "": No value specified.
#     All files/directories, get set with the permissions identified within the
#     image.
#  "private": it is equivalent to 0700.
#     All files/directories get set with 0700 permissions.  The owner has rwx
#     access to the files. No other users on the system can access the files.
#     This setting could be used with networked based homedirs.
#  "shared": it is equivalent to 0755.
#     The owner has rwx access to the files and everyone else can read, access
#     and execute them. This setting is useful for sharing containers storage
#     with other users.  For instance have a storage owned by root but shared
#     to rootless users as an additional store.
#     NOTE:  All files within the image are made readable and executable by any
#     user on the system. Even /etc/shadow within your image is now readable by
#     any user.
#
#   OCTAL: Users can experiment with other OCTAL Permissions.
#
#  Note: The force_mask Flag is an experimental feature, it could change in the
#  future.  When "force_mask" is set the original permission mask is stored in
#  the "user.containers.override_stat" xattr and the "mount_program" option must
#  be specified. Mount programs like "/usr/bin/fuse-overlayfs" present the
#  extended attribute permissions to processes within containers rather then the
#  "force_mask"  permissions.
#
# force_mask = ""

[storage.options.thinpool]
# Storage Options for thinpool

# autoextend_percent determines the amount by which pool needs to be
# grown. This is specified in terms of % of pool size. So a value of 20 means
# that when threshold is hit, pool will be grown by 20% of existing
# pool size.
# autoextend_percent = "20"

# autoextend_threshold determines the pool extension threshold in terms
# of percentage of pool size. For example, if threshold is 60, that means when
# pool is 60% full, threshold has been hit.
# autoextend_threshold = "80"

# basesize specifies the size to use when creating the base device, which
# limits the size of images and containers.
# basesize = "10G"

# blocksize specifies a custom blocksize to use for the thin pool.
# blocksize="64k"

# directlvm_device specifies a custom block storage device to use for the
# thin pool. Required if you setup devicemapper.
# directlvm_device = ""

# directlvm_device_force wipes device even if device already has a filesystem.
# directlvm_device_force = "True"

# fs specifies the filesystem type to use for the base device.
# fs="xfs"

# log_level sets the log level of devicemapper.
# 0: LogLevelSuppress 0 (Default)
# 2: LogLevelFatal
# 3: LogLevelErr
# 4: LogLevelWarn
# 5: LogLevelNotice
# 6: LogLevelInfo
# 7: LogLevelDebug
# log_level = "7"

# min_free_space specifies the min free space percent in a thin pool require for
# new device creation to succeed. Valid values are from 0% - 99%.
# Value 0% disables
# min_free_space = "10%"

# mkfsarg specifies extra mkfs arguments to be used when creating the base
# device.
# mkfsarg = ""

# metadata_size is used to set the `pvcreate --metadatasize` options when
# creating thin devices. Default is 128k
# metadata_size = ""

# Size is used to set a maximum size of the container image.
# size = ""

# use_deferred_removal marks devicemapper block device for deferred removal.
# If the thinpool is in use when the driver attempts to remove it, the driver
# tells the kernel to remove it as soon as possible. Note this does not free
# up the disk space, use deferred deletion to fully remove the thinpool.
# use_deferred_removal = "True"

# use_deferred_deletion marks thinpool device for deferred deletion.
# If the device is busy when the driver attempts to delete it, the driver
# will attempt to delete device every 30 seconds until successful.
# If the program using the driver exits, the driver will continue attempting
# to cleanup the next time the driver is used. Deferred deletion permanently
# deletes the device and all data stored in device will be lost.
# use_deferred_deletion = "True"

# xfs_nospace_max_retries specifies the maximum number of retries XFS should
# attempt to complete IO when ENOSPC (no space) error is returned by
# underlying storage device.
# xfs_nospace_max_retries = "0"

Other debug output

[build@5f0791d24923 /]$ capsh --print
Current: =
Bounding set =cap_chown,cap_dac_override,cap_fowner,cap_fsetid,cap_kill,cap_setgid,cap_setuid,cap_setpcap,cap_net_bind_service,cap_sys_chroot,cap_setfcap
Ambient set =
Current IAB: !cap_dac_read_search,!cap_linux_immutable,!cap_net_broadcast,!cap_net_admin,!cap_net_raw,!cap_ipc_lock,!cap_ipc_owner,!cap_sys_module,!cap_sys_rawio,!cap_sys_ptrace,!cap_sys_pacct,!cap_sys_admin,!cap_sys_boot,!cap_sys_nice,!cap_sys_resource,!cap_sys_time,!cap_sys_tty_config,!cap_mknod,!cap_lease,!cap_audit_write,!cap_audit_control,!cap_mac_override,!cap_mac_admin,!cap_syslog,!cap_wake_alarm,!cap_block_suspend,!cap_audit_read,!cap_perfmon,!cap_bpf,!cap_checkpoint_restore
Securebits: 00/0x0/1'b0 (no-new-privs=0)
 secure-noroot: no (unlocked)
 secure-no-suid-fixup: no (unlocked)
 secure-keep-caps: no (unlocked)
 secure-no-ambient-raise: no (unlocked)
uid=1000(build) euid=1000(build)
gid=1000(build)
groups=
Guessed mode: UNCERTAIN (0)
[build@5f0791d24923 /]$ cat /etc/sub{u,g}id
build:100000:65536
build:100000:65536
[build@5f0791d24923 /]$ dnf list shadow-utils
Fedora 33 openh264 (From Cisco) - x86_64                                                                                       6.1 kB/s | 2.5 kB     00:00    
Fedora Modular 33 - x86_64                                                                                                     3.2 MB/s | 3.3 MB     00:01    
Fedora Modular 33 - x86_64 - Updates                                                                                           5.9 MB/s | 3.1 MB     00:00    
Fedora 33 - x86_64 - Updates                                                                                                   1.9 MB/s |  24 MB     00:12    
Fedora 33 - x86_64                                                                                                             4.9 MB/s |  72 MB     00:14    
Installed Packages
shadow-utils.x86_64                                                           2:4.8.1-5.fc33                                                           @updates
[build@5f0791d24923 /]$

About this issue

  • Original URL
  • State: closed
  • Created 3 years ago
  • Comments: 26 (18 by maintainers)

Most upvoted comments

welll…I only waisted 3 hours of my life trying to figure out why my rootlest buildah bud builds inside a container stopped working between buildah 1.15 and 1.19 when i finally found this issue. Doing the dnf reinstall shadow-utils did the trick for me. though I still don’t understand why.

Thank you for this document; I have struggled with the same issue for days on my own image in which I wanted to use buildah. I only got it to work by picking apart the buildah image on quay.io … and finding the odd uid range of 2000:50000. When I did this, it worked for me in my own image. Then I googled that (2000:50000) to see if there is any information why this is important… and it led immediately to this issue. Kind suggestion: update the documentation for this please. There are many articles out there talking about buildah within a container… and none of them mention this absolutely critical bit of information.

Check to see if newuidmap and newgidmap have the setfcap flags set inside of your container. Sometimes you have to reinstall the shadow-utils package.

Here is the Containerfile we use to build buildah/stable. https://github.com/containers/buildah/blob/master/contrib/buildahimage/stable/Dockerfile

I’m hitting this as well using tekton on Openshift (Openshift Pipelines Operator on Openshift 4.7).

+ buildah --storage-driver=vfs bud --format=docker --tls-verify=true --no-cache -f Dockerfile -t ******* -t ******** .
Error: error writing "0 0 4294967295\n" to /proc/25/uid_map: write /proc/25/uid_map: operation not permitted
level=error msg="error writing \"0 0 4294967295\\n\" to /proc/25/uid_map: write /proc/25/uid_map: operation not permitted"
level=error msg="(unable to determine exit status)"

Is there a build image i can plug in to fix this?

As @anthr76 already pointed out in https://github.com/containers/buildah/issues/3053#issuecomment-859610721 I got the same issue when testing buildah on OKD 4.7 cluster. Solution was to add USER build as the last line of Dockerfile. Question is why call useradd build here https://github.com/containers/buildah/blob/main/contrib/buildahimage/stable/Dockerfile#L14 if it’s not used to set the environment for container execution ?

@rhatdan I know you and @umohnani8 have been digging around a lot in this space as of late, any tips?

Yes, although this should be exposed in containers.conf.

Ok I got it to work, but it is not pretty.

$  mkdir containers

We are going to need a containers file that is not mounted on fuse-overlay, since fuse-overlay will not work on a fuse-overlay. We mount the volume into the podman container, add add the /dev/fuse device so that we can use fuse-overlay inside of the container. Otherwise we could use storage driver vfs.

$ podman run -v ./containers:/home/build/.local/share/containers:Z --device /dev/fuse --entrypoint=/bin/bash -it quay.io/buildah/stable:v1.19.6
[root@f522e92ed4d5 /]# 

Notice how logged in as root, this is because I need to modify the /etc/subuid and /etc/subgid files to use a smaller range, since my container has only 65k uids to use. I pick UID 2000 and then the next 50000 uids.

[root@f522e92ed4d5 /]# echo build:2000:50000 > /etc/subuid
[root@f522e92ed4d5 /]# echo build:2000:50000 > /etc/subgid

I also want to chown the homedir including the volume I mounted in, to be owned by the buildah user.

[root@f522e92ed4d5 /]# chown -R build:build /home/build

Now I switch to the buildah user and create the Containerfile.

[root@f522e92ed4d5 /]# su - build
[build@f522e92ed4d5 ~]$ cat > Containerfile << _EOF
from fedora:33
run dnf -y update; dnf -y install gcc; dnf -y clean all
_EOF

Now I want to run buildah bud, but I have to use --isolation=chroot, otherwise buildah will try to create devices, which I am not allowed to do in a rootless environment.

[build@f522e92ed4d5 ~]$ buildah bud --isolation=chroot ./Containerfile 
STEP 1: FROM fedora:33
Resolved "fedora" as an alias (/etc/containers/registries.conf.d/shortnames.conf)
Getting image source signatures
Copying blob 157ab8011454 [--------------------------------------] 0.0b / 0.0b
Copying config 9f2a560376 done  
Writing manifest to image destination
Storing signatures
STEP 2: run dnf -y update; dnf -y install gcc; dnf -y clean all
Fedora 33 openh264 (From Cisco) - x86_64        1.3 kB/s | 2.5 kB     00:01    
Fedora Modular 33 - x86_64                      451 kB/s | 3.3 MB     00:07    
Fedora Modular 33 - x86_64 - Updates            203 kB/s | 3.1 MB     00:15    
Fedora 33 - x86_64 - Updates                    424 kB/s |  24 MB     00:58    
Fedora 33 - x86_64                              1.5 MB/s |  72 MB     00:46    
Dependencies resolved.
================================================================================
 Package                       Arch     Version                 Repo       Size
================================================================================
Upgrading:
 audit-libs                    x86_64   3.0.1-2.fc33            updates   115 k
...

Installed:
  binutils-2.35-18.fc33.x86_64          binutils-gold-2.35-18.fc33.x86_64      
  cpp-10.2.1-9.fc33.x86_64              gc-8.0.4-4.fc33.x86_64                 
  gcc-10.2.1-9.fc33.x86_64              glibc-devel-2.32-4.fc33.x86_64         
  glibc-headers-x86-2.32-4.fc33.noarch  guile22-2.2.7-1.fc33.x86_64            
  isl-0.16.1-12.fc33.x86_64             kernel-headers-5.10.13-200.fc33.x86_64 
  libmpc-1.1.0-9.fc33.x86_64            libpkgconf-1.7.3-5.fc33.x86_64         
  libtool-ltdl-2.4.6-36.fc33.x86_64     libxcrypt-devel-4.4.18-1.fc33.x86_64   
  make-1:4.3-2.fc33.x86_64              pkgconf-1.7.3-5.fc33.x86_64            
  pkgconf-m4-1.7.3-5.fc33.noarch        pkgconf-pkg-config-1.7.3-5.fc33.x86_64 

Complete!
42 files removed
STEP 3: COMMIT
Getting image source signatures
Copying blob d9e1d1e08de2 skipped: already exists  
Copying blob 0a925791ef20 done  
Copying config c6672ce7a7 done  
Writing manifest to image destination
Storing signatures
--> c6672ce7a79
c6672ce7a793bd2840011380e58502a5128ac5aeb45347ad5593f416ce9a5e86

There it works. We could make this much easier if we modified the default range of UIDs inside of the buildah stable container and defaulted for rootless users to isolation=chroot.

This means the host User Namespace is not large enough to include buildah inside of the container

While in the container you have only 65000 UIDs, but the container wants to start with UID 100000. If you modify the /etc/subuid inside of the container to say start at 2000 for 50000 UIDs, it should work.