-
Notifications
You must be signed in to change notification settings - Fork 4.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
Handle folder permissions in wp-env #22515
Comments
note: blocking some tests here: #22454 (comment) |
This happens because wp-env assumes that the user id's between systems will be consistent, ie. that the An example of this is https://github.com/WordPress/gutenberg/blob/master/packages/env/lib/wordpress.js#L36-L48 where it I was looking into this yesterday, and I have a few ideas that I hashed out, one of which worked, I just need to explore it further (I was testing in an interactive GitHub action, so limited patching ability) Another option was to alter the upstream The other option is that the WordPress mount and everything under it could just be |
Unfortunately, we have many examples of this too. :( Even chmod 777 on the whole mount would be an improvement to scattering it around everywhere.
This sounds pretty great! Is it possible to modify this user without having to change images (which seems like a large undertaking, particularly since multiple images are used)? For example, the |
Thankfully with Docker you don't have to completely change the upstream images, creating a "new local image" from the upstream image is a few extra lines of code, effectively you can run a few extra CLI commands between the upstreams commands and the upstreams execution point. It does however add a few seconds (and an extra 2 temporary docker container builds) to the bootup process. The other option is that you change the entrypoint, the "default command" that executes when you start a docket container, to be a wrapper script that's effectively I'm looking at the first option today :)
Unfortunately the
I wouldn't call myself an expert, but I've run into these problems myself and researched such things a lot! |
Thank you for investigating! I look forward to learning more about it |
Not fully tested, but master...dd32:fix/wp-env-users is basically what I was thinking of. It's working for me in my testing on linux/mac, I suspect it might not work for Windows systems - I'd need to spin up a Windows box to try. |
Nice! Do you think similar changes would be needed for the |
If the proposed changes work over other environments, then it would make sense to also add it to the other containers. The I hadn't dug too deep into the It may make more sense to standardise on what's done there, running as a |
Nice. I think theoretically change away from |
Found this issue when I was having permissions issues when using rootless docker on Linux. It may be an edge-case that only needs documentation, but it would be great if the solution for this issue also worked with rootless docker. (And I can help test that scenario when a PR becomes available) |
I'm trying to get wp-env working on a Linux environment and I'm facing this issue as well, although the issue seems more severe than is being described here. Namely, the files aren't even readable by the
It seems when running docker-compose like here: gutenberg/packages/env/lib/wordpress.js Lines 27 to 33 in ace0643
It is running as the
The result is that when WP-CLI runs its $wp_exists = $this->wp_exists();
$wp_is_readable = $this->wp_is_readable();
if ( ! $wp_exists || ! $wp_is_readable ) { Because Is this a problem then with
Me too! |
Nice investigation! That could explain why it's not happening to everyone. Depending on your .wp-env config, the default is to just use the WordPress files from the
wp-env isn't doing anything to set permissions. I wonder if there's a kind of conflict overriding the permissions in the Development docker image with a local git source? As a side note, I used wp-env successfully on both Arch and Ubuntu, and it's definitely running on Linux in CI as well. I'm super curious why this issue is not coming up consistently! |
I'm trying this with the Gutenberg repo. I was able to get chmod -R 755 . Once that was done then WP-CLI was able to read the files properly. So it does seem like insufficient file permissions are indeed the problem. I don't know why either, however. |
For reference, here are the permissions on my working copy (on macOS): $ docker exec -it 93b83f01977a ls -laF
total 212
drwxr-xr-x 24 root root 768 Apr 22 22:33 ./
drwxr-xr-x 1 root root 4096 Apr 20 11:18 ../
drwxr-xr-x 14 root root 448 Apr 22 22:33 .git/
-rw-r--r-- 1 root root 405 Jan 5 21:49 index.php
-rw-r--r-- 1 root root 19915 Jan 5 21:49 license.txt
-rwxrwxrwx 1 root root 5839 Apr 22 22:33 phpunit-wp-config.php*
-rw-r--r-- 1 root root 7437 Jan 5 21:49 readme.html
-rw-r--r-- 1 root root 7165 Jan 5 21:49 wp-activate.php
drwxr-xr-x 101 www-data www-data 3232 Apr 22 22:33 wp-admin/
-rw-r--r-- 1 root root 351 Jan 5 21:49 wp-blog-header.php
-rw-r--r-- 1 root root 2338 Jan 5 21:49 wp-comments-post.php
-rw-r--r-- 1 root root 3001 Jan 5 21:49 wp-config-sample.php
-rw-r--r-- 1 www-data www-data 5881 Apr 15 21:08 wp-config.php
drwxr-xr-x 6 root root 192 Jan 5 21:50 wp-content/
-rw-r--r-- 1 root root 3939 Jan 5 21:49 wp-cron.php
drwxr-xr-x 242 www-data www-data 7744 Apr 22 22:33 wp-includes/
-rw-r--r-- 1 root root 2496 Jan 5 21:49 wp-links-opml.php
-rw-r--r-- 1 www-data www-data 3900 Jan 5 21:49 wp-load.php
-rw-r--r-- 1 root root 47914 Apr 22 22:33 wp-login.php
-rw-r--r-- 1 root root 8582 Jan 5 21:49 wp-mail.php
-rw-r--r-- 1 www-data www-data 23025 Jan 5 21:49 wp-settings.php
-rw-r--r-- 1 root root 31959 Jan 5 21:49 wp-signup.php
-rw-r--r-- 1 root root 4747 Jan 5 21:49 wp-trackback.php
-rw-r--r-- 1 root root 3236 Jan 5 21:49 xmlrpc.php Should we then add |
Sounds good to me, but I'm no authority on these matters 😄 |
Why not just go ahead and |
Apologies for the delay, been fairly busy! I experimented with; await dockerCompose.exec( 'wordpress', 'chmod -R 777 .', dockerComposeConfig );
await dockerCompose.exec( 'tests-wordpress', 'chmod -R 777 .', dockerComposeConfig ); put right around here: gutenberg/packages/env/lib/commands/start.js Line 144 in 1b9fe38
Essentially, right after downloading and starting the docker images, but before configuring anything else. After trying this, it did work correctly -- everything has rwx permissions from ls, but I noticed I now have ~7000 VCS changes. So I'm assuming that this is updating permissions in my Gutenberg checkout, which I think we want to avoid! |
Oh right. We should avoid touching the execute bit for files because that is tracked by Git. So So I think files should get 666 and directories should get 777: await dockerCompose.exec( 'wordpress', 'find wordpress tests-wordpress -type d -exec chmod 777 {} +', dockerComposeConfig );
await dockerCompose.exec( 'wordpress', 'find wordpress tests-wordpress -type f -exec chmod 666 {} +', dockerComposeConfig ); Either that, or when cloning the repo the git config core.filemode false |
Toying around with something like this: const ex = ( container, cmd ) =>
dockerCompose.exec( container, cmd, dockerComposeConfig );
await Promise.all( [
ex( 'wordpress', 'find -type d -exec chmod 777 {} +' ),
ex( 'wordpress', 'find -type f -exec chmod 666 {} +' ),
ex( 'tests-wordpress', 'find -type d -exec chmod 777 {} +' ),
ex( 'tests-wordpress', 'find -type f -exec chmod 666 {} +' ),
] ); The performance is really poor. There are a ton of files -- for example, it's doing stuff on I'm not loving this approach, partly because of the performance, but also because I don't love the idea of setting permissions on user's directories which wp-env doesn't "own." So I went back to looking at the download source function, and tried using fs.chmod to set 777 permissions on the local filesystem instead of doing it from docker... but I'm unsure if this fixes the root problem. Do you have a way to test it? I made a draft PR here: #40864 |
Oh, yeah, this should be excluding |
Continuing on from https://github.com/WordPress/gutenberg/pull/40864/files#r875265169: But then again, like you said, this will take awhile to run. What I don't understand is why the Docker user downloading WordPress is not the same user who is actually running the site. If the user was the same, then no permissions changes would be needed at all. |
What's a current workaround for this issue? I am struggling to get It works locally, but not in a GitHub Actions environment. |
I don't know if it'll help in this instance, but There was also a lot more discussion on this recent PR about this issue: #42867. The general idea is that docker makes this harder than it should be, and that we might need to introduce something like https://github.com/boxboat/fixuid to really solve the issue 🤔 |
If it helps, this is what I ended up doing to ensure I can install languages with WP-CLI on the tests instance: WP_ENV_DIR=$(npm run wp-env install-path --silent 2>&1 | head -1)
cd $WP_ENV_DIR
mkdir -p tests-WordPress/wp-content/languages tests-WordPress/wp-content/upgrade
chmod -R 767 tests-WordPress/wp-content/languages tests-WordPress/wp-content/upgrade
cd -
npm run wp-env run tests-cli "wp language core install de_CH de_DE es_ES fr_FR it_IT" |
I dove really deep into this issue today. While our
Approaching this as an ownership problem instead of a permission problem might help us reach a better solution that is minimally invasive enough to be implemented in
As a result of the above changes:
I think the only caveat here is that anything mapped using a local path will still have permission issues in the As an aside, currently, any files or folders created by the What do you think @noahtallen? |
Thanks for doing a deep dive! I really appreciate it. Could we change the user of the CLI environments to deal with the locally mapped file issue? (Including ones managed by wp-env?) One thing which came up recently is that the WordPress source code is a locally mapped directory via git (to better handle setting the correct version). As a result, this makes the surface area for problems fairly large. There was another great summary of the issue recently here: #45592 (comment) The prevailing thought was to use fixuid in our dockerfile. Any thoughts about how that connects to this issue? |
Thank you for linking that issue @noahtallen; there is a lot of great ideas and detail there. One thing in particular that it made apparent is that it's important that files created by the
I would prefer we don't use any external tools in As far as I can tell, this might be the best course of action:
The end result is that you have I'm going to set aside some time today to poke at this solution and see if it works as well as I expect it to. If so, I'll put up a PR and we can see if it works for folks in the other issue. |
Is your feature request related to a problem? Please describe.
In some recent merged PRs, there's been a requirement to change the permissions of certain folders to be writable when using
wp-env
, in particular when using travis.The way this is handled should be consistent, and there may also be a requirement to handle other folders (e.g. all of the upload folder).
It'd also be good to get an understanding of why this is required in certain environments.
Previous examples:
Describe the solution you'd like
Open to suggestions, but the code should be made consistent as a first improvement.
The text was updated successfully, but these errors were encountered: