CLI: Setup fake auth

Since version 2.7.x CLI actions load all enabled modules automatically.
This includes launching configuration.php and run.php. Though code
in those files should be restricted to a supported set of functions,
module devs may write any code here. If a module requires authentication
in those files, CLI actions fail because there is no auth possible.
With this patch, we setup a fake user named "cli" w/o any permission when
running CLI actions.
This commit is contained in:
Eric Lippmann 2020-02-03 10:38:58 +01:00
parent 990a5e4d61
commit 3361cac59a

View File

@ -5,6 +5,7 @@ namespace Icinga\Application;
use Icinga\Application\Platform;
use Icinga\Application\ApplicationBootstrap;
use Icinga\Authentication\Auth;
use Icinga\Cli\Params;
use Icinga\Cli\Loader;
use Icinga\Cli\Screen;
@ -12,6 +13,7 @@ use Icinga\Application\Logger;
use Icinga\Application\Benchmark;
use Icinga\Data\ConfigObject;
use Icinga\Exception\ProgrammingError;
use Icinga\User;
require_once __DIR__ . '/ApplicationBootstrap.php';
@ -43,7 +45,8 @@ class Cli extends ApplicationBootstrap
->setupLogger()
->setupModuleManager()
->setupUserBackendFactory()
->loadSetupModuleIfNecessary();
->loadSetupModuleIfNecessary()
->setupFakeAuthentication();
}
/**
@ -87,6 +90,13 @@ class Cli extends ApplicationBootstrap
return $this;
}
protected function setupFakeAuthentication()
{
Auth::getInstance()->setUser(new User('cli'));
return $this;
}
public function cliLoader()
{
if ($this->cliLoader === null) {