Repository navigation
fix: reduce world writeable directories and files, fixes #8194 - #8195
Conversation
|
Download the artifacts for this pull request:
See Testing a PR. |
|
Those are definitely purposefully made writable by the DDEV-added user, but maybe can be reconsidered. |
ee290f1 to
5ec42f7
Compare
|
I pushed a Docker image for this. |
Analysis: Why `/usr/sbin` and `/usr/bin` were made world-writeableThe `chmod -R ugo+w /usr/sbin /usr/bin` line goes back to #828, the very first commit that moved container code into the ddev repo (e36b1f6e, May 2018). The reason was that the container runs as an arbitrary unprivileged user, but two runtime operations in `start.sh` needed to write into those directories:
The key change in 89464a79 in PR #8195 — replacing `ln -sf /usr/sbin/php-fpm${VERSION} /usr/sbin/php-fpm` with `update-alternatives --set php-fpm` in both `start.sh` scripts and in the Dockerfile — is precisely what makes it safe to drop `/usr/sbin` from the `chmod -fR ugo+w` list. The `update-alternatives` approach routes the symlink through `/etc/alternatives` and `/var/lib/dpkg/alternatives` (both of which this PR correctly adds to the `chmod` list) rather than writing directly into `/usr/sbin`. `/usr/bin` may still need to be writable for `update-alternatives --set php /usr/bin/php${VERSION}` in `start.sh` — worth confirming whether `update-alternatives` needs write access to `/usr/bin` itself, or whether `/etc/alternatives` + `/var/lib/dpkg/alternatives` are sufficient for non-root execution. So the removal of `/usr/sbin` from the `chmod -fR ugo+w` line is deliberate and correct. The `/usr/bin` removal is likely also correct (since `update-alternatives` manages things through `/etc/alternatives`), but that's the one to verify with a runtime test switching PHP versions. |
|
I'll look at the history before this also |
|
update-alternatives updates the symlinks in /etc/alternatives, which is also world writeable in the DDEV image, and most likely should stay that way to keep core DDEV functionality working as-is, at least short-term. Removing user write rights from that directory as well would require some further reaching changes in the way DDEV switches versions, and is not required for restoring functionality with the updated adduser script. /usr/bin/php is a symlink to /etc/alternatives/php, which is a symlink to the configured php version. So removing the write rights from just /usr/bin keeps that functionality intact as-is. |
|
What do you think about /usr/local/bin being writable? |
|
While not required for adduser for some reason (not sure why actually, since it's also in the $PATH), ideally this should also not get more permissions than required. From what I've seen, drush is the main reason this is currently world writeable, since that symlink is created during runtime instead of at build time. Or maybe keep it at runtime, but linked into a user bin directory (e.g. $HOME/.local/bin is a common path for this) instead. |
|
And drush is only symlinked for long-outdated drupal6/7. It could easily go as a symlink in ~/bin or ~/.local/bin etc |
|
Many activities can be done with sudo if they're for normal development situations. |
|
You can either use sudo, or add a folder to PATH which is user-writable (e.g. ~/.local/bin). Anything in /usr should never be world writable, that's what #8194 is about. IMO the fix here looks good and solves the main problem. |
|
I note that the problem here prevents |
|
I think we should probably get this into upcoming release, either as is or with improvements. |
The Issue
The adduser version used in Debian Trixie introduced a permission check for the folders set in PATH, failing when system directory like /usr/bin and /usr/sbin are world writeable.
How This PR Solves The Issue
Exclude /usr/sbin and /usr/bin from
chmod ugo+win DockerfileRegister php-fpm in update-alternatives
Use update-alternatives instead of symlink recreation to switch php-fpm versions
Manual Testing Instructions
TBD
Automated Testing Overview
Release/Deployment Notes