-
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
Wrong CWD value set when calling OCI poststop hook executable #18907
Wrong CWD value set when calling OCI poststop hook executable #18907
Comments
I read the code a bit more, the Run method is making the osexec.Cmd struct at And according to Go's doc for
the |
Nope, I just tried, if you run
in
Shouldn't be too hard to fix, I will probably create a PR tomorrow for this. |
Please open a PR to fix. |
@rhatdan I created a PR here along with one for common and one for buildah As a first time contributor, I am not sure how the workflow looks like here. I didn't add change in vendor folder in my PR. Please let me know if this is not the correct way to open PR with across repo changes here, thanks! 🙏 |
…or-poststop-hook-exe Fixes #18907, pass in correct cwd value for hooks exe
Issue Description
I am figuring out how to use OCI hooks for some custom clean up implementations. But then I realized it's pretty odd that OCI poststop hook is called by podman with a wrong CWD value (I assume it's wrong, see below).
I wrote a simple C++ program for dumping the CWD value and environment variables like this
dump_env.cpp
Then I have two OCI hook json files created like this
/usr/share/containers/oci/hooks.d/start.json
:and this
/usr/share/containers/oci/hooks.d/stop.json
:After run any
pod run
command, I got output files, for start hook it's like this:And the output of stop env dump looks like this
As you can see the CWD for start hook invoked by
crun
is set to theuserdata
folder of container. With that, I can easily readconfig.json
and perform the task for my starting hook. But forpoststop
, somehow the CWD value was set to/home/user
.After digging a bit deeper, for the reasons I am not aware of, podman is making the
poststop
call instead of delegate it tocrun
here.I haven't look at the code carefully yet, not sure why the cwd is set to home folder instead of container's userdata folder. I also tried my best to read the OCI container runtime spec see if they mention anything about setting the CWD value when calling the hook executable. Unfortunately, I didn't find anything about this part in the documents. So I assume this is an implementation details up to vendor like podman? The behavior is inconsistent between crun invoked calls and the podman invoked calls, plus it's harder to make a poststop hook works without knowing the container userdata folder, I wounder if this should be seen as a bug? I assume it is, but if it's not or this is even intentional, please feel free to close this issue.
Steps to reproduce the issue
Steps to reproduce the issue
createRuntime
andpoststop
hook files to use the dump cwd command to output the value to somewherepodman run
with any image and exit the containerDescribe the results you received
Describe the results you received
Describe the results you expected
CWD value when poststop executable invoked:
podman info output
The text was updated successfully, but these errors were encountered: