-
Notifications
You must be signed in to change notification settings - Fork 2.5k
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
Volumes always owned by root #2898
Comments
Podman by default in rootless mode makes the UID of the user running the command ROOT inside of the container. That means that when you look at the UID of the running process it will be 0, even though the process is really running as your UID. Also any files with your UID as owner or group will be seen as UID==0 while in the container. Any file actually owned by a UID==0 will be seen as -1. So this is not a bug. |
Hi @rhatdan, thanks for your response. Is there any way to use
|
If you eliminate the --user=$UID it should work for you, but you will think you are running as root inside of the container. Another option is to use the User Namespace differently. I am going to guess that your UID == 1000, Current @giuseppe I wonder if we should make this an option for podman, |
I changed the command slightly to get it working, but now files from the volume are owned by nobody:
|
I like it, I would love to make this easier for non expert users. |
|
I would want something to indicate this is usernamespace --userns-map-uid |
we could do that, it should be pretty easy. We need to provide a preconfigured mapping for the namespace. We also need |
We could default to the logged-in user's UID |
@giuseppe Why would we need --user? I still am fine with them being root when the container starts and then remapping to their user. |
@mheon I don't think we should change the default. If we had a flag that changed the default then you could toggle the flag via an environment variable. |
We need user for the effective setresuid in the oci runtime, that needs to happen after the second mapping is in place. |
Hi, I couldn't figure out how to fix this yet. If I use ➜ podman run --rm -v="$PWD:$PWD" -w="$PWD" --uidmap=0:10000:$((UID)) --uidmap=$UID:$UID:1 --uidmap=$((UID+1)):$((UID+10001)):$((55536-UID)) alpine ls -l -n
total 0
-rw-r--r-- 1 65534 65534 0 Apr 12 17:47 test
➜ ls -l -n
total 0
-rw-r--r--. 1 1001 1001 0 Apr 12 17:47 test |
Is uid 1001 mapped into your container? If not it will show up as 65534 |
Yes, it is (
Here is another example that doesn't work either:
|
@giuseppe I am seeing this also. Any ideas? Is showing me the files in my homedir as:
|
root from the first namespace (which is your user) is not mapped inside the new namespace, you need to do |
So the issue here is that my command is executing in the second namespace. |
we need to use something like fedora-toolbox: https://github.com/debarshiray/toolbox/blob/master/toolbox#L732-L734 |
Very confusing for the user. |
@rhatdan agreed. We need to do this automatically:
|
To allow for users above 65536 you will need something like:
|
Since I keep getting yelled at for recommending Here's what I've tried:
Here's what I get:
But, magically, it works if I add
Am I violating security best practices by adding |
Are you running Podman rootless, or with root?
The problem is likely SELinux, given that the user in question should have
permissions to write in /tmp otherwise. Privileged relaxes the container's
SELinux constraints, so it makes sense that it resolves the issue.
If you're running Podman rootless, using privileged increases the
container's ability to interact with the system (more of the host is
mounted into the container, SELinux and Seccomp restrictions are relaxed,
etc), but it still has no privileges the user that launched the container
did not.
If you only need to make files and don't want the other effects of
privileged, security-opt label=disable might work better. You can also use
:z on the volume mounts to label them for container use, but I'd only
recommend that for folders you made explicitly to share with the container
(relabelling /tmp for example would probably break your system)
…On Sat, Apr 27, 2019, 05:12 Dan Allen ***@***.***> wrote:
Since I keep getting yelled at for recommending --privileged, I'm trying
to work out how I can mount a volume unprivileged such that the root user
in the container writes files to that volume as the user who started the
container. (In other words, when the container stops, the files that were
written are owned by the user who started the container).
Here's what I've tried:
podman run --rm -it -v "/tmp:/tmp" alpine touch /tmp/test.txt
Here's what I get:
touch: text.txt: Permission denied
But, magically, it works if I add --privileged:
podman run --rm -it --privileged -v "/tmp:/tmp" alpine touch /tmp/test.txt
Am I violating security best practices by adding --privileged? Or is it
safe because this is podman? I'm confused. If it is safe, it would be nice
if the documentation would say so.
—
You are receiving this because you were mentioned.
Reply to this email directly, view it on GitHub
<#2898 (comment)>,
or mute the thread
<https://github.com/notifications/unsubscribe-auth/AB3AOCA7DD2U4YMDOUKMVZ3PSQKHFANCNFSM4HFEIAOA>
.
|
That is exactly what I needed to know. And it's also exactly the behavior I need to make volumes viable. (The use case is to invoke the container as though it is a local command to save the user from having to install a toolchain). Is there anywhere in the documentation I can link to that makes this assertion? |
You might want to look at the gnome toolbox package, which is designed for pretty much your use case. It wraps podman to act in a behaviour where it gives the users their own container, which they can become root and install what ever software they want, but does not effect the host OS. I wrote a series of blogs on podman and user namespace out on opensource.com |
@rhatdan I appreciate that suggestion, and I will certainly look into it for my own use. However, when it comes to providing instructions for users who want to run a piece of software without having to install the whole toolchain, that's asking too much of them. They just want to know what command they have to type into the console to be able to run the application. It's a means to an end. And for that, the podman command alone is what they're after. And it's something that requires very little explanation (once we sort out the right arguments for them to use). |
I am not arguing against the use of podman. Podman is the tool for a user to install a containerized application. That is why we are building it. |
@mojavelinux We've mentioned that rootless uses no additional privileges in a few blog posts, but nothing in the README or manpages. That sounds like a big omission on our part, so I'll look into getting something written up for the README first, and then maybe the manpages |
@mojavelinux I took a first pass at adding a description in #3038 - would appreciate your checking to see if this would have adequately answered your question, or if we need to include more detail. |
@mheon I very appreciate you following up to add information about this to the docs. However, the paragraph you added doesn't really enhance my knowledge or understanding in anyway. Specifically, I don't see any mention of
Honestly, I think it was a poor decision to reuse the same flag as in Docker since clearly it has very different implications. But for consistency, I could see the benefits if it is properly documented. |
A lot of the implications are still the same - we're still relaxing Seccomp, SELinux, and restrictions on mounts in /proc and /sys. The biggest difference is the starting point in terms of permissions and capabilities - we can grant you additional privileges with |
(I should probably put that bit in the readme too) |
where are we on this one? |
#3038 merged with documentation, so I think this might be fixed |
Actually, I think @giuseppe solved our other issues with a |
I'm going to close as we've added documentation and #3196 added a way to retain UIDs |
The user_id_real=$(id -u)
max_uid_count=65536
max_minus_uid=$((max_uid_count - user_id_real))
uid_plus_one=$((user_id_real + 1))
if [ $user_id_real -lt 65536 ]; then
extra_args="--privileged --uidmap $user_id_real:0:1 --uidmap 0:1:$user_id_real --uidmap $uid_plus_one:$uid_plus_one:$max_minus_uid"
else
extra_args="--privileged --uidmap $user_id_real:0:1 --uidmap 0:1:65536"
fi |
Thanks this fixed my problems with typical VSCode dev containers. "remoteUser": "vscode",
"runArgs": [
"--userns=keep-id"
], |
I think that I've found a simple solution for this. The idea is to NOT map root in the container to the running user on the host, but to map it to one of those large automatically assigned UIDs. In particular, map UIDs 0-999 in the container to automatically assigned UIDs, but map UID 1000 in the container to the host user's UID. Like this:
So if you now create a user with UID 1000 in the container (the first normal created user will get that UID), it will have full access to bind mounted folders owner by the host user. |
Is this a BUG REPORT or FEATURE REQUEST? (leave only one on its own line)
/kind bug
Description
Volumes are always owned by root instead of inheriting owner and group from the host.
Steps to reproduce the issue:
podman run --rm -v "$HOME:$HOME" alpine ls -l "$HOME/.."
podman run --rm -v "$HOME:$HOME" --user "$(id -u):$(id -g)" alpine ls -l "$(dirname $HOME)"
Describe the results you received:
The mount is owned by root.
Describe the results you expected:
The mount should be owned by the current user in both cases. (At least this is what Docker does.)
Additional information you deem important (e.g. issue happens only occasionally):
100% reproducible. Probably related to #2643 and #2634.
Output of
podman version
:Output of
podman info --debug
:Additional environment details (AWS, VirtualBox, physical, etc.):
I'm using Fedora Workstation 29.
The text was updated successfully, but these errors were encountered: