From 3361cac59a920d9f518f74126d9731598d3789ce Mon Sep 17 00:00:00 2001 From: Eric Lippmann Date: Mon, 3 Feb 2020 10:38:58 +0100 Subject: [PATCH] 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. --- library/Icinga/Application/Cli.php | 12 +++++++++++- 1 file changed, 11 insertions(+), 1 deletion(-) diff --git a/library/Icinga/Application/Cli.php b/library/Icinga/Application/Cli.php index 243771919..194a86a52 100644 --- a/library/Icinga/Application/Cli.php +++ b/library/Icinga/Application/Cli.php @@ -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) {