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
fix(deploy): skip logging deploy key commands
Andras Bacsai1a5b8d3612cb
diff --git a/app/Jobs/ApplicationDeploymentJob.php b/app/Jobs/ApplicationDeploymentJob.phpindex 20eae036bd..3e46f34f5b 100644--- a/app/Jobs/ApplicationDeploymentJob.php+++ b/app/Jobs/ApplicationDeploymentJob.php@@ -2306,6 +2306,8 @@ class ApplicationDeploymentJob implements ShouldBeEncrypted, ShouldQueue],[executeInDocker($this->deployment_uuid, "echo '{$private_key}' | base64 -d | tee {$customSshKeyLocation} > /dev/null"),+ 'hidden' => true,+ 'skip_command_log' => true,],[executeInDocker($this->deployment_uuid, "chmod 600 {$customSshKeyLocation}"),diff --git a/app/Traits/ExecuteRemoteCommand.php b/app/Traits/ExecuteRemoteCommand.phpindex bb252148ab..4d989f406b 100644--- a/app/Traits/ExecuteRemoteCommand.php+++ b/app/Traits/ExecuteRemoteCommand.php@@ -79,6 +79,7 @@ trait ExecuteRemoteCommand$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);+ $skip_command_log = data_get($single_command, 'skip_command_log', false);$this->save = data_get($single_command, 'save');if ($this->server->isNonRoot()) {if (str($command)->startsWith('docker exec')) {@@ -91,7 +92,7 @@ trait ExecuteRemoteCommand// Check for cancellation before executing commandsif (isset($this->application_deployment_queue)) {$this->application_deployment_queue->refresh();- if ($this->application_deployment_queue->status === \App\Enums\ApplicationDeploymentStatus::CANCELLED_BY_USER->value) {+ if ($this->application_deployment_queue->status === ApplicationDeploymentStatus::CANCELLED_BY_USER->value) {throw new \RuntimeException('Deployment cancelled by user', 69420);}}@@ -103,7 +104,7 @@ trait ExecuteRemoteCommandwhile ($attempt < $maxRetries && ! $commandExecuted) {try {- $this->executeCommandWithProcess($command, $hidden, $customType, $append, $ignore_errors, $command_hidden);+ $this->executeCommandWithProcess($command, $hidden, $customType, $append, $ignore_errors, $command_hidden, $skip_command_log);$commandExecuted = true;} catch (\RuntimeException|DeploymentException $e) {$lastError = $e;@@ -119,7 +120,7 @@ trait ExecuteRemoteCommand// Check for cancellation during retry wait$this->application_deployment_queue->refresh();- if ($this->application_deployment_queue->status === \App\Enums\ApplicationDeploymentStatus::CANCELLED_BY_USER->value) {+ if ($this->application_deployment_queue->status === ApplicationDeploymentStatus::CANCELLED_BY_USER->value) {throw new \RuntimeException('Deployment cancelled by user during retry', 69420);}}@@ -153,9 +154,9 @@ trait ExecuteRemoteCommand/*** Execute the actual command with process handling*/- private function executeCommandWithProcess($command, $hidden, $customType, $append, $ignore_errors, $command_hidden = false)+ private function executeCommandWithProcess($command, $hidden, $customType, $append, $ignore_errors, $command_hidden = false, $skip_command_log = false){- if ($command_hidden && isset($this->application_deployment_queue)) {+ if ($command_hidden && ! $skip_command_log && isset($this->application_deployment_queue)) {$this->application_deployment_queue->addLogEntry('[CMD]: '.$this->redact_sensitive_info($command), hidden: true);}@@ -170,7 +171,7 @@ trait ExecuteRemoteCommand$sanitized_output = sanitize_utf8_text($output);$new_log_entry = [- 'command' => $command_hidden ? null : $this->redact_sensitive_info($command),+ 'command' => $skip_command_log || $command_hidden ? null : $this->redact_sensitive_info($command),'output' => $this->redact_sensitive_info($sanitized_output),'type' => $customType ?? ($type === 'err' ? 'stderr' : 'stdout'),'timestamp' => Carbon::now('UTC'),@@ -227,7 +228,7 @@ trait ExecuteRemoteCommand// Check if deployment was cancelled while command was runningif (isset($this->application_deployment_queue)) {$this->application_deployment_queue->refresh();- if ($this->application_deployment_queue->status === \App\Enums\ApplicationDeploymentStatus::CANCELLED_BY_USER->value) {+ if ($this->application_deployment_queue->status === ApplicationDeploymentStatus::CANCELLED_BY_USER->value) {throw new \RuntimeException('Deployment cancelled by user', 69420);}}diff --git a/tests/Unit/DeployKeyDedicatedPathTest.php b/tests/Unit/DeployKeyDedicatedPathTest.phpindex a3373f42a1..04fa08b26b 100644--- a/tests/Unit/DeployKeyDedicatedPathTest.php+++ b/tests/Unit/DeployKeyDedicatedPathTest.php@@ -19,6 +19,23 @@ afterEach(function () {*/$keyPath = '/root/.ssh/id_rsa_coolify_test-deployment-uuid';+it('skips logging the docker deploy key materialization command before ls-remote', function () {+ $source = file_get_contents(__DIR__.'/../../app/Jobs/ApplicationDeploymentJob.php');+ $commandPosition = strpos($source, 'base64 -d | tee {$customSshKeyLocation}');++ expect($commandPosition)->not->toBeFalse()+ ->and(substr($source, $commandPosition, 200))->toContain("'skip_command_log' => true");+});++it('supports skipping command log entries without adding a hidden command entry', function () {+ $source = file_get_contents(__DIR__.'/../../app/Traits/ExecuteRemoteCommand.php');++ expect($source)+ ->toContain('$skip_command_log = data_get($single_command, \'skip_command_log\', false);')+ ->toContain('if ($command_hidden && ! $skip_command_log && isset($this->application_deployment_queue))')+ ->toContain('\'command\' => $skip_command_log || $command_hidden ? null : $this->redact_sensitive_info($command),');+});+it('writes a deploy key to a per-deployment path and cleans it up for ls-remote on the host', function () use ($keyPath) {$privateKey = Mockery::mock(PrivateKey::class)->makePartial();$privateKey->shouldReceive('getAttribute')->with('private_key')->andReturn('fake-private-key');