shell: Optionally restrict commands' access with firejail
authorKunal Mehta <legoktm@member.fsf.org>
Wed, 18 Oct 2017 06:54:19 +0000 (23:54 -0700)
committerTim Starling <tstarling@wikimedia.org>
Tue, 28 Nov 2017 00:06:40 +0000 (00:06 +0000)
commitbdb5b592f444f4670070808048afcb0bb1adcc5a
treeadbc1178addde9ce93983b9ecc7c8a9057298e7b
parente4e7c5acf3e59895dae977c65cbf75ee0c08257b
shell: Optionally restrict commands' access with firejail

Introduces a FirejailCommand class, which can be used to add additional
restrictions to a command, for increased security. For now, firejail
containment needs to be enabled on a per-command basis.

The following restrictions are implemented:
* NO_ROOT - disallows any root access, including via setuid binaries
* SECCOMP - block dangerous syscalls with seccomp
* PRIVATE_DEV - create a private /dev
* NO_NETWORK - deny all network access
* NO_EXECVE - block the execve syscall

A convenient Shell::RESTRICT_DEFAULT is equivalent to NO_ROOT | SECCOMP
| PRIVATE_DEV, with the expectation that more restrictions may be added
to it in the future.

In addition, specific paths can be whitelisted with
Command::whitelistPaths(). Any file/directory that isn't whitelisted in
that top level directory (e.g. /srv) won't exist inside the firejail.

$wgShellRestrictionMethod can be set to false for no restriction system,
'firejail' to explicitly use it, or 'autodetect' to autodetect whatever
system is available. In the future the default should be changed to
autodetection once firejail is tested more.

Bug: T173370
Change-Id: Id74df0dbba40e1e7c07c4368aacffb6eb06a17c5
autoload.php
includes/DefaultSettings.php
includes/GitInfo.php
includes/ServiceWiring.php
includes/shell/Command.php
includes/shell/CommandFactory.php
includes/shell/FirejailCommand.php [new file with mode: 0644]
includes/shell/Shell.php
includes/shell/firejail.profile [new file with mode: 0644]
tests/phpunit/includes/shell/CommandFactoryTest.php
tests/phpunit/includes/shell/FirejailCommandTest.php [new file with mode: 0644]