Repository navigation
fix: make custom commands executable without dropping group-write or ACLs, fixes #9031 - #9032
Conversation
|
Download this PR's build for your OS and architecture with: ddev utility download-ddev --pr 9032Or download the artifact for your OS and architecture directly:
See Testing a PR. |
|
The first thing to do... is see if we even have needed to chmod. I suspect we haven't needed to chmod at all for years. |
|
I do find that the chmod is currently required. I'm not entirely sure what your situation is where you're apparently commiting files without the x mode? I don't object to this as it is, but I'm pretty sure we could change to using bash to execute the commands on the host like we do in the container (where it doesn't have to have the x). |
It's committed as 775, but DDEV overrides it to 755 in v1.25.5
We have |
stasadev
left a comment
There was a problem hiding this comment.
This fixes the reported case. Three changes before merge:
-
Add x wherever r is set instead of skipping files that already have owner-x, so a 664 command becomes 775 instead of 755. See the inline suggestion, then add this helper before
isCustomCommandInArgs:// makeExecutable adds an exec bit wherever the file has a read bit, so a // custom command runs without losing group-write or the POSIX ACL mask. // The owner always gets read, since DDEV parses the file's directives. func makeExecutable(path string) { if si, err := os.Stat(path); err == nil { m := si.Mode().Perm() | 0400 _ = util.Chmod(path, m|(m&0444)>>2) } }
-
Replace both
_ = util.Chmod(autocompletePathOnHost, 0755)withmakeExecutable(autocompletePathOnHost). Right now.ddev/commands/*/autocomplete/*is still reset to 755 on every run. -
Apply the inline test suggestion, which also covers 664 and an autocomplete script. Then update the PR body: the first limit is gone, and the second one doesn't apply to web and db, which run as
$DDEV_UID, the owner of the file, so 700 and 750 still work there.
🤖 Reviewed with assistance from Claude Code
Both happen:
Updated the PR title and body to reflect the changes. |
rfay
left a comment
There was a problem hiding this comment.
Works great. Simple and elegant solution to a very obscure (and probably unsupported) problem.
7b71937 to
5bdbdb7
Compare
|
Rebased |
|
🎉 This PR is included in the v1.25.6 release. |
Short Summary (TL;DR)
Every ddev invocation rewrote custom command files to
0755, stripping group-write and capping POSIX ACLs.The chmod now runs only when the file has no owner-executable bit, so files that are already executable keep their mode.ddev now adds an exec bit wherever the file has a read bit, so commands become executable without losing group-write or the ACL mask.The Issue
addCustomCommandsFromDir()chmod'ed every custom command file to0755on every ddev invocation, includingddev --versionandddev describe. That stripped group-write from plain modes and capped the POSIX ACL mask tor-x, so in shared-group setups teammates lost write access to.ddev/commands/until someone re-appliedchmod g+w, and the next invocation broke it again.How This PR Solves The Issue
The chmod now runs only when the file has no owner-executable bit. Files that already have owner-exec keep their mode and ACLs; files without any exec bit still become0755as before, which keeps the guarantee from #1861 that custom commands are executable. This implements variant 1 from this comment.Two limits of that approach:- A command file that arrives without an exec bit, for example0664from agit pullunderumask 002, is still rewritten to0755on its first ddev invocation and loses group-write and the ACL mask once. After that it has owner-exec and is left alone.- Project commands run in a container are bind-mounted with their host mode and executed by the container user. On Linux, a file with owner-exec but no other-exec (0700,0750) used with a non-rootx-ddev.container-userwas made0755before and is now left as-is, so that user can no longer execute it. With the default root container user, and for host commands, nothing changes.A new
makeExecutable()helper derives the new mode from the file's current permissions: it adds an exec bit wherever the file has a read bit, and the owner always gets read, since DDEV parses the file's directives. A0644command becomes0755, a0664command becomes0775, and files that are already executable (0775,0700) are left untouched, so group-write and the POSIX ACL mask survive. The same helper now covers the.ddev/commands/*/autocomplete/scripts, which were previously reset to0755on every run.On Windows
os.Statreports no executable bits andos.Chmodonly toggles the read-only flag, sothe condition always holds there andthe behavior is the same as before.Manual Testing Instructions
.ddev/commands/host/foo,chmod 0775it, and run any ddev command from the project directory:0775.setfacl -m g:somegroup:rwX .ddev/commands/host/fooand invoke ddev again;getfacl -pkeepsmask::rwx.chmod 0644) and run ddev; it still becomes0755.On Linux, for a container command, setx-ddev.container-userto a non-root user: with0755the command runs, with0700it fails, as described above.0664command becomes0775, and a0775script in.ddev/commands/host/autocomplete/<command>stays0775.Automated Testing Overview
TestCustomCommandModePreservedincmd/ddev/cmd/commands_test.gocreates a project withtwo host commands, one athost commands at0775and one at0644, runsddev versioninside the project, and asserts the first keeps0775while the second becomes07550775,0664,0644,0700and0000, plus an autocomplete script at0775, runsddev versioninside the project, and asserts the resulting modes (0775,0775,0755,0700,0500,0775). It fails without the change and passes with it. The test is skipped on Windows, which has no exec bits. It does not useSkipUnlessDefaultEnvironment, so it also runs on rootless Docker and Mutagen setups whereTestCustomCommandsskips.Release/Deployment Notes
Custom commands that are already executable are no longer rewritten to
0755on every invocation. Two things to know:Command files without an exec bit are still made0755once, which can strip group-write on that first invocation.0644becomes0755,0664becomes0775,0000becomes0500.On Linux, container commands executed by a non-rootx-ddev.container-userneed the file to be executable by that user; such files were previously normalized to0755automatically.$DDEV_UID, the owner of the file, so container commands with private modes like0700keep working.