Closed siretart closed 4 years ago
It's the sticky bit in /tmp
. Removing it makes everything work fine. strace
is not especially helpful:
/ # strace tee -a /tmp/foo
execve("/usr/bin/tee", ["tee", "-a", "/tmp/foo"], 0x7ffc942827e0 /* 7 vars */) = 0
arch_prctl(ARCH_SET_FS, 0x7fac360e8d48) = 0
set_tid_address(0x7fac360e931c) = 11
mprotect(0x7fac360e5000, 4096, PROT_READ) = 0
mprotect(0x55656f6db000, 16384, PROT_READ) = 0
getuid() = 0
rt_sigaction(SIGPIPE, {sa_handler=SIG_IGN, sa_mask=[], sa_flags=SA_RESTORER|SA_RESTART, sa_restorer=0x7fac3609928e}, {sa_handler=SIG_DFL, sa_mask=[], sa_flags=0}, 8) = 0
open("/tmp/foo", O_WRONLY|O_CREAT|O_APPEND, 0666) = -1 EACCES (Permission denied)
write(2, "tee: /tmp/foo: Permission denied"..., 33tee: /tmp/foo: Permission denied
) = 33
Nothing obvious wrt capabilities:
/ # grep Cap /proc/1/status
CapInh: 0000003fffffffff
CapPrm: 0000003fffffffff
CapEff: 0000003fffffffff
CapBnd: 0000003fffffffff
CapAmb: 0000003fffffffff
this also happens outside of podman so I don't think this is a bug:
root@babibox:/tmp# touch wat
root@babibox:/tmp# chown nobody wat
root@babibox:/tmp# echo hi > wat
-bash: wat: Permission denied
I believe it's due to the sticky bit on /tmp
which changes how permissions work slightly (only the owning user can write to the file)
I've investigated this a bit further, and with the help of #debian-devel
, we believe the error doesn't happen on distros that compile bash with the option --with-afs
.
On Debian, the kernel sets /proc/sys/fs/protected_regular
to 2 as a hardening feature (cf. https://www.kernel.org/doc/Documentation/sysctl/fs.txt). However, it seems that Fedora/RHEL based distributions defeat this protection. I've posted some strace outputs here: https://gist.github.com/siretart/130920831016cbba9df89e871c0948de -- the relevant code part in bash can be seen here: https://sources.debian.org/src/bash/5.0-7/redir.c/?hl=694#L691
I don't think there is any code change necessary in podman.
Interesting: I did confirm earlier that the problem doesn't manifest on Fedora (32):
# echo hi >/tmp/foo
#
This is indeed bash. However, something else that tries to open()
the file fails:
# tee -a /tmp/foo
tee: /tmp/foo: Permission denied
So indeed, there's probably not much podman can do about it. @siretart thank you for the report and the followup. I'm closing, please reopen if new information arises.
/kind bug
Description
This issue is reproducible with Debian and alpine images, but not with ubi7 or ubi8 images. What's different about them?
Output of
podman version
:Output of
podman info --debug
:Package info (e.g. output of
rpm -q podman
orapt list podman
):