-
Notifications
You must be signed in to change notification settings - Fork 2.4k
This issue was moved to a discussion.
You can continue the conversation there. Go to discussion →
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
Add chown and root_chown options for image volume mount #18986
Comments
Created a new oci hook as mentioned in the issue here https://github.com/LaunchPlatform/oci-hooks-mount-chown/ I think this could be used as a reference for the feature. podman run \
--user 2000:2000 \
--annotation=com.launchplatform.oci-hooks.mount-chown.data.mount-point=/data \
--annotation=com.launchplatform.oci-hooks.mount-chown.data.owner=2000:2000 \
--annotation=com.launchplatform.oci-hooks.mount-chown.data.policy=root-only \
--mount type=image,source=my-data-image,destination=/data,rw=true \
-it alpine
# Now you can write to the root folder of the image mount
touch /data/my-data.lock Instead of the
The |
Hmmm, maybe this problem cannot be resolved by just using a hook?
Just tested my hook, but I guess at the point of |
nvm, turned out podman pull fangpenlin/pure-data-image-demo
podman run \
--user 2000:2000 \
--annotation=com.launchplatform.oci-hooks.mount-chown.data.path=/data \
--annotation=com.launchplatform.oci-hooks.mount-chown.data.owner=2000:2000 \
--annotation=com.launchplatform.oci-hooks.mount-chown.data.policy=root-only \
--mount type=image,source=fangpenlin/pure-data-image-demo,destination=/data,rw=true \
-it alpine then /data $ id
uid=2000(2000) gid=2000(2000) groups=2000(2000)
/data $ chmod 755 .
~ $ touch /data/my-note.txt.lock
~ $ ls -al /data
total 12
drwxr-xr-x 1 2000 2000 4096 Jun 24 02:08 .
dr-xr-xr-x 1 root root 4096 Jun 24 01:21 ..
-rw-r--r-- 1 2000 2000 12 Jun 23 19:21 my-note.txt
-rw-r--r-- 1 2000 2000 0 Jun 24 02:08 my-note.txt.lock |
Just realized, if we only care about being able to write new files to the root mount path, we ca actually chmod of it. With the idea, I added Here's the example with the latest OCI hook I built podman run \
--user 2000:2000 \
--annotation=com.launchplatform.oci-hooks.mount-chown.data.path=/data \
--annotation=com.launchplatform.oci-hooks.mount-chown.data.mode=777 \
--annotation=run.oci.hooks.stderr=/tmp/hooks-stderr \
--mount type=image,source=fangpenlin/pure-data-image-demo,destination=/data,rw=true \
-it alpine then
So I wonder, one possible alternative of chown could be just allow user to change mode of the image mount point folder. |
A friendly reminder that this issue had no activity for 30 days. |
This issue was moved to a discussion.
You can continue the conversation there. Go to discussion →
Feature request description
I really love that the podman supports image mount, but I encountered a problem while trying to use it. One major issue I saw was that the root folder of mounted image volume seems like fixed to owner
root
with mode555
. If you are running the container with a non-root user, you are not going to be able to write anything into the root folder of the image mount point.I made a docker image with just simple data in it for demo purpose.
And its Dockerfile:
Then here's the commands for showcasing the issue:
podman pull fangpenlin/pure-data-image-demo podman run \ --user 2000:2000 \ --mount type=image,source=fangpenlin/pure-data-image-demo,target=/data,rw=true \ -w /data \ --entrypoint=/bin/sh -it \ alpine -c 'ls -al && touch my-note-v2.txt'
And the result looks like this
As you can see I got the files in the image with owner
2000:2000
, surely I can write to the file, but if I runand there will be a permission error because the root folder comes with
root
as the owner and555
mode. I will be forced to added extra nested folder with the correct owner or permission in the image content to make things work.Suggest potential solution
I think it would be great to have
chown
option for the image mount as well just like the bind mount. However, given that if the mounted image's nature is mostly for data purpose, recursive chown might be very slow. I like Kubernete's newfsGroupChangePolicy: "OnRootMismatch"
option for mounted volume:https://kubernetes.io/blog/2020/12/14/kubernetes-release-1.20-fsgroupchangepolicy-fsgrouppolicy/#allow-users-to-skip-recursive-permission-changes-on-mount
It only changes the root owner. So I wonder, maybe we can add two options, one is
chown
comes with recursive owner changes for the whole image mount. Another isroot_chown
only changes the root folder.Have you considered any alternatives?
From the end-user endpoint, an alternative could be avoid writing anything new to the root dir. While that could solve the problem, but it also limits what you can do with the image mount.
To solve the problem for our own use cases before the new feature is added in podman, I will build an OCI hook that reads annotations like
Pretty much like this one I built a while back: https://github.com/LaunchPlatform/oci-hooks-archive-overlay
Additional context
Add any other context or screenshots about the feature request here.
The text was updated successfully, but these errors were encountered: