Page MenuHomePhabricator

Allow deployers to get a php REPL environment inside the mw-debug pods
Closed, ResolvedPublic

Description

We want deployers to be able to run a MediaWiki REPL inside kubernetes.

The way to do this is as follows:

  • read wmfMasterDatacenter from etcd
  • Find which pods are running right now in mw-debug in that dc, and pick one at random
  • Run, as superuser, KUBECONFIG=/etc/kubernetes/admin-eqiad.config kubectl -n mw-debug exec <pod> -c mediawiki-pinkunicorn-app -ti -- php /srv/mediawiki/multiversion/MWScript.php shell.php --wiki <wiki>

This would limit deployers to just execute this script as superusers and not have the larger issues related to being able to execute random scripts, which is a larger problem to solve.

Event Timeline

Joe triaged this task as High priority.
Joe moved this task from Incoming 🐫 to Doing 😎 on the serviceops board.

Change 936046 had a related patch set uploaded (by Giuseppe Lavagetto; author: Giuseppe Lavagetto):

[operations/puppet@production] deployment_server: add REPL for mw-debug

https://gerrit.wikimedia.org/r/936046

Change 936046 merged by Giuseppe Lavagetto:

[operations/puppet@production] deployment_server: add REPL for mw-debug

https://gerrit.wikimedia.org/r/936046

I tried the new REPL prompt per @Joe's request, and I have two suggestions for consideration:

  • My first command to run was sudo mw-debug-repl cswiki (and I expected a REPL prompt for cswiki). I recevied aawiki's prompt, because the script expects -w cswiki.
  • The current parameter parsing is unintuitive for deployers, as it differs from mwscript, which uses --wiki (or first unnamed parameter after script name; cf. mwscript shell.php cswiki)
  • Most deployer-focused scripts automatically sudo as the right user, which means the deployer doesn't have to think about sudo'ing as the right user first. I suggest doing that here as well.

In any way, thanks again @Joe for creating this script!

@Urbanecm sadly the last request isn't something we can actually do, as it would complicate quite a bit how the sudo rules would work. I'll add a check for the user being root and recommending running the command as root.

@Urbanecm sadly the last request isn't something we can actually do, as it would complicate quite a bit how the sudo rules would work. I'll add a check for the user being root and recommending running the command as root.

Thanks for the info. I don't understand why though. Does adding [[ "$UID" == 0 ]] || exec sudo "$0" "$@" or similar to the begining of the script break sudo rules in some way that I'm missing?

Change 936280 had a related patch set uploaded (by Giuseppe Lavagetto; author: Giuseppe Lavagetto):

[operations/puppet@production] mw-debug-repl: improve UX

https://gerrit.wikimedia.org/r/936280

@Urbanecm sadly the last request isn't something we can actually do, as it would complicate quite a bit how the sudo rules would work. I'll add a check for the user being root and recommending running the command as root.

Thanks for the info. I don't understand why though. Does adding [[ "$UID" == 0 ]] || exec sudo "$0" "$@" or similar to the begining of the script break sudo rules in some way that I'm missing?

Oh yeah, that wouldn't. I just didn't think of it :)

Change 936280 merged by Giuseppe Lavagetto:

[operations/puppet@production] mw-debug-repl: improve UX

https://gerrit.wikimedia.org/r/936280

Change 936394 had a related patch set uploaded (by Giuseppe Lavagetto; author: Giuseppe Lavagetto):

[operations/puppet@production] mediawiki::repl: allow execution from everyone

https://gerrit.wikimedia.org/r/936394

Change 936394 merged by Giuseppe Lavagetto:

[operations/puppet@production] mediawiki::repl: allow execution from everyone

https://gerrit.wikimedia.org/r/936394