-
Notifications
You must be signed in to change notification settings - Fork 2.1k
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
If we use a .sh or .py(-rwxr-xr--.) has defined #!/bin/sh or #!/usr/bin/python3 as the pid=1 of the container, starting the container with a normal user without permissions will report an error "permission denied" #3926
Comments
I've tried to reproduce the issue you described (removing the The way permissions work with % echo '#!/bin/echo' > script
% ./script
zsh: permission denied: ./script
% chmod +x ./script
% ./script
./script And you can verify that the error is really coming directly from exec, meaning the kernel is refusing the access: % strace -e execve ./script
execve("./script", ["./script"], 0x7ffdd15d1b90 /* 104 vars */) = -1 EACCES (Permission denied)
strace: exec: Permission denied
+++ exited with 1 +++ All of this means that
The key line being:
We are just passing the script path to the kernel, and it handles everything else. |
Actually I started the container through docker. |
Ah yeah, There was a bug with how this check was handled by the standard library when We fixed this issue and added tests for it in #3753 (which was released in runc 1.1.6) and this bug seems like a duplicate of #3715 (which we've long-since fixed AFAIK). |
I'm using golang1.20.5. exec.LookPath will check the capabilities, it works fine. I have seen |
This was done to fix #3520. Problem is, when we call This is why we do this check early -- to be able to report an error. |
Closing as fixed; @zzyyzte feel free to let us know if the issue is still not fixed |
Description
While golang >= 1.20, If we use .sh and .py as the pid=1 of the container, starting the container with a normal user without permissions will report an error "permission denied".
But If the golang <1.20, If we use .sh and .py as the pid=1 of the container, starting the container with a normal user will start the .py or .sh success.
https://github.com/opencontainers/runc/blob/main/libcontainer/standard_init_linux.go#L202
This error return by exec.LookPath. In golang 1.20, golang/go@2b8f214
I can understand that this commit introduces Eaccess.
But if we comment out this line, runc can start a .sh or .py script without permissions(we should define #!/bin/sh or #!/bin/python3 in script).
Actually in scripts, even if the file's mode is 754(-rwxr-xr--.), we can also call
/bin/bash .sh
or/usr/bin/python3 .py
to run this script successfully without permision.I think this is because
syscall.Exec
will call /bin/sh or /usr/bin/python3 as pid=1, and then, call /bin/sh .sh or /usr/bin/python3 .py, this is permitted.(In fact, I used theps
command to check process relationships, and indeed started /usr/bin/bash before starting the script.) But I cannot do this outside runc, I can only do this by commenting out the lookpath line and the Eaccess line in runc, is there anyone can explain this?But now, After runc is compiled by golang>=1.20, this will not succeed anymore.
Steps to reproduce the issue
sleep.sh and sleep.py mode is 754, just means -rwxr-xr--. sleep.sh and sleep.py like this:
Describe the results you received and expected
If runc is compiled by golang>=1.20, it will return "permission denied".
If runc is compiled by golang<1.20, it will success.
What version of runc are you using?
Host OS information
all centos
Host kernel information
4.18
The text was updated successfully, but these errors were encountered: