Background
I spent some time looking into T393444: Wiki creations not being reported to newprojects list. The addWiki.php script we use to create new project sends an email to newprojects@lists.wikimedia.org to tell everyone that a new project has been created (currently broken, but that's being looked into in the linked task). The script's logic contains something like this:
// [...] $user = getenv( 'SUDO_USER' ); $body = "A new wiki was created by $user at $time for \"$siteName\".\n" . "Once the wiki is fully set up, it'll be visible at $url"; // [...] return UserMailer::send( $to, $from, "New wiki: $wiki", $body );
This code is supposed to find the username of whoever started it (using the SUDO_USER environment variable), and include it in the announcement email.
Problem
As of writing, mwscript-k8s does not populate this variable:
[urbanecm@deploy1003 ~]$ mwscript-k8s --attach shell.php -- --wiki=testwiki
⏳ Starting shell.php on Kubernetes as job mw-script.eqiad.eqb5bju6 ...
🚀 Job is running.
ℹ️ Expecting a prompt but don't see it? Due to a race condition, the beginning of the output might be missing. Try pressing enter.
📜 Attached to stdin/stdout:
> getenv('SUDO_USER')
= false
> ^D
INFO Ctrl+D.
[urbanecm@deploy1003 ~]$This is presumably because we do not actually make use of sudo (and even if we did, it would be from an in-container user rather than the executing user's name on deploy1003).
I tried to check whether there is a comparable env variable that would contain the username, but it doesn't seem there is:
> $envs = getenv();
> foreach($envs as $key => $value) {
. if(str_contains($value, 'urbanecm')) {
. var_dump([$key, $value]);
. break;
. }
. }
>Proposed solution
Inject an environment variable that would include the name of the shell user who initiated the script.
Alternatively, considering addWiki.php seems to be the only user of SUDO_USER in MediaWiki, we might also elect to remove the name from the announcement instead.