From 6a52f518515f26a2b6be7b5ae5f24ba96c8928db Mon Sep 17 00:00:00 2001 From: peaklabs-dev <122374094+peaklabs-dev@users.noreply.github.com> Date: Fri, 7 Feb 2025 18:27:30 +0100 Subject: [PATCH] fix(ssl): get caCert correctly --- app/Actions/Database/StartMariadb.php | 9 ++++----- app/Actions/Database/StartMysql.php | 9 ++++----- app/Actions/Database/StartPostgresql.php | 4 ++-- app/Jobs/RegenerateSslCertJob.php | 5 +---- 4 files changed, 11 insertions(+), 16 deletions(-) diff --git a/app/Actions/Database/StartMariadb.php b/app/Actions/Database/StartMariadb.php index f97d732c9..50fd1ab00 100644 --- a/app/Actions/Database/StartMariadb.php +++ b/app/Actions/Database/StartMariadb.php @@ -57,12 +57,11 @@ public function handle(StandaloneMariadb $database) } else { $this->commands[] = "echo 'Setting up SSL for this database.'"; $this->commands[] = "mkdir -p $this->configuration_dir/ssl"; - $server = $this->database->destination->server; - $caCert = SslCertificate::where('server_id', $server->id)->firstOrFail(); - $this->ssl_certificate = SslCertificate::where('resource_type', $this->database->getMorphClass()) - ->where('resource_id', $this->database->id) - ->first(); + $server = $this->database->destination->server; + $caCert = SslCertificate::where('server_id', $server->server_id)->where('is_ca_certificate', true)->first(); + + $this->ssl_certificate = SslCertificate::where('resource_type', $this->database->getMorphClass())->where('resource_id', $this->database->id)->first(); if (! $this->ssl_certificate) { $this->commands[] = "echo 'No SSL certificate found, generating new SSL certificate for this database.'"; diff --git a/app/Actions/Database/StartMysql.php b/app/Actions/Database/StartMysql.php index cbdda3381..bec1c7fb1 100644 --- a/app/Actions/Database/StartMysql.php +++ b/app/Actions/Database/StartMysql.php @@ -57,12 +57,11 @@ public function handle(StandaloneMysql $database) } else { $this->commands[] = "echo 'Setting up SSL for this database.'"; $this->commands[] = "mkdir -p $this->configuration_dir/ssl"; - $server = $this->database->destination->server; - $caCert = SslCertificate::where('server_id', $server->id)->firstOrFail(); - $this->ssl_certificate = SslCertificate::where('resource_type', $this->database->getMorphClass()) - ->where('resource_id', $this->database->id) - ->first(); + $server = $this->database->destination->server; + $caCert = SslCertificate::where('server_id', $server->server_id)->where('is_ca_certificate', true)->first(); + + $this->ssl_certificate = SslCertificate::where('resource_type', $this->database->getMorphClass())->where('resource_id', $this->database->id)->first(); if (! $this->ssl_certificate) { $this->commands[] = "echo 'No SSL certificate found, generating new SSL certificate for this database.'"; diff --git a/app/Actions/Database/StartPostgresql.php b/app/Actions/Database/StartPostgresql.php index b582136a3..75f43a5ee 100644 --- a/app/Actions/Database/StartPostgresql.php +++ b/app/Actions/Database/StartPostgresql.php @@ -62,9 +62,9 @@ public function handle(StandalonePostgresql $database) } else { $this->commands[] = "echo 'Setting up SSL for this database.'"; $this->commands[] = "mkdir -p $this->configuration_dir/ssl"; - $server = $this->database->destination->server; - $caCert = SslCertificate::where('server_id', $server->id)->firstOrFail(); + $server = $this->database->destination->server; + $caCert = SslCertificate::where('server_id', $server->server_id)->where('is_ca_certificate', true)->first(); $this->ssl_certificate = SslCertificate::where('resource_type', $this->database->getMorphClass())->where('resource_id', $this->database->id)->first(); diff --git a/app/Jobs/RegenerateSslCertJob.php b/app/Jobs/RegenerateSslCertJob.php index 0155ee798..3e4bf9070 100644 --- a/app/Jobs/RegenerateSslCertJob.php +++ b/app/Jobs/RegenerateSslCertJob.php @@ -47,10 +47,7 @@ public function handle() foreach ($certificates as $certificate) { try { - $caCert = SslCertificate::where('server_id', $certificate->server_id) - ->where('resource_type', null) - ->where('resource_id', null) - ->first(); + $caCert = SslCertificate::where('server_id', $certificate->server_id)->where('is_ca_certificate', true)->first(); SSLHelper::generateSslCertificate( commonName: $certificate->common_name,