podman: Volume for container with custom user is not writeable
/kind bug
Description
When running a container with explicitly set user, such as
https://github.com/schemaspy/schemaspy/blob/a28c9fc932cc6f85c7780050a678b3a3d7f595e9/Dockerfile#L44 the volume mounted by podman is not writeable.
Steps to reproduce the issue:
-
Get some PostreSQL host (192.168.4.1) and port (5432)
-
Create dir to mount as a volume
$ mkdir html
- Run
podman
$ podman run -it -v "$PWD"/html:/output:Z schemaspy/schemaspy:snapshot -u postgres -t pgsql11 -host 192.168.4.1 -port 5432 -db anitya
...
INFO - Starting Main v6.1.0-SNAPSHOT on 9090a61652af with PID 1 (/schemaspy-6.1.0-SNAPSHOT.jar started by java in /)
INFO - The following profiles are active: default
INFO - Started Main in 2.594 seconds (JVM running for 3.598)
INFO - Starting schema analysis
ERROR - IOException
Unable to create directory /output/tables
INFO - StackTraces have been omitted, use `-debug` when executing SchemaSpy to see them
Describe the results you received:
Container is unable to write to /output, most likely because it is running with java user.
Describe the results you expected:
Volumes work rw regardless of user settings inside of conainer.
Output of podman version:
✗ podman version
Version: 1.5.1
RemoteAPI Version: 1
Go Version: go1.12.7
OS/Arch: linux/amd64
About this issue
- Original URL
- State: closed
- Created 5 years ago
- Reactions: 3
- Comments: 42 (26 by maintainers)
Commits related to this issue
- Dockerfile: Update JRE and remove `java` user `java` user creates problems when mounting volumes. See https://github.com/containers/libpod/issues/3990 — committed to abitrolly/schemaspy by abitrolly 5 years ago
- Dockerfile: Update JRE and remove `java` user `java` user creates problems when mounting volumes. See https://github.com/containers/libpod/issues/3990 — committed to abitrolly/schemaspy by abitrolly 5 years ago
- Run the command in the container with the host's user ID and GUID this is needed to solve the issue https://github.com/containers/podman/issues/3990 when running on Podman. Podman by default is not m... — committed to zhukovgreen/convert2rhel by zhukovgreen 3 years ago
How hard it could be to write a nice blog post series for the simple users which follows the Podman mantra of not running root-full containers, but wants just to mount some volumes. For the most common use-cases. Like:
IMO there is not so much different flavors of the setups which are used by the mainstream users. Not everyone works on Go/Rust single binaries which most often does not require volumes. Not everybody is working in the CI/CD environment which constantly does full baking. Not everyone wants to run
podman build/runon every single line added to the code.This volumes question is like Top 1 asked question and yet, in Podman (which “coined” the root-less idioms) website can’t be found any article for “simple users”. Every article i saw is like - “Guys, in order to run your quick container idea in rootless, please first learn whole SELinux labeling and type enforcement, then learn Linux namespacing and then feel free to read this article and to run your container in rootless.”
I understand that this is fairly complex topic. And the tooling is tailored to match pretty low level requirements and thus it is kinda flexible and complex at the same time. So… there is no need for high level user friendly API implementations which could take ages to implement. All it takes, just to write canonical blog series about the most common setups. I am not expert, to write 100% accurate articles, but there are people who are. And those people are wasting their valuable time in answering the individual issues in the GitHub instead of writing single canonical user reference which could be updated as API changes.
Wow, this stuff is way too complicated. I’ve the same issue as @abitrolly (running podman as non-root, having a user inside the container that is not “root” and I cannot write to the mounted directory). I’ve read every comment here and I still don’t have an idea how to make this work.
@abitrolly But bottom line, I tell people to always run their containers as non-root, even in the rootless container. One thing we could consider would be to add a :U to volumes which would chown the directory to match the primary user of the container. For podman Might be something to consider.
It might not work in all use cases but another work around is to run the command in the container with the host’s user ID and GUID by using
--userns=keep-id --user=$(id -ur):$(id -gr), e.g.:while without it it fails:
Now how do you chown the directory back to the host user though?
I agree that
unshareis a terrible name; we named it after an existing utility that enters user namespaces (doing something very similar to what we do, but not doing many of the things we do to make sure that it matches what otherpodmancommands are doing.Root should not be necessary -
podman unsharesticks you into the same user namespace that the rootless container uses, which gives you access to every UID/GID that the container does. Within apodman unshareshell you should be able to chown folders/files owned by your user to the UID/GID used by Jenkins. You will need to know what IDs are in use inside the container, becausepodman unshareis a shell on the host (though you can mount the container withpodman mountand inspect its/etc/passwdto get those). This can also potentially allow you to identify the user we’re mapped to on the host (suto the right UID in thepodman unshareshell and touch a file in your/home- the UID there should be the one in use).For the second issue… That is definitely a concern, and one I don’t think we have an easy solution to as yes. There is talk of adding UID/GID mappings to LDAP for use across multiple systems, but they will still be unique to the user running the container for security reasons, so not portable between users
Running rootless containers as non-root and mounting in volumes is proving to be quite complicated. I think a review of how things are right now and a discussion of how we can improve (maybe a blog?) is definitely warranted here.
I still don’t understand what
unsharedoes. How is that different fromsu <user>? How doesunshareknow the UID to run inside?What is the proposed solution? Is the following correct?
podman unshare chown -R RLUID /host/pathpodman run -v /host/path:/guest/path-/guest/pathis now writablechown -R UIDto get permissions backIs that right?
i’m battling this same thing. i am using a bitnami image of postgresql from docker hub. it has a baked in user id of 1001. on my arch linux system my uid is 1000. I would like to make a directory in my home directory for postgres to persist its data to, and be able to poke around in that directory without having to chown it all the time when i want to. @rhatdan what is your suggestion for people using vendor provided images that already have a uid baked in?
Not sure if this is a “true” solution or more of a workaround, but would not
--usernshandle at least some of the situations desired to mount with non-root user permissions?For example:
podman run --rm --userns=keepid -v /home/hostUserName/tmp:/home/containerUserName/tmp:Z -it image_name /bin/bashThis mounts tmp inside the container at
/home/containerUserName/tmpwith the same UID:GID inside the container as it possesses on the host.Perhaps
--userns=ns:my_namespacecould be used to mount a volume with the UID:GID corresponding to the user namedmy_namespace?Note: you cannot use
--user myUserNameand--userns=...in the samepodman run ....command, as I understand it.Well for now you can do
$ podman unshare chown 1001:1001 PATHTODIR
We could add something to the volume command to do this, but I am not sure how ugly the syntax would be.
Okay, but how?