An open-source, self-hostable PaaS alternative to Vercel, Heroku & Netlify that lets you easily deploy static sites, databases, full-stack applications and 360+ one-click services on your own servers.
PHP coolifydatabasesdeploymentdockerdocker-composeinertiajslaravelmariadbmysqlnextjsnodejsphppostgresredisself-hostedself-hostingserverstatic-sitesveltesvelte5
feat(deployment): add command_hidden flag to hide command text in logs
Andras Bacsai333cc9589ddc
diff --git a/app/Jobs/ApplicationDeploymentJob.php b/app/Jobs/ApplicationDeploymentJob.phpindex 2af380a45a..b39ab4f685 100644--- a/app/Jobs/ApplicationDeploymentJob.php+++ b/app/Jobs/ApplicationDeploymentJob.php@@ -783,7 +783,7 @@ class ApplicationDeploymentJob implements ShouldBeEncrypted, ShouldQueuetry {$this->execute_remote_command(- [executeInDocker($this->deployment_uuid, "cd {$this->workdir} && {$start_command}"), 'hidden' => true],+ [executeInDocker($this->deployment_uuid, "cd {$this->workdir} && {$start_command}"), 'hidden' => false, 'type' => 'stdout', 'command_hidden' => true],);} catch (\RuntimeException $e) {if (str_contains($e->getMessage(), "matching `'") || str_contains($e->getMessage(), 'unexpected EOF')) {@@ -801,7 +801,7 @@ class ApplicationDeploymentJob implements ShouldBeEncrypted, ShouldQueue$command .= " --env-file {$server_workdir}/.env";$command .= " --project-directory {$server_workdir} -f {$server_workdir}{$this->docker_compose_location} up -d";$this->execute_remote_command(- ['command' => $command, 'hidden' => true],+ ['command' => $command, 'hidden' => false, 'type' => 'stdout', 'command_hidden' => true],);}} else {@@ -818,11 +818,11 @@ class ApplicationDeploymentJob implements ShouldBeEncrypted, ShouldQueue$this->write_deployment_configurations();if ($this->preserveRepository) {$this->execute_remote_command(- ['command' => "cd {$server_workdir} && {$start_command}", 'hidden' => true],+ ['command' => "cd {$server_workdir} && {$start_command}", 'hidden' => false, 'type' => 'stdout', 'command_hidden' => true],);} else {$this->execute_remote_command(- [executeInDocker($this->deployment_uuid, "cd {$this->basedir} && {$start_command}"), 'hidden' => true],+ [executeInDocker($this->deployment_uuid, "cd {$this->basedir} && {$start_command}"), 'hidden' => false, 'type' => 'stdout', 'command_hidden' => true],);}} else {@@ -834,14 +834,14 @@ class ApplicationDeploymentJob implements ShouldBeEncrypted, ShouldQueue$this->write_deployment_configurations();$this->execute_remote_command(- ['command' => $command, 'hidden' => true],+ ['command' => $command, 'hidden' => false, 'type' => 'stdout', 'command_hidden' => true],);} else {// Always use .env file$command .= " --env-file {$this->workdir}/.env";$command .= " --project-name {$this->application->uuid} --project-directory {$this->workdir} -f {$this->workdir}{$this->docker_compose_location} up -d";$this->execute_remote_command(- [executeInDocker($this->deployment_uuid, $command), 'hidden' => true],+ [executeInDocker($this->deployment_uuid, $command), 'hidden' => false, 'type' => 'stdout', 'command_hidden' => true],);$this->write_deployment_configurations();}diff --git a/app/Traits/ExecuteRemoteCommand.php b/app/Traits/ExecuteRemoteCommand.phpindex 72e0adde8c..bb252148ab 100644--- a/app/Traits/ExecuteRemoteCommand.php+++ b/app/Traits/ExecuteRemoteCommand.php@@ -78,6 +78,7 @@ trait ExecuteRemoteCommand$customType = data_get($single_command, 'type');$ignore_errors = data_get($single_command, 'ignore_errors', false);$append = data_get($single_command, 'append', true);+ $command_hidden = data_get($single_command, 'command_hidden', false);$this->save = data_get($single_command, 'save');if ($this->server->isNonRoot()) {if (str($command)->startsWith('docker exec')) {@@ -102,7 +103,7 @@ trait ExecuteRemoteCommandwhile ($attempt < $maxRetries && ! $commandExecuted) {try {- $this->executeCommandWithProcess($command, $hidden, $customType, $append, $ignore_errors);+ $this->executeCommandWithProcess($command, $hidden, $customType, $append, $ignore_errors, $command_hidden);$commandExecuted = true;} catch (\RuntimeException|DeploymentException $e) {$lastError = $e;@@ -152,10 +153,14 @@ trait ExecuteRemoteCommand/*** Execute the actual command with process handling*/- private function executeCommandWithProcess($command, $hidden, $customType, $append, $ignore_errors)+ private function executeCommandWithProcess($command, $hidden, $customType, $append, $ignore_errors, $command_hidden = false){+ if ($command_hidden && isset($this->application_deployment_queue)) {+ $this->application_deployment_queue->addLogEntry('[CMD]: '.$this->redact_sensitive_info($command), hidden: true);+ }+$remote_command = SshMultiplexingHelper::generateSshCommand($this->server, $command);- $process = Process::timeout(config('constants.ssh.command_timeout'))->idleTimeout(3600)->start($remote_command, function (string $type, string $output) use ($command, $hidden, $customType, $append) {+ $process = Process::timeout(config('constants.ssh.command_timeout'))->idleTimeout(3600)->start($remote_command, function (string $type, string $output) use ($command, $hidden, $customType, $append, $command_hidden) {$output = str($output)->trim();if ($output->startsWith('╔')) {$output = "\n".$output;@@ -165,9 +170,9 @@ trait ExecuteRemoteCommand$sanitized_output = sanitize_utf8_text($output);$new_log_entry = [- 'command' => $this->redact_sensitive_info($command),+ 'command' => $command_hidden ? null : $this->redact_sensitive_info($command),'output' => $this->redact_sensitive_info($sanitized_output),- 'type' => $customType ?? $type === 'err' ? 'stderr' : 'stdout',+ 'type' => $customType ?? ($type === 'err' ? 'stderr' : 'stdout'),'timestamp' => Carbon::now('UTC'),'hidden' => $hidden,'batch' => static::$batch_counter,