You signed in with another tab or window. Reload to refresh your session.You signed out in another tab or window. Reload to refresh your session.You switched accounts on another tab or window. Reload to refresh your session.Dismiss alert
{{ message }}
Repository navigation
ext/ffi/tests/300.phpt test is failing on Alpine linux #9139
Looking at the code, this error is triggered when running as root and opcache.preload_user was not defined. According to the doc, opcache.preload_user must be defined when running as root.
We could clarify the error message.
Reacted by Christoph M. Becker and Michael Voříšek
I searched all occurences of opcache.preload_user in tests and ext/ffi/tests/bug78761.phpt test does not fail. It is because ffi.enable=1 is not defined there?
Would it also be possible to run the tests on Alpine as regular user?
We can. Why is opcache.preload_user actually so dangerous to require non root user? In Docker, it is very common to run everything as root and rely on Docker isolation. So maybe such arbitrary limitation should be removed complete.
Fatal error: Uncaught FFI\Exception: FFI::load() doesn't work in conjunction with "opcache.preload_user". Use "ffi.preload" instead.
We should skip this test when ran as root.
I also think that we should execute tests as a non root user.
I searched all occurences of opcache.preload_user in tests and ext/ffi/tests/bug78761.phpt test does not fail. It is because ffi.enable=1 is not defined there?
Can fork() be skipped entirely when pw->pw_uid == 0? preload_user would be still required for root, just to make sure, but FFI::load() would work on root.
Is there anything againt allowing preload as a root (/wo opcache.preload_user)?
I've tried to look for particular reasons for this. What I've found is that when running Apache mod_php, the function accel_finish_startup is called before Apache switches to an unprivileged user. This is because extension startup happens in the SAPI's main process.
People wouldn't expect their PHP scripts to be loaded/executed as root when they have configured Apache to run as an unprivileged user.
So opcache.preload_user is a workaround for this. However it's easy to miss this fact or to forget about this, which would be a security issue. The fact that opcache.preload is forbidden when the current user is root and opcache.preload_user is unset prevents this: It is not possible to forget about this.
This also explains why the error message is worded this way: "opcache.preload_user" has not been defined.
It's possible that FPM and other SAPIs work in a similar way.
Can fork() be skipped entirely when pw->pw_uid == 0? preload_user would be still required for root, just to make sure, but FFI::load() would work on root.
It would be actually good to have one of the pipeline run as root possibly as for example fpm often runs under root. Currently we have got just one test specific to root but there might be more in the future. Think the best solution is to skip it if run under root.
In terms of opcache preloading and fpm, you get the same issue so that preload_user is needed there to work correctly. However it might still not resolve all of the issues as there can be multiple pools to run under different users and then it might not really work because opcache is shared between pools which is not ideal. You can see some discussion on the related issue in #8072 .
Reacted by Christoph M. Becker and Arnaud Le Blanc
People wouldn't expect their PHP scripts to be loaded/executed as root when they have configured Apache to run as an unprivileged user.
In that light, doesn't it make sense to have the check (requiring opcache.preload_user) only for web SAPIs, and not check it on CLI SAPIs - because there you'll anyway run the preloaded code as the executing user, entirely within peoples expectations.
Activity
cmb69 commentedon Jul 26, 2022
This test has a skipif clause which checks the
opcache.preload_useris not empty. I have no idea why that doesn't skip the test.mvorisek commentedon Jul 26, 2022
Yes, but it skips the test if the
opcache.preload_useris non-empty. @dstogov you are the author of the test, can you please have a look?arnaud-lb commentedon Jul 28, 2022
Looking at the code, this error is triggered when running as root and
opcache.preload_userwas not defined. According to the doc,opcache.preload_usermust be defined when running as root.We could clarify the error message.
cmb69 commentedon Jul 28, 2022
Would it also be possible to run the tests on Alpine as regular user?
mvorisek commentedon Jul 29, 2022
I searched all occurences of
opcache.preload_userin tests andext/ffi/tests/bug78761.phpttest does not fail. It is becauseffi.enable=1is not defined there?We can. Why is
opcache.preload_useractually so dangerous to require non root user? In Docker, it is very common to run everything asrootand rely on Docker isolation. So maybe such arbitrary limitation should be removed complete.KapitanOczywisty commentedon Jul 29, 2022
Seems like
opcache.preload_userdo not require non-root user.php-src/.cirrus.yml
Lines 23 to 24 in fdb9e3a
arnaud-lb commentedon Aug 5, 2022
Adding
opcache.preload_useryields a new error:We should skip this test when ran as root.
I also think that we should execute tests as a non root user.
This test also fails here
cmb69 commentedon Aug 5, 2022
Isn't this resolved via 1c9a49e?
ACK
arnaud-lb commentedon Aug 5, 2022
With 1c9a49e we get the new error:
That's because
opcache.preload_userpreloads in a separate processmvorisek commentedon Aug 5, 2022
I confirm this issue: https://github.com/php/php-src/runs/7694180097?check_suite_focus=true#step:10:92
Is there anything againt allowing preload as a root (/wo
opcache.preload_user)?KapitanOczywisty commentedon Aug 5, 2022
php-src/ext/opcache/ZendAccelerator.c
Line 4621 in ad04345
Can
fork()be skipped entirely whenpw->pw_uid == 0?preload_userwould be still required forroot, just to make sure, butFFI::load()would work onroot.Crude patch:
arnaud-lb commentedon Aug 7, 2022
I've tried to look for particular reasons for this. What I've found is that when running Apache mod_php, the function
accel_finish_startupis called before Apache switches to an unprivileged user. This is because extension startup happens in the SAPI's main process.People wouldn't expect their PHP scripts to be loaded/executed as root when they have configured Apache to run as an unprivileged user.
So
opcache.preload_useris a workaround for this. However it's easy to miss this fact or to forget about this, which would be a security issue. The fact thatopcache.preloadis forbidden when the current user isrootandopcache.preload_useris unset prevents this: It is not possible to forget about this.This also explains why the error message is worded this way:
"opcache.preload_user" has not been defined.It's possible that FPM and other SAPIs work in a similar way.
Yes, I think so
arnaud-lb commentedon Aug 7, 2022
For the purpose of #8621, we could run the tests as a non-root user, or skip this test when ran as root.
We could then allow FFI preloading to work a root in a separate PR.
bukka commentedon Aug 9, 2022
It would be actually good to have one of the pipeline run as root possibly as for example fpm often runs under root. Currently we have got just one test specific to root but there might be more in the future. Think the best solution is to skip it if run under root.
In terms of opcache preloading and fpm, you get the same issue so that preload_user is needed there to work correctly. However it might still not resolve all of the issues as there can be multiple pools to run under different users and then it might not really work because opcache is shared between pools which is not ideal. You can see some discussion on the related issue in #8072 .
Fix phpGH-9139
bwoebi commentedon Sep 6, 2022
In that light, doesn't it make sense to have the check (requiring
opcache.preload_user) only for web SAPIs, and not check it on CLI SAPIs - because there you'll anyway run the preloaded code as the executing user, entirely within peoples expectations.Fix GH-9139: Allow FFI in opcache.preload when opcache.preload_user=…