Skip to content

fix: reduce world writeable directories and files, fixes #8194 - #8195

Merged
stasadev merged 2 commits into
ddev:mainfrom
AkibaAT:20260303_akibaat_reduce_world_writeables
Mar 25, 2026
Merged

stasadev merged 2 commits into
ddev:mainfrom
AkibaAT:20260303_akibaat_reduce_world_writeables

Conversation

@AkibaAT

@AkibaAT AkibaAT commented Mar 2, 2026

Copy link
Copy Markdown
Contributor

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+w in Dockerfile
Register 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

@github-actions github-actions Bot added the bugfix label Mar 2, 2026
@github-actions

github-actions Bot commented Mar 2, 2026 •

Copy link
Copy Markdown

@rfay

rfay commented Mar 2, 2026

Copy link
Copy Markdown
Member

Those are definitely purposefully made writable by the DDEV-added user, but maybe can be reconsidered.

@stasadev stasadev changed the title fix: reduce world writeable directories and files (#8194) fix: reduce world writeable directories and files, fixes #8194 Mar 4, 2026
@stasadev
stasadev force-pushed the 20260303_akibaat_reduce_world_writeables branch from ee290f1 to 5ec42f7 Compare March 4, 2026 20:26
@github-actions github-actions Bot added the dependencies Pull requests that update a dependency file label Mar 4, 2026
@stasadev

stasadev commented Mar 4, 2026

Copy link
Copy Markdown
Member

I pushed a Docker image for this.

@rfay

rfay commented Mar 11, 2026 •

Copy link
Copy Markdown
Member

Analysis: Why `/usr/sbin` and `/usr/bin` were made world-writeable

The `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:

  1. `ln -sf /usr/sbin/php-fpm${VERSION} /usr/sbin/php-fpm` — creating this symlink at container startup to switch PHP versions requires write permission on `/usr/sbin`.
  2. `update-alternatives --set php /usr/bin/php${VERSION}` — requires write access to `/usr/bin` (and `/etc/alternatives`) when run as non-root.

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.

@rfay

rfay commented Mar 11, 2026

Copy link
Copy Markdown
Member

I'll look at the history before this also

@AkibaAT

AkibaAT commented Mar 11, 2026 •

Copy link
Copy Markdown
Contributor Author

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.

@rfay

rfay commented Mar 11, 2026 •

Copy link
Copy Markdown
Member

What do you think about /usr/local/bin being writable?

@AkibaAT

AkibaAT commented Mar 11, 2026

Copy link
Copy Markdown
Contributor Author

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.

@rfay

rfay commented Mar 11, 2026

Copy link
Copy Markdown
Member

And drush is only symlinked for long-outdated drupal6/7. It could easily go as a symlink in ~/bin or ~/.local/bin etc

@rfay

rfay commented Mar 11, 2026

Copy link
Copy Markdown
Member

Many activities can be done with sudo if they're for normal development situations.

@stucki

stucki commented Mar 18, 2026

Copy link
Copy Markdown
Contributor

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.

@rfay

rfay commented Mar 25, 2026

Copy link
Copy Markdown
Member

I note that the problem here prevents sudo apt update && sudo apt install -y memcached

@rfay

rfay commented Mar 25, 2026

Copy link
Copy Markdown
Member

I think we should probably get this into upcoming release, either as is or with improvements.

@stasadev
stasadev marked this pull request as ready for review March 25, 2026 14:22
@stasadev
stasadev requested a review from a team as a code owner March 25, 2026 14:22
@stasadev
stasadev merged commit b07a32a into ddev:main Mar 25, 2026
36 checks passed
@AkibaAT
AkibaAT deleted the 20260303_akibaat_reduce_world_writeables branch March 25, 2026 16:34
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

bugfix dependencies Pull requests that update a dependency file

Projects

None yet

Development

Successfully merging this pull request may close these issues.

adduser broken in 1.25.x due to world writeable PATH

4 participants