-
Notifications
You must be signed in to change notification settings - Fork 2.4k
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
Calling podman binary as rootless user from C++ running as a separate user? w/ --group-add keep-groups #10212
Comments
I have a feeling this has nothing to do with Podman, and something else is happening. I would just check to see if the process being execed out of the c++ program actually ends up with the video group when you execute it from the root account without the video group. All that podman is doing is allowing the container to inherit the groups of the process that executed it. If that process does not have the video group, then the container will not have the video group. |
Right, this could be the incorrect place for this issue. But, running your test is actually why I created this ticket.
What this shows is me starting my daemon, which uses the same function to execv different processes. This shows my podman container starts successfully with Now if all I change is this:
(remove root user from video group) When I re-run the program:
Adding root user back into video group fixes this issue. |
On the second one, could you just execute Without the hooks? |
Yes definitely.
Lastly I removed the first execv process, so now the only thing that get started is podman.
This looks correct to me. It correctly adds the video group to the container. However, of course since the nvidia script did not run the GPU is not under /dev so I can't access it. As a sanity test, I added
video group looks to be added. Side note: The user that is starting the container is not an |
So it looks like Podman is working as expected. |
This actually got me digging a bit more, and I was able to access my GPU without invoking the script at all. By adding the proper So something seems to be happening in the hook portion of the execution. Is it possible that because it is a Update: Maybe this actually doesn't make sense because it works in a terminal fine. Which leads me to why I opened this ticket :) |
@giuseppe Is it possible the crun/runc are dropping groups before executing the hooks? |
So I setup a test, to test this:
test.sh
Ran my C++ program with sudo, and added the
So this is correct, the user that is executing the nvidia script should be aware of the |
does it work if you don't do any Anyway, it seems there is nothing we can do from Podman. I am closing this issue, but feel free to comment more (or reopen if you disagree) |
I am trying to understand what is required to properly call podman from a non-terminal environment, using: execve.
My understanding from this rootless container login doc is that the best way to use rootless container runtimes is to be logged in as the user on a terminal, using
ssh
ormachinectl shell
.However, I would like to use podman from a C++ program, but, this program is not started as the user that I want podman to be called with.
So I am wondering if anyone can point me to what I need to set?
I am using fork() + execve:
Essentially the C program is running as root (for the time being)
But I want to spin up podman with a rootless user,
user1
:user1 - uid == 1000
user1 - gid == 1001
Essentially I am doing:
This does seem to correctly spin up containers, with the correct user. And in a terminal I can verify that I see the running container with that user.
The problem, comes from the following and is related to this: #10166 and NVIDIA/nvidia-container-runtime#85
Part of my podman arguments are using the
--group-add keep-groups
and additionally--hooks-dir=/data/hooks/ -e NVIDIA_VISIBLE_DEVICES=all
.These arguments helps map the
video
group that myuser1
is apart of into the rootless container, which allows the nvidia hook to detect my GPUs.When I start it from inside my
C++ program
it seems that the user which starts theC++ program
also needs to be inside thevideo
group for me to properly access the GPU.If I remove
user1
from thevideo
group, my container starts but my GPU is not detected when I try and run cuda code.If I remove
root
from thevideo
group, my container does not start, because the nvidia hook that detects the GPU fails with the error:Error: OCI runtime error: error executing hook 'usr/bin/nvidia-container-toolkit' (exit code: 1)
And from experience, I see this error when the
video
group is not correctly being used/mapped.When both users,
user1
androot
, are in thevideo
group, the container successfully starts and I have access to the GPU.I am wondering if there is any path forward for me here?
Should I be using something other than:
setresuid
/setresgid
?Why do both users need to be in
video
group? Is it related to how hooks are invoked in podman?The text was updated successfully, but these errors were encountered: