-
Notifications
You must be signed in to change notification settings - Fork 2k
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
chmod 1777 has surprising behaviour #1556
Comments
In your Dockerfile, you don't explicitly set a user so the https://github.com/docker-library/php/blob/master/8.2/bookworm/fpm/Dockerfile#L49 |
No, this has nothing to do with /tmp/files at all. You can get the same behaviour pointing the symlink at / or /etc/os-release or whatever you want. It's the symlink that can't be read. The symlink named Yes, creating the symlink with the same UID as the final user would fix this, but that's completely new and surprising and abnormal for these directories. You only need to care about the UID of symlinks in sticky-bit directories, and on a normal system that's only /tmp and /var/tmp Again, I'd be happy to suggest a fix if I understood why the sticky bit was added in the first place, but I don't; the PR just said "security", but I have no idea what the threat model is for directory security inside a container. |
Yeah, the symlink also needs its permission expanded. There seems to be something weird about the The following Dockerfile yields this result
|
You really need to go read https://sysctl-explorer.net/fs/protected_symlinks/ please; the ls behaviour you're seeing is exactly the problem I'm talking about, and exactly what's expected when you throw 1777 on random directories. Changing a symlink to 1777 is a bad idea and isn't relevant; it's about alignment of ownership. Seriously, y'all need to take 1777 off these directories, and again if you told me what you were trying to accomplish I'd have suggestions for alternate solutions. |
https://en.m.wikipedia.org/wiki/Sticky_bit With that being said, you are able to change those permissions in your child image. |
That doesn't explain why you want it in a container. The sticky bit functionality is designed for shared directories on shared systems with lots of users, like /tmp. A container is, by definition, not normally shared between users. There's no reason to have sticky bit on a directory that different actual humans are not sharing access to. |
The purpose is to prevent PHP, a general purpose language, from being able to perform destructive operations on the filesystem if an attacker is able to inject malicious code that gets executed. |
These directories exist in a container. A bind mount won't have these perms, so they exist only in the container. The user that apache is running as in the container already has perms on all these files. If someone injects malicious code, it'll be running as that user, which already has perms on all these files. The sticky bit won't have any impact in what is fundamentally a single-user context. |
The use case that this support is running the container as another user that therefore doesn't have permission to modify the data. |
Yes, that's exactly the problem I hit, with extremely surprising results. A container should not have this behaviour, it is not a multi-user system. I really think this behaviour is going to surprise and confuse people in the future. It's clear, though, that you're not interested in what I'm saying, so I'm going to stop now. |
The goal of using The php/8.4/bookworm/apache/Dockerfile Line 87 in 75a0c3c
That being said, I can't reproduce a failure related to $ docker run -it --rm --user 1234:5678 --pull=always php:apache
apache: Pulling from library/php
Digest: sha256:2c9ae64a55950a3b44c5121cae9b1dc82601e9ff2a0ed0279d02c047019ca53d
Status: Image is up to date for php:apache
AH00558: apache2: Could not reliably determine the server's fully qualified domain name, using 172.27.0.9. Set the 'ServerName' directive globally to suppress this message
AH00558: apache2: Could not reliably determine the server's fully qualified domain name, using 172.27.0.9. Set the 'ServerName' directive globally to suppress this message
[Tue Jan 07 01:19:59.244877 2025] [mpm_prefork:notice] [pid 1:tid 1] AH00163: Apache/2.4.62 (Debian) PHP/8.4.2 configured -- resuming normal operations
[Tue Jan 07 01:19:59.244910 2025] [core:notice] [pid 1:tid 1] AH00094: Command line: 'apache2 -D FOREGROUND' Can you provide more details about how I could reproduce? |
The following cost me hours of debugging. It's a side effect of #1383 plus https://sysctl-explorer.net/fs/protected_symlinks/ .
Dockerfile:
Commands:
podman is basically the same as docker;
--userns=keep-id
just makes it so everything runs as the user running the command in the container, so in this case I was running with UID 1086.In the container:
I discovered this because https://github.com/wikimedia/mediawiki-docker has symlinks from /var/log/apache2/error.log to /dev/stderr (and a few other similar ones) that with this php docker image change, cause apache to fail to run if the running UID is not the same as whatever the default for www-data is (33 I think?) because /var/log/apache2 is 1777 and own by that ID.
I don't have any particular suggestions for how to solve this because I'm not sure what problem you were trying to solve by making this change in the first place.
The text was updated successfully, but these errors were encountered: