- Issue created by @mondrake
- First commit to issue fork.
- ๐ช๐ธSpain fjgarlinThe MR shows permission denied failures: https://git.drupalcode.org/issue/drupal-3476189/-/jobs/2831557 
- ๐บ๐ธUnited States cmlara-1 as this could hide real issues in file access. It is less than I originally thought (as the webserver is not running root part of functional tests will still be non-root) however that still leaves kernel and unit tests to run excessive permissions. Sudo supports passing all environment variables using the -E flag. Tagging as needs an IS a update. I noted in the linked issues that it appeared the problem was that run-tests.sh appeared to accidentally call sudo inside its loops (probably some how confused when looking at argv would be my guess) I would suggest core debug and fixing the underlying fault in run-tests.sh instead of switching to a privileged user for testing. 
- ๐ช๐ธSpain fjgarlinThe MR made just shows the problem. Itโs not the solution )or at least all of it). I agree that root should not be needed. I think that we agree on the solution but maybe the issue description or title does not reflect that. 
- ๐บ๐ธUnited States cmlaraFew minutes with the debugger. Global $php is indeed being set to the sudo path. I' have not run a full test run however it appears the solution to the root fault is to move elseif ($sudo = getenv('SUDO_COMMAND')) {block beforeelseif ($php_env = getenv('_')) {insimpletest_script_init()(check for sudo before checking if _ is set) 
- ๐ฎ๐นItaly mondrake ๐ฎ๐นIt looks like we do not agree on the solution yet, actually. I think first of all we need to agree on: what is the user (meaning, the op sys user) that should run PHPUnit tests in the context of GitLabCI? Then, with a decision, adjust accordingly. At the moment in HEAD it's www-databecause of the usage ofsudo.However, I repeat my comment from the related issue #3475974-27: Add www-data user to root group so all env vars as passed to run-tests.sh โ : In fact, I think we should just be running tests as root, like we run all other tasks in these jobs.www-datais, or at least it should be, the user for the Apache webserver to deliver pages: using it to run Unit or Kernel tests is just, IMHO, wrong, and possibly a remnant of simpletest times. Functional(Javascript) tests are different, and IMHO the tests should run underroot, and the SUT underwww-databecause these tests check the results of pages delivered by the webserver.Elaborating a bit: I think we should run the test without sudo, just with whatever user we are executing the rest of the commands in the context of the test job. In CI, this happens to be root.
- ๐บ๐ธUnited States cmlaraCounter view: Generally you want all tests that execute code to run as close to production as possible, this includes unit and kernel tests. Both of these can access the file system and running as root can mask faults. In production it is unlikely the process running any of the Drupal code will have root privileges. All our other tests (cspell, phpstan, lint, etc) are not executing the code they are just reading it for analysis as such the execution user is not relevant to the code. 
- ๐ฎ๐นItaly mondrake ๐ฎ๐นMR!9585 goes in the alternative direction of using the -Eflag withsudoto keep all the env variables.Also possibly related, ๐ Change run-tests.sh to use Symfony Process instead of proc_open Active . 
- ๐บ๐ธUnited States cmlaraFixed up the tests to pass in HOME to clean up the small few errors that remained. The last two remaining errors are related to Telemetry. It appears that OTEL_COLLECTORis being set to a literal string$OTEL_COLLECTORon cursory glance I'm not 100% sure why.Perhaps Gitlab does this when its an undefined value? Though I don't understand why it would work before the sudo. Unless this was kept in an environment file for user www-data we are no longer loading, although I don't see any code doing so on cursory glance either. 
- ๐ฎ๐นItaly mondrake ๐ฎ๐นmondrake โ changed the visibility of the branch 3476189-drop-using-sudo to hidden. 
- ๐ช๐ธSpain fjgarlinReally minor feedback in the MR. Two questions and a small character left. 
- ๐ช๐ธSpain fjgarlinI think this is a great improvement as we know can pass all variables via -Einstead of needing to pass one by one.
 There is some really minor feedback on the MR, some of it already addressed and some of it might just be a non-issue at all.This change will also simplify the solution for the gitlab_templatesrelated issue.I'm setting it to RTBC. 
- ๐ฎ๐นItaly mondrake ๐ฎ๐นAdded a test skip in case OTEL_COLLECTOR is empty. But not sure we want to skip the test overall in that case. Anyway, up for review. 
- ๐ฎ๐นItaly mondrake ๐ฎ๐นReverted last commit on a better thinking. Back to RTBC as it was. 
- ๐ฎ๐นItaly mondrake ๐ฎ๐นIMHO this needs backport to all branches currently tested so the parallel contrib issue can benefit as well. 
- ๐บ๐ธUnited States cmlaraIMHO this needs backport to all branches currently tested so the parallel contrib issue can benefit as well I will note gitlab_templates probably should just use the โphpflag for run-tests.sh as it allows them to support versions this canโt be backported for (existing tagged releases) for those who may do min/max testing.They could do the above today without waiting for this issue. 
- ๐ณ๐ฟNew Zealand quietoneEverything looks in order here, no unanswered questions. 
- ๐ฆ๐บAustralia larowlan ๐ฆ๐บ๐.au GMT+10Left one question on the MR 
- ๐ซ๐ทFrance andypostMaybe instead of using such a long sudocommand it's better to add simple wrapper-script tosource .test.envbefore running the command.
 Moreover it will make logs shorter and less noisy to parse!
- ๐ซ๐ทFrance andypostAlso it should be enough to use sufor this purpose so more secure environment
- ๐ฆ๐ฒArmenia murz Yerevan, ArmeniaNow we use sudo -u www-data -E HOME=/var/wwwto set the correct home directory path, butsudoprovides also-H, --set-homeoption that does the same, so maybe let's use it instead?
- ๐ฎ๐นItaly mondrake ๐ฎ๐น@murz that seems sensible; letโs try it and see if it works 
- ๐ฎ๐นItaly mondrake ๐ฎ๐นTests pass (apart from the usual bunch of random fails in functional ones), so it seems to be working. Setting back to RTBC. 
- ๐ฎ๐นItaly mondrake ๐ฎ๐นFrom https://linux.die.net/man/8/sudo, emphasis mine: -H' The -H (HOME) option requests that the security policy set the HOME environment variable to the home directory of the target user (root by default) as specified by the password database. Depending on the policy, this may be the default behavior. 
- ๐ฌ๐งUnited Kingdom longwave UKRe OTEL_COLLECTORthis is injected into the scheduled core performance test pipelines directly in GitLab.There is also code in PerformanceTestTrait::openTelemetryTracing() that skips sending to the collector if the variable is not set: $collector = getenv('OTEL_COLLECTOR'); if (!$collector) { return; }
- Status changed to RTBC11 months ago 3:56am 6 December 2024
- ๐ณ๐ฟNew Zealand quietoneI did a light review of the comment and I don't see any response to the suggestions by andypost in #24. 
- ๐ฎ๐นItaly mondrake ๐ฎ๐น#24 is above me, but to me it sounds like it can be a follow up anyway. 
- ๐ฌ๐งUnited Kingdom longwave UKAdded a comment about OTEL_COLLECTOR, setting it to the empty string is a bit confusing when we shouldn't need it at all - I think we can remove it entirely. 
- ๐ฎ๐นItaly mondrake ๐ฎ๐นI think the change is minor enough to let me RTBC back. Tests are green. 
- 
            
              longwave โ
             committed eba0136d on 11.x
Issue #3476189 by mondrake, cmlara, fjgarlin, murz, longwave, andypost,... 
 
- 
            
              longwave โ
             committed eba0136d on 11.x
- ๐ฎ๐นItaly mondrake ๐ฎ๐นSlack discussion on backport: https://drupal.slack.com/archives/CGKLP028K/p1735851033816899 
- Automatically closed - issue fixed for 2 weeks with no activity.